Skip to content

Commit

Permalink
Merge pull request #436 from code4romania/420-implement-back-feature
Browse files Browse the repository at this point in the history
Back action
  • Loading branch information
gheorghelupu17 authored Dec 20, 2024
2 parents 7b7062d + 64fe225 commit 8de7b66
Show file tree
Hide file tree
Showing 62 changed files with 493 additions and 33 deletions.
24 changes: 24 additions & 0 deletions app/Actions/BackAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace App\Actions;

use Filament\Actions\Action;

class BackAction extends Action
{
protected function setUp(): void
{
parent::setUp();

$this->icon('heroicon-o-chevron-left');
$this->hiddenLabel();
$this->link();
}

public function getName(): ?string
{
return 'back_action';
}
}
18 changes: 18 additions & 0 deletions app/Concerns/HasBackAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace App\Concerns;

use App\Actions\BackAction;

trait HasBackAction
{
protected function getHeaderActions(): array
{
return [
BackAction::make()
->url($this->getRedirectUrl()),
];
}
}
2 changes: 2 additions & 0 deletions app/Concerns/RedirectToCloseFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

trait RedirectToCloseFile
{
use HasBackAction;

protected function getRedirectUrl(): string
{
return self::$resource::getUrl('view_close_file', [
Expand Down
2 changes: 2 additions & 0 deletions app/Concerns/RedirectToDetailedEvaluation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

trait RedirectToDetailedEvaluation
{
use HasBackAction;

protected function getRedirectUrl(): string
{
return self::$resource::getUrl('view_detailed_evaluation', [
Expand Down
2 changes: 2 additions & 0 deletions app/Concerns/RedirectToIdentity.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

trait RedirectToIdentity
{
use HasBackAction;

protected function getRedirectUrl(): string
{
return static::getResource()::getUrl('view_identity', [
Expand Down
2 changes: 2 additions & 0 deletions app/Concerns/RedirectToInitialEvaluation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

trait RedirectToInitialEvaluation
{
use HasBackAction;

protected function getRedirectUrl(): string
{
return self::$resource::getUrl('view_initial_evaluation', [
Expand Down
2 changes: 2 additions & 0 deletions app/Concerns/RedirectToMonitoring.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

trait RedirectToMonitoring
{
use HasBackAction;

protected function getRedirectUrl(): ?string
{
return self::getParentResource()::getUrl('monitorings.view', [
Expand Down
2 changes: 2 additions & 0 deletions app/Concerns/RedirectToPersonalInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

trait RedirectToPersonalInformation
{
use HasBackAction;

protected function getRedirectUrl(): string
{
return static::getResource()::getUrl('view_personal_information', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Admin\Resources\BenefitResource\Pages;

use App\Actions\BackAction;
use App\Concerns\PreventMultipleSubmit;
use App\Concerns\PreventSubmitFormOnEnter;
use App\Filament\Admin\Resources\BenefitResource;
Expand Down Expand Up @@ -36,4 +37,12 @@ protected function getRedirectUrl(): string
{
return self::$resource::getUrl('view', ['record' => $this->getRecord()]);
}

protected function getHeaderActions(): array
{
return [
BackAction::make()
->url(BenefitResource::getUrl()),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Admin\Resources\BenefitResource\Pages;

use App\Actions\BackAction;
use App\Filament\Admin\Actions\ChangeNomenclatureStatusAction;
use App\Filament\Admin\Resources\BenefitResource;
use Filament\Actions;
Expand Down Expand Up @@ -35,6 +36,9 @@ protected function getRedirectUrl(): string
protected function getHeaderActions(): array
{
return [
BackAction::make()
->url($this->getRedirectUrl()),

ChangeNomenclatureStatusAction::make(),

Actions\DeleteAction::make()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Admin\Resources\BenefitResource\Pages;

use App\Actions\BackAction;
use App\Filament\Admin\Resources\BenefitResource;
use App\Filament\Admin\Resources\BenefitResource\Widgets\BenefitTypesWidget;
use Filament\Actions\EditAction;
Expand All @@ -20,9 +21,12 @@ public function getFooterWidgetsColumns(): int|string|array
return 1;
}

protected function getActions(): array
protected function getHeaderActions(): array
{
return [
BackAction::make()
->url(BenefitResource::getUrl()),

EditAction::make()
->label(__('nomenclature.actions.edit_benefit')),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Admin\Resources\InstitutionResource\Pages;

use App\Actions\BackAction;
use App\Filament\Admin\Resources\InstitutionResource;
use App\Forms\Components\Repeater;
use App\Models\Organization;
Expand Down Expand Up @@ -38,6 +39,14 @@ public function getTitle(): string|Htmlable
return $this->getRecord()->name;
}

public function getHeaderActions(): array
{
return [
BackAction::make()
->url($this->getRedirectUrl()),
];
}

public function form(Form $form): Form
{
return $form->schema(self::getSchema());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Admin\Resources\InstitutionResource\Pages;

use App\Actions\BackAction;
use App\Enums\AreaType;
use App\Enums\OrganizationType;
use App\Filament\Admin\Resources\InstitutionResource;
Expand Down Expand Up @@ -44,6 +45,14 @@ public function form(Form $form): Form
return $form->schema(self::getSchema());
}

public function getHeaderActions(): array
{
return [
BackAction::make()
->url($this->getRedirectUrl()),
];
}

public static function getSchema(): array
{
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Admin\Resources\InstitutionResource\Pages;

use App\Actions\BackAction;
use App\Filament\Admin\Resources\InstitutionResource;
use App\Filament\Admin\Resources\InstitutionResource\Actions\ActivateInstitution;
use App\Filament\Admin\Resources\InstitutionResource\Actions\InactivateInstitution;
Expand Down Expand Up @@ -36,6 +37,9 @@ public function getTitle(): string|Htmlable
protected function getActions(): array
{
return [
BackAction::make()
->url(InstitutionResource::getUrl()),

ActivateInstitution::make(),

InactivateInstitution::make(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Admin\Resources\ResultResource\Pages;

use App\Actions\BackAction;
use App\Concerns\PreventMultipleSubmit;
use App\Concerns\PreventSubmitFormOnEnter;
use App\Filament\Admin\Resources\ResultResource;
Expand Down Expand Up @@ -36,4 +37,12 @@ protected function getRedirectUrl(): string
{
return self::$resource::getUrl();
}

public function getHeaderActions(): array
{
return [
BackAction::make()
->url(ResultResource::getUrl()),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Admin\Resources\ResultResource\Pages;

use App\Actions\BackAction;
use App\Filament\Admin\Actions\ChangeNomenclatureStatusAction;
use App\Filament\Admin\Resources\ResultResource;
use Filament\Actions;
Expand All @@ -30,6 +31,9 @@ public function getTitle(): string|Htmlable
protected function getHeaderActions(): array
{
return [
BackAction::make()
->url(ResultResource::getUrl()),

ChangeNomenclatureStatusAction::make(),

Actions\DeleteAction::make()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Admin\Resources\RoleResource\Pages;

use App\Actions\BackAction;
use App\Concerns\PreventMultipleSubmit;
use App\Concerns\PreventSubmitFormOnEnter;
use App\Filament\Admin\Resources\RoleResource;
Expand Down Expand Up @@ -31,4 +32,12 @@ public function getBreadcrumbs(): array
RoleResource::getUrl('create') => __('nomenclature.actions.add_role'),
];
}

protected function getHeaderActions(): array
{
return [
BackAction::make()
->url(RoleResource::getUrl()),
];
}
}
4 changes: 4 additions & 0 deletions app/Filament/Admin/Resources/RoleResource/Pages/EditRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Admin\Resources\RoleResource\Pages;

use App\Actions\BackAction;
use App\Filament\Admin\Actions\ChangeNomenclatureStatusAction;
use App\Filament\Admin\Resources\RoleResource;
use Filament\Actions\DeleteAction;
Expand Down Expand Up @@ -35,6 +36,9 @@ protected function getRedirectUrl(): ?string
protected function getHeaderActions(): array
{
return [
BackAction::make()
->url($this->getRedirectUrl()),

ChangeNomenclatureStatusAction::make(),

DeleteAction::make()
Expand Down
6 changes: 5 additions & 1 deletion app/Filament/Admin/Resources/RoleResource/Pages/ViewRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Admin\Resources\RoleResource\Pages;

use App\Actions\BackAction;
use App\Filament\Admin\Resources\RoleResource;
use Filament\Actions;
use Filament\Infolists\Components\Section;
Expand All @@ -29,9 +30,12 @@ public function getBreadcrumbs(): array
];
}

protected function getActions(): array
protected function getHeaderActions(): array
{
return [
BackAction::make()
->url(RoleResource::getUrl()),

Actions\EditAction::make()
->label(__('nomenclature.actions.edit_role')),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Admin\Resources\ServiceResource\Pages;

use App\Actions\BackAction;
use App\Concerns\PreventMultipleSubmit;
use App\Concerns\PreventSubmitFormOnEnter;
use App\Filament\Admin\Resources\ServiceResource;
Expand Down Expand Up @@ -31,4 +32,12 @@ public function getBreadcrumbs(): array
self::$resource::getUrl('create') => __('nomenclature.actions.add_service'),
];
}

public function getHeaderActions(): array
{
return [
BackAction::make()
->url(ServiceResource::getUrl()),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Admin\Resources\ServiceResource\Pages;

use App\Actions\BackAction;
use App\Filament\Admin\Actions\ChangeNomenclatureStatusAction;
use App\Filament\Admin\Resources\ServiceResource;
use Filament\Actions\DeleteAction;
Expand Down Expand Up @@ -35,6 +36,9 @@ public function getTitle(): string|Htmlable
protected function getActions(): array
{
return [
BackAction::make()
->url($this->getRedirectUrl()),

ChangeNomenclatureStatusAction::make()
->relationship('organizationServices'),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Admin\Resources\ServiceResource\Pages;

use App\Actions\BackAction;
use App\Enums\CounselingSheet;
use App\Filament\Admin\Resources\ServiceResource;
use App\Filament\Admin\Resources\ServiceResource\Widgets\InterventionsWidget;
Expand Down Expand Up @@ -37,6 +38,9 @@ public function getTitle(): string|Htmlable
protected function getActions(): array
{
return [
BackAction::make()
->url(ServiceResource::getUrl()),

Actions\EditAction::make()
->label(__('nomenclature.actions.edit_service')),
];
Expand Down
Loading

0 comments on commit 8de7b66

Please sign in to comment.