Skip to content

Commit

Permalink
refactor:[LAR-32] integrate review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Chri$ committed Oct 16, 2024
1 parent 7b8a253 commit 63e70df
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 65 deletions.
7 changes: 5 additions & 2 deletions app/Filament/Actions/ApprovedAction.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<?php

declare(strict_types=1);

namespace App\Filament\Actions;

use Filament\Actions\Concerns\CanCustomizeProcess;
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 @@ -27,7 +30,7 @@ protected function setUp(): void

$this->color('success');

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

$this->requiresConfirmation();

Expand Down
8 changes: 5 additions & 3 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-x-mark');
$this->icon('heroicon-s-x-mark');

$this->requiresConfirmation();

Expand Down
6 changes: 4 additions & 2 deletions 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';
protected static ?string $navigationIcon = 'heroicon-o-newspaper';
}
66 changes: 34 additions & 32 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,55 +10,55 @@
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;

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationIcon = 'heroicon-o-newspaper';

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';
}else{
return 'Brouillon';
}
})
->colors([
'success' => 'Approuver',
'danger' => 'Décliner',
'warning' => 'Soumis',
'default' => 'Brouillon',
])
->badge(),
->getStateUsing(function ($record) {
if ($record->approved_at) {
return 'Approuver';
} elseif ($record->declined_at) {
return 'Décliner';
} elseif ($record->submitted_at) {
return 'Soumis';
} else {
return 'Brouillon';
}
})
->colors([
'success' => 'Approuver',
'danger' => 'Décliner',
'warning' => 'Soumis',
'default' => 'Brouillon',
])
->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
12 changes: 3 additions & 9 deletions app/Filament/Resources/ArticleResource/Pages/ListArticles.php
Original file line number Diff line number Diff line change
@@ -1,19 +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;

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

protected function getHeaderActions(): array
{
return [

];
}
}
21 changes: 4 additions & 17 deletions tests/Feature/Filament/ArticleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use App\Filament\Resources\ArticleResource;
use Filament\Tables\Actions\DeleteAction;
use App\Models\Article;
use Livewire\Livewire;

Expand Down Expand Up @@ -39,9 +38,8 @@

expect($article->approved_at)
->not
->toBe(null);

expect($article->declined_at)
->toBe(null)
->and($article->declined_at)
->toBe(null);
});

Expand All @@ -55,20 +53,9 @@

expect($article->declined_at)
->not
->toBe(null);

expect($article->approved_at)
->toBe(null)
->and($article->approved_at)
->toBe(null);
});

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

// Livewire::test(ArticleResource\Pages\ListArticles::class)
// ->callTableAction('delete', $article);
// //->callAction(DeleteAction::class);

// expect(Article::find($article->id))
// ->toBe(null);
// });
})->group('articles');

0 comments on commit 63e70df

Please sign in to comment.