Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudio-Emmolo authored and github-actions[bot] committed Aug 4, 2023
1 parent d07325a commit 38c9874
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 38 deletions.
28 changes: 10 additions & 18 deletions src/Abstract/GithubTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -48,8 +52,6 @@ public function cacheFor()

/**
* Return an error message in Nova Table Row
*
* @return array
*/
public function returnErrorMessage(): array
{
Expand All @@ -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 [];
});
}

}
11 changes: 5 additions & 6 deletions src/LatestCommitsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
Expand All @@ -57,8 +58,6 @@ public function renderCommitsTable()

/**
* Get commits from Github
*
* @return mixed
*/
public function getCommits(): mixed
{
Expand Down
25 changes: 12 additions & 13 deletions src/LatestIssuesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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'];

Expand All @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion src/NovaGithubCardsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 38c9874

Please sign in to comment.