From 1e481fa55ece01cc4014ace85393a869b1dc87eb Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Thu, 24 Feb 2022 18:23:22 +0000 Subject: [PATCH] wip --- .../admin/src/Commands/MakeWidgetCommand.php | 1 - .../src/Resources/Pages/CreateRecord.php | 18 +++++++--------- .../admin/src/Resources/Pages/EditRecord.php | 21 ++++++++++++------- .../admin/src/Resources/Pages/ListRecords.php | 7 ++++++- .../ListRecords/Concerns/CanDeleteRecords.php | 7 ++++++- .../ListRecords/Concerns/CanEditRecords.php | 7 ++++++- .../Concerns/CanAttachRecords.php | 7 ++++++- .../Concerns/CanCreateRecords.php | 7 ++++++- .../Concerns/CanDeleteRecords.php | 14 +++++++++++-- .../Concerns/CanDetachRecords.php | 14 +++++++++++-- .../Concerns/CanEditRecords.php | 7 ++++++- .../src/Pages/SettingsPage.php | 7 ++++++- 12 files changed, 87 insertions(+), 30 deletions(-) diff --git a/packages/admin/src/Commands/MakeWidgetCommand.php b/packages/admin/src/Commands/MakeWidgetCommand.php index 239855e9625..1e72c9674ee 100644 --- a/packages/admin/src/Commands/MakeWidgetCommand.php +++ b/packages/admin/src/Commands/MakeWidgetCommand.php @@ -87,7 +87,6 @@ public function handle(): int 'Radar chart', 'Scatter chart', ], - 0, ); $this->copyStubToApp('ChartWidget', $path, [ diff --git a/packages/admin/src/Resources/Pages/CreateRecord.php b/packages/admin/src/Resources/Pages/CreateRecord.php index a76eec72ed4..8c924def23f 100644 --- a/packages/admin/src/Resources/Pages/CreateRecord.php +++ b/packages/admin/src/Resources/Pages/CreateRecord.php @@ -62,8 +62,12 @@ public function create(bool $another = false): void $this->callHook('afterCreate'); - $this->getCreatedNotification(another: $another); - + $this->notify( + 'success', + $this->getCreatedNotificationMessage(), + isAfterRedirect: ! $another, + ); + if ($another) { // Ensure that the form record is anonymized so that relationships aren't loaded. $this->form->model($this->record::class); @@ -77,17 +81,11 @@ public function create(bool $another = false): void $this->redirect($this->getRedirectUrl()); } - public function getCreatedNotification(bool $another): void + protected function getCreatedNotificationMessage(): string { - $this->notify( - 'success', - __('filament::resources/pages/create-record.messages.created'), - isAfterRedirect: !$another, - ); + return __('filament::resources/pages/create-record.messages.created'); } - - public function createAndCreateAnother(): void { $this->create(another: true); diff --git a/packages/admin/src/Resources/Pages/EditRecord.php b/packages/admin/src/Resources/Pages/EditRecord.php index cad715e2e50..15f0caa2f8d 100644 --- a/packages/admin/src/Resources/Pages/EditRecord.php +++ b/packages/admin/src/Resources/Pages/EditRecord.php @@ -80,20 +80,20 @@ public function save(bool $shouldRedirect = true): void $shouldRedirect = $shouldRedirect && ($redirectUrl = $this->getRedirectUrl()); - $this->getUpdatedNotification(isAfterRedirect: $shouldRedirect); + $this->notify( + 'success', + $this->getSavedNotificationMessage(), + isAfterRedirect: $shouldRedirect, + ); if ($shouldRedirect) { $this->redirect($redirectUrl); } } - public function getUpdatedNotification(bool $isAfterRedirect): void + protected function getSavedNotificationMessage(): string { - $this->notify( - 'success', - __('filament::resources/pages/edit-record.messages.saved'), - isAfterRedirect: $isAfterRedirect, - ); + return __('filament::resources/pages/edit-record.messages.saved'); } protected function handleRecordUpdate(Model $record, array $data): Model @@ -127,13 +127,18 @@ public function delete(): void $this->notify( 'success', - __('filament::resources/pages/edit-record.actions.delete.messages.deleted'), + $this->getDeletedNotificationMessage(), isAfterRedirect: true, ); $this->redirect($this->getDeleteRedirectUrl()); } + protected function getDeletedNotificationMessage(): string + { + return __('filament::resources/pages/edit-record.actions.delete.messages.deleted'); + } + protected function getActions(): array { $resource = static::getResource(); diff --git a/packages/admin/src/Resources/Pages/ListRecords.php b/packages/admin/src/Resources/Pages/ListRecords.php index 5cc8cad5012..5e7e8c0cfb2 100644 --- a/packages/admin/src/Resources/Pages/ListRecords.php +++ b/packages/admin/src/Resources/Pages/ListRecords.php @@ -124,7 +124,12 @@ public function bulkDelete(): void $this->callHook('afterBulkDelete'); - $this->notify('success', __('filament::resources/pages/list-records.table.bulk_actions.delete.messages.deleted')); + $this->notify('success', $this->getBulkDeletedNotificationMessage()); + } + + protected function getBulkDeletedNotificationMessage(): string + { + return __('filament::resources/pages/list-records.table.bulk_actions.delete.messages.deleted'); } protected function handleRecordBulkDeletion(Collection $records): void diff --git a/packages/admin/src/Resources/Pages/ListRecords/Concerns/CanDeleteRecords.php b/packages/admin/src/Resources/Pages/ListRecords/Concerns/CanDeleteRecords.php index c52df0bb0ae..71723eca5d3 100644 --- a/packages/admin/src/Resources/Pages/ListRecords/Concerns/CanDeleteRecords.php +++ b/packages/admin/src/Resources/Pages/ListRecords/Concerns/CanDeleteRecords.php @@ -32,7 +32,12 @@ public function delete(): void $this->callHook('afterDelete'); - $this->notify('success', __('filament::resources/pages/list-records.table.actions.delete.messages.deleted')); + $this->notify('success', $this->getDeletedNotificationMessage()); + } + + protected function getDeletedNotificationMessage(): string + { + return __('filament::resources/pages/list-records.table.actions.delete.messages.deleted'); } protected function handleRecordDeletion(Model $record): void diff --git a/packages/admin/src/Resources/Pages/ListRecords/Concerns/CanEditRecords.php b/packages/admin/src/Resources/Pages/ListRecords/Concerns/CanEditRecords.php index 13634aaefcd..5d6b0c07666 100644 --- a/packages/admin/src/Resources/Pages/ListRecords/Concerns/CanEditRecords.php +++ b/packages/admin/src/Resources/Pages/ListRecords/Concerns/CanEditRecords.php @@ -72,7 +72,12 @@ public function save(): void $this->callHook('afterSave'); - $this->notify('success', __('filament::resources/pages/list-records.table.actions.edit.messages.saved')); + $this->notify('success', $this->getSavedNotificationMessage()); + } + + protected function getSavedNotificationMessage(): string + { + return __('filament::resources/pages/list-records.table.actions.edit.messages.saved'); } protected function handleRecordUpdate(Model $record, array $data): Model diff --git a/packages/admin/src/Resources/RelationManagers/Concerns/CanAttachRecords.php b/packages/admin/src/Resources/RelationManagers/Concerns/CanAttachRecords.php index 258408aac5a..70ec391ecaf 100644 --- a/packages/admin/src/Resources/RelationManagers/Concerns/CanAttachRecords.php +++ b/packages/admin/src/Resources/RelationManagers/Concerns/CanAttachRecords.php @@ -130,7 +130,12 @@ public function attach(bool $another = false): void $form->fill(); } - $this->notify('success', __('filament::resources/relation-managers/attach.action.messages.attached')); + $this->notify('success', $this->getAttachedNotificationMessage()); + } + + protected function getAttachedNotificationMessage(): string + { + return __('filament::resources/relation-managers/attach.action.messages.attached'); } public function attachAndAttachAnother(): void diff --git a/packages/admin/src/Resources/RelationManagers/Concerns/CanCreateRecords.php b/packages/admin/src/Resources/RelationManagers/Concerns/CanCreateRecords.php index ac5daba53a0..d4b2a131d57 100644 --- a/packages/admin/src/Resources/RelationManagers/Concerns/CanCreateRecords.php +++ b/packages/admin/src/Resources/RelationManagers/Concerns/CanCreateRecords.php @@ -61,7 +61,12 @@ public function create(bool $another = false): void $form->fill(); } - $this->notify('success', __('filament::resources/relation-managers/create.action.messages.created')); + $this->notify('success', $this->getCreatedNotificationMessage()); + } + + protected function getCreatedNotificationMessage(): string + { + return __('filament::resources/relation-managers/create.action.messages.created'); } public function createAndCreateAnother(): void diff --git a/packages/admin/src/Resources/RelationManagers/Concerns/CanDeleteRecords.php b/packages/admin/src/Resources/RelationManagers/Concerns/CanDeleteRecords.php index 7d35ba562f0..44dee69636d 100644 --- a/packages/admin/src/Resources/RelationManagers/Concerns/CanDeleteRecords.php +++ b/packages/admin/src/Resources/RelationManagers/Concerns/CanDeleteRecords.php @@ -25,7 +25,12 @@ public function delete(): void $this->callHook('afterDelete'); - $this->notify('success', __('filament::resources/relation-managers/delete.action.messages.deleted')); + $this->notify('success', $this->getDeletedNotificationMessage()); + } + + protected function getDeletedNotificationMessage(): string + { + return __('filament::resources/relation-managers/delete.action.messages.deleted'); } public function bulkDelete(): void @@ -36,7 +41,12 @@ public function bulkDelete(): void $this->callHook('afterBulkDelete'); - $this->notify('success', __('filament::resources/relation-managers/delete.bulk_action.messages.deleted')); + $this->notify('success', $this->getBulkDeletedNotificationMessage()); + } + + protected function getBulkDeletedNotificationMessage(): string + { + return __('filament::resources/relation-managers/delete.bulk_action.messages.deleted'); } protected function getDeleteAction(): Tables\Actions\Action diff --git a/packages/admin/src/Resources/RelationManagers/Concerns/CanDetachRecords.php b/packages/admin/src/Resources/RelationManagers/Concerns/CanDetachRecords.php index a8a5056e62c..7742347e5bf 100644 --- a/packages/admin/src/Resources/RelationManagers/Concerns/CanDetachRecords.php +++ b/packages/admin/src/Resources/RelationManagers/Concerns/CanDetachRecords.php @@ -29,7 +29,12 @@ public function detach(): void $this->callHook('afterDetach'); - $this->notify('success', __('filament::resources/relation-managers/detach.action.messages.detached')); + $this->notify('success', $this->getDetachedNotificationMessage()); + } + + protected function getDetachedNotificationMessage(): string + { + return __('filament::resources/relation-managers/detach.action.messages.detached'); } public function bulkDetach(): void @@ -43,7 +48,12 @@ public function bulkDetach(): void $this->callHook('afterBulkDetach'); - $this->notify('success', __('filament::resources/relation-managers/detach.bulk_action.messages.detached')); + $this->notify('success', $this->getBulkDetachedNotificationMessage()); + } + + protected function getBulkDetachedNotificationMessage(): string + { + return __('filament::resources/relation-managers/detach.bulk_action.messages.detached'); } protected function getDetachAction(): Tables\Actions\Action diff --git a/packages/admin/src/Resources/RelationManagers/Concerns/CanEditRecords.php b/packages/admin/src/Resources/RelationManagers/Concerns/CanEditRecords.php index 054383cf792..8789d305f63 100644 --- a/packages/admin/src/Resources/RelationManagers/Concerns/CanEditRecords.php +++ b/packages/admin/src/Resources/RelationManagers/Concerns/CanEditRecords.php @@ -55,7 +55,12 @@ public function save(): void $this->callHook('afterSave'); - $this->notify('success', __('filament::resources/relation-managers/edit.action.messages.saved')); + $this->notify('success', $this->getSavedNotificationMessage()); + } + + protected function getSavedNotificationMessage(): string + { + return __('filament::resources/relation-managers/edit.action.messages.saved'); } protected function handleRecordUpdate(Model $record, array $data): Model diff --git a/packages/spatie-laravel-settings-plugin/src/Pages/SettingsPage.php b/packages/spatie-laravel-settings-plugin/src/Pages/SettingsPage.php index 8e2b2410f00..8a783b9e5d4 100644 --- a/packages/spatie-laravel-settings-plugin/src/Pages/SettingsPage.php +++ b/packages/spatie-laravel-settings-plugin/src/Pages/SettingsPage.php @@ -53,10 +53,15 @@ public function save(): void if ($redirectUrl = $this->getRedirectUrl()) { $this->redirect($redirectUrl); } else { - $this->notify('success', __('filament-spatie-laravel-settings-plugin::pages/settings-page.messages.saved')); + $this->notify('success', $this->getSavedNotificationMessage()); } } + protected function getSavedNotificationMessage(): string + { + return __('filament-spatie-laravel-settings-plugin::pages/settings-page.messages.saved'); + } + protected function callHook(string $hook): void { if (! method_exists($this, $hook)) {