Skip to content

Commit

Permalink
Fix code styling
Browse files Browse the repository at this point in the history
  • Loading branch information
cybersoldattech authored and github-actions[bot] committed Oct 15, 2024
1 parent 8196a78 commit 79eebde
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 53 deletions.
10 changes: 6 additions & 4 deletions app/Filament/Actions/ApprovedAction.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

declare(strict_types=1);

namespace App\Filament\Actions;

use Filament\Actions\Concerns\CanCustomizeProcess;
use Filament\Support\Facades\FilamentIcon;
use Illuminate\Database\Eloquent\Model;

class ApprovedAction extends \Filament\Tables\Actions\Action
final class ApprovedAction extends \Filament\Tables\Actions\Action
{
use CanCustomizeProcess;

public static function getDefaultName(): ?string
{
return 'approved';
Expand All @@ -28,7 +30,7 @@ protected function setUp(): void

$this->color('success');

$this->icon( 'heroicon-s-x-mark');
$this->icon('heroicon-s-x-mark');

$this->requiresConfirmation();

Expand All @@ -37,7 +39,7 @@ protected function setUp(): void
$this->action(function (): void {
$result = $this->process(static fn (Model $record) => $record->update(['approved_at' => now(), 'declined_at' => null]));

if (! $result) {
if ( ! $result) {
$this->failure();

return;
Expand Down
10 changes: 6 additions & 4 deletions app/Filament/Actions/DeclinedAction.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

declare(strict_types=1);

namespace App\Filament\Actions;

use Filament\Actions\Concerns\CanCustomizeProcess;
use Filament\Support\Facades\FilamentIcon;
use Illuminate\Database\Eloquent\Model;

class DeclinedAction extends \Filament\Tables\Actions\Action
final class DeclinedAction extends \Filament\Tables\Actions\Action
{
use CanCustomizeProcess;

public static function getDefaultName(): ?string
{
return 'declined';
Expand All @@ -28,7 +30,7 @@ protected function setUp(): void

$this->color('warning');

$this->icon( 'heroicon-s-check');
$this->icon('heroicon-s-check');

$this->requiresConfirmation();

Expand All @@ -37,7 +39,7 @@ protected function setUp(): void
$this->action(function (): void {
$result = $this->process(static fn (Model $record) => $record->update(['declined_at' => now(), 'approved_at' => null]));

if (! $result) {
if ( ! $result) {
$this->failure();

return;
Expand Down
4 changes: 3 additions & 1 deletion app/Filament/Clusters/Articles.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php

declare(strict_types=1);

namespace App\Filament\Clusters;

use Filament\Clusters\Cluster;

class Articles extends Cluster
final class Articles extends Cluster
{
protected static ?string $navigationIcon = 'heroicon-o-squares-2x2';
}
59 changes: 30 additions & 29 deletions app/Filament/Resources/ArticleResource.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources;

use App\Filament\Actions\ApprovedAction;
Expand All @@ -8,14 +10,13 @@
use App\Models\Article;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ActionGroup;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Filament\Tables\Actions\ActionGroup;


class ArticleResource extends Resource
final class ArticleResource extends Resource
{
protected static ?string $model = Article::class;

Expand All @@ -26,36 +27,36 @@ public static function table(Table $table): Table
return $table
->columns([
TextColumn::make('title')
->label('Titre')
->sortable(),
->label('Titre')
->sortable(),
TextColumn::make('status')
->label('Status')
->getStateUsing(function ($record) {
if ($record->approved_at) {
return 'Approuver';
} elseif ($record->declined_at) {
return 'Décliner';
} elseif($record->submitted_at) {
return 'Soumis';
}
})
->colors([
'success' => 'Approuver',
'danger' => 'Décliner',
'warning' => 'Soumis',
])
->badge(),
->label('Status')
->getStateUsing(function ($record) {
if ($record->approved_at) {
return 'Approuver';
} elseif ($record->declined_at) {
return 'Décliner';
} elseif ($record->submitted_at) {
return 'Soumis';
}
})
->colors([
'success' => 'Approuver',
'danger' => 'Décliner',
'warning' => 'Soumis',
])
->badge(),
TextColumn::make('submitted_at')
->label('Date de soumission')
->dateTime(),
->label('Date de soumission')
->dateTime(),
TextColumn::make('user.name')
->label('Auteur')
->sortable()
->label('Auteur')
->sortable(),
])
->filters([
Filter::make('submitted_at')->query( fn (Builder $query) => $query->whereNotNull('submitted_at'))->label('Soumis'),
Filter::make('declined_at')->query( fn (Builder $query) => $query->whereNotNull('declined_at'))->label('Décliner'),
Filter::make('approved_at')->query( fn (Builder $query) => $query->whereNotNull('approved_at'))->label('Approuver')
Filter::make('submitted_at')->query(fn (Builder $query) => $query->whereNotNull('submitted_at'))->label('Soumis'),
Filter::make('declined_at')->query(fn (Builder $query) => $query->whereNotNull('declined_at'))->label('Décliner'),
Filter::make('approved_at')->query(fn (Builder $query) => $query->whereNotNull('approved_at'))->label('Approuver'),
])

->actions([
Expand Down
6 changes: 3 additions & 3 deletions app/Filament/Resources/ArticleResource/Pages/ListArticles.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\ArticleResource\Pages;

use App\Filament\Resources\ArticleResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
use Filament\Tables\Actions\DeleteAction;

class ListArticles extends ListRecords
final class ListArticles extends ListRecords
{
protected static string $resource = ArticleResource::class;

Expand Down
3 changes: 0 additions & 3 deletions app/Models/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,11 @@ public function getRouteKeyName(): string
return 'slug';
}


public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}



public function excerpt(int $limit = 110): string
{
return Str::limit(strip_tags((string) md_to_html($this->body)), $limit);
Expand Down
15 changes: 6 additions & 9 deletions tests/Feature/Filament/ArticleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

declare(strict_types=1);

use App\Filament\Actions\ApprovedAction;
use App\Filament\Actions\DeclinedAction;
use App\Filament\Resources\ArticleResource;
use App\Models\Article;
use Filament\Tables\Actions\DeleteAction;
Expand All @@ -12,26 +10,26 @@
beforeEach(function (): void {
$this->user = $this->login();
$this->articles = Article::factory()->count(10)->create([
'submitted_at' => now()
'submitted_at' => now(),
]);
});

describe(ArticleResource::class, function (): void {

it('page can display table with records', function () {
it('page can display table with records', function (): void {
Livewire::test(ArticleResource\Pages\ListArticles::class)
->assertCanSeeTableRecords($this->articles);
});

it('table can render columns', function () {
it('table can render columns', function (): void {
Livewire::test(ArticleResource\Pages\ListArticles::class)
->assertCanRenderTableColumn('title')
->assertCanRenderTableColumn('status')
->assertCanRenderTableColumn('status')
->assertCanRenderTableColumn('submitted_at');
});

it('admin user can approved article', function () {
it('admin user can approved article', function (): void {
$article = Article::factory()->create(['submitted_at' => now()]);

Livewire::test(ArticleResource\Pages\ListArticles::class)
Expand All @@ -47,12 +45,11 @@
->toBe(null);
});


it('admin user can declined article', function () {
it('admin user can declined article', function (): void {
$article = Article::factory()->create(['submitted_at' => now()]);

Livewire::test(ArticleResource\Pages\ListArticles::class)
->callTableAction('declined', $article);
->callTableAction('declined', $article);

$article->refresh();

Expand Down

0 comments on commit 79eebde

Please sign in to comment.