From 38c9874959aaa0bd83ddf72f59b81a72b13f31f9 Mon Sep 17 00:00:00 2001 From: Claudio-Emmolo Date: Fri, 4 Aug 2023 15:56:05 +0000 Subject: [PATCH] Fix styling --- src/Abstract/GithubTable.php | 28 +++++++++----------------- src/LatestCommitsTable.php | 11 +++++----- src/LatestIssuesTable.php | 25 +++++++++++------------ src/NovaGithubCardsServiceProvider.php | 4 +++- 4 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/Abstract/GithubTable.php b/src/Abstract/GithubTable.php index b010c5a..fba043a 100644 --- a/src/Abstract/GithubTable.php +++ b/src/Abstract/GithubTable.php @@ -6,14 +6,18 @@ use Laravel\Nova\Metrics\MetricTableRow; use Laravel\Nova\Metrics\Table; - abstract class GithubTable extends Table { public $title = 'GitHubâ„¢'; + protected ?string $vendor; + protected ?string $repository; + protected ?string $branch; + protected ?int $per_page; + protected ?int $cache_ttl; /** @@ -48,8 +52,6 @@ public function cacheFor() /** * Return an error message in Nova Table Row - * - * @return array */ public function returnErrorMessage(): array { @@ -63,37 +65,27 @@ public function returnErrorMessage(): array /** * Render a row in Nova table - * - * @param string $title - * @param string $subtitle - * @param string|null $icon - * @param string|null $iconClass - * - * @return MetricTableRow */ public function renderRow( string $title, string $subtitle, - ?string $icon = null, - ?string $iconClass = null, - ?string $url = null) - : MetricTableRow + string $icon = null, + string $iconClass = null, + string $url = null): MetricTableRow { return MetricTableRow::make() ->icon($icon ?? config('nova-github-cards.icons.success.icon')) ->iconClass($iconClass ?? config('nova-github-cards.icons.success.iconClass')) ->title($title) ->subtitle($subtitle) - ->actions(function () use ($url) - { + ->actions(function () use ($url) { if ($url) { return [ - MenuItem::externalLink( (__('novaGithubCard.show')), $url)->openInNewTab(), + MenuItem::externalLink((__('novaGithubCard.show')), $url)->openInNewTab(), ]; } return []; }); } - } diff --git a/src/LatestCommitsTable.php b/src/LatestCommitsTable.php index ae2c585..5a814b8 100644 --- a/src/LatestCommitsTable.php +++ b/src/LatestCommitsTable.php @@ -11,14 +11,14 @@ final class LatestCommitsTable extends GithubTable { - public $title = 'novaGithubCard.commitsTitle'; + public array $commits = []; /** * Calculate the value of the metric. */ - public function calculate(NovaRequest $request) : mixed + public function calculate(NovaRequest $request): mixed { $this->commits = $this->getCommits(); @@ -39,14 +39,15 @@ public function renderCommitsTable() { $table = []; - if(empty($this->commits)) { + if (empty($this->commits)) { $table[] = $this->renderRow(title: (__('novaGithubCard.noCommitsFound')), subtitle: '', icon: 'information-circle', iconClass: 'text-gray-500'); + return $table; } foreach ($this->commits as $commit) { $title = $commit['commit']['message']; - $subtitle = Carbon::parse($commit['commit']['author']['date'])->diffForHumans() . ' - ' . (__('novaGithubCard.commitBy')) . $commit['commit']['author']['name']; + $subtitle = Carbon::parse($commit['commit']['author']['date'])->diffForHumans().' - '.(__('novaGithubCard.commitBy')).$commit['commit']['author']['name']; $url = $commit['html_url']; $table[] = $this->renderRow(title: $title, subtitle: $subtitle, url: $url); @@ -57,8 +58,6 @@ public function renderCommitsTable() /** * Get commits from Github - * - * @return mixed */ public function getCommits(): mixed { diff --git a/src/LatestIssuesTable.php b/src/LatestIssuesTable.php index 9e1b165..f9246aa 100644 --- a/src/LatestIssuesTable.php +++ b/src/LatestIssuesTable.php @@ -11,14 +11,14 @@ final class LatestIssuesTable extends GithubTable { - public $title = 'novaGithubCard.issuesTitle'; + public array $issues = []; /** * Calculate the value of the metric. */ - public function calculate(NovaRequest $request) : mixed + public function calculate(NovaRequest $request): mixed { $this->issues = $this->getIssues(); @@ -39,16 +39,17 @@ public function renderIssuesTable() { $table = []; - if(empty($this->issues)) { + if (empty($this->issues)) { $table[] = $this->renderRow((__('novaGithubCard.noIssuesFound')), ''); + return $table; } foreach ($this->issues as $issue) { $title = $issue['title']; - $assigneeName = $issue['assignee'] != null ? (__('novaGithubCard.assigned')) . $issue['assignee']['login'] : (__('novaGithubCard.assign')); - $subtitle = Carbon::parse($issue['created_at'])->diffForHumans() . ' - ' . $assigneeName; + $assigneeName = $issue['assignee'] != null ? (__('novaGithubCard.assigned')).$issue['assignee']['login'] : (__('novaGithubCard.assign')); + $subtitle = Carbon::parse($issue['created_at'])->diffForHumans().' - '.$assigneeName; $icon = $issue['assignee'] != null ? 'tag' : 'plus-circle'; $url = $issue['html_url']; @@ -60,17 +61,15 @@ public function renderIssuesTable() /** * Get issues from Github - * - * @return mixed */ public function getIssues(): mixed { -// dd( -// Github::issues()->all( -// $this->vendor, -// $this->repository, -// ['sha' => $this->branch, 'per_page' => $this->per_page]) -// ); + // dd( + // Github::issues()->all( + // $this->vendor, + // $this->repository, + // ['sha' => $this->branch, 'per_page' => $this->per_page]) + // ); try { // @phpstan-ignore-next-line return Github::issues()->all( diff --git a/src/NovaGithubCardsServiceProvider.php b/src/NovaGithubCardsServiceProvider.php index ae98b53..738b7b5 100644 --- a/src/NovaGithubCardsServiceProvider.php +++ b/src/NovaGithubCardsServiceProvider.php @@ -4,19 +4,21 @@ use Illuminate\Support\ServiceProvider; use Outl1ne\NovaTranslationsLoader\LoadsNovaTranslations; + class NovaGithubCardsServiceProvider extends ServiceProvider { /** * Bootstrap the application services. */ use LoadsNovaTranslations; + public function boot() { $this->publishes([ __DIR__.'/../config/nova-github-cards.php' => config_path('nova-github-cards.php'), ], 'config'); - $this->loadTranslations(__DIR__ . '/../lang', 'nova-github-cards', true); + $this->loadTranslations(__DIR__.'/../lang', 'nova-github-cards', true); } /**