From 42dfd33ad5792a7b3cc6eca89ffbfddb2d29c818 Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Mon, 25 Mar 2024 10:23:21 +0000 Subject: [PATCH] Integrate component actions --- .../app/app/Livewire/Forms/FieldsDemo.php | 2 +- .../app/app/Livewire/Forms/LayoutDemo.php | 4 +- packages/actions/src/Action.php | 52 +++++++-- .../src/Concerns/BelongsToComponent.php | 23 ++++ packages/forms/docs/03-fields/03-select.md | 3 +- .../forms/docs/03-fields/06-checkbox-list.md | 3 +- packages/forms/docs/03-fields/12-repeater.md | 11 +- packages/forms/docs/03-fields/13-builder.md | 11 +- packages/forms/docs/03-fields/16-key-value.md | 3 +- packages/forms/docs/04-layout/05-wizard.md | 3 +- packages/forms/docs/04-layout/06-section.md | 10 +- packages/forms/docs/06-actions.md | 30 ++---- .../views/components/builder.blade.php | 2 +- .../components/field-wrapper/index.blade.php | 2 +- .../views/components/repeater/index.blade.php | 2 +- .../forms/src/Components/Actions/Action.php | 101 ------------------ .../Actions/Concerns/BelongsToComponent.php | 28 ----- packages/forms/src/Components/Builder.php | 2 +- .../forms/src/Components/CheckboxList.php | 2 +- .../src/Components/Concerns/HasAffixes.php | 2 +- .../Concerns/HasExtraItemActions.php | 2 +- .../Components/Concerns/HasFooterActions.php | 2 +- .../Components/Concerns/HasHeaderActions.php | 2 +- .../forms/src/Components/Concerns/HasHint.php | 2 +- .../Components/Contracts/HasAffixActions.php | 2 +- .../Contracts/HasExtraItemActions.php | 2 +- .../Components/Contracts/HasFooterActions.php | 2 +- .../Components/Contracts/HasHeaderActions.php | 2 +- .../Components/Contracts/HasHintActions.php | 2 +- packages/forms/src/Components/KeyValue.php | 2 +- packages/forms/src/Components/Repeater.php | 2 +- packages/forms/src/Components/Select.php | 2 +- .../TextInput/Actions/HidePasswordAction.php | 2 +- .../TextInput/Actions/ShowPasswordAction.php | 2 +- packages/forms/src/Components/Wizard.php | 2 +- .../src/Concerns/HasFormComponentActions.php | 2 +- .../docs/03-resources/04-editing-records.md | 5 +- .../views/components/actions.blade.php | 0 .../actions/action-container.blade.php | 0 packages/schema/src/ComponentContainer.php | 2 +- .../src/Components/Actions.php | 7 +- .../Components/Actions/ActionContainer.php | 5 +- .../src/Components/Component.php | 4 +- .../src/Components/Concerns/HasActions.php | 2 +- .../src/Components/Concerns/HasState.php | 20 +++- packages/schema/src/SchemaServiceProvider.php | 2 +- .../src/Testing/TestsComponentActions.php | 2 +- .../views/components/input/wrapper.blade.php | 4 +- packages/tables/src/Actions/ButtonAction.php | 2 + .../tables/src/Actions/IconButtonAction.php | 2 + .../Forms/Components/RuleBuilder.php | 2 +- packages/upgrade/src/rector.php | 9 +- tests/src/Forms/ActionTest.php | 2 +- tests/src/Forms/Fixtures/Actions.php | 2 +- 54 files changed, 166 insertions(+), 234 deletions(-) create mode 100644 packages/actions/src/Concerns/BelongsToComponent.php delete mode 100644 packages/forms/src/Components/Actions/Action.php delete mode 100644 packages/forms/src/Components/Actions/Concerns/BelongsToComponent.php rename packages/{forms => schema}/resources/views/components/actions.blade.php (100%) rename packages/{forms => schema}/resources/views/components/actions/action-container.blade.php (100%) rename packages/{forms => schema}/src/Components/Actions.php (86%) rename packages/{forms => schema}/src/Components/Actions/ActionContainer.php (81%) rename packages/{panels => schema}/src/Components/Component.php (96%) diff --git a/docs-assets/app/app/Livewire/Forms/FieldsDemo.php b/docs-assets/app/app/Livewire/Forms/FieldsDemo.php index 4a86effb92..df7dec1703 100644 --- a/docs-assets/app/app/Livewire/Forms/FieldsDemo.php +++ b/docs-assets/app/app/Livewire/Forms/FieldsDemo.php @@ -2,7 +2,7 @@ namespace App\Livewire\Forms; -use Filament\Forms\Components\Actions\Action; +use Filament\Actions\Action; use Filament\Forms\Components\Builder; use Filament\Forms\Components\Checkbox; use Filament\Forms\Components\CheckboxList; diff --git a/docs-assets/app/app/Livewire/Forms/LayoutDemo.php b/docs-assets/app/app/Livewire/Forms/LayoutDemo.php index c4604a6ee2..245f42996a 100644 --- a/docs-assets/app/app/Livewire/Forms/LayoutDemo.php +++ b/docs-assets/app/app/Livewire/Forms/LayoutDemo.php @@ -2,8 +2,8 @@ namespace App\Livewire\Forms; -use Filament\Forms\Components\Actions; -use Filament\Forms\Components\Actions\Action; +use Filament\Actions\Action; +use Filament\Components\Actions; use Filament\Forms\Components\Checkbox; use Filament\Forms\Components\Fieldset; use Filament\Forms\Components\Grid; diff --git a/packages/actions/src/Action.php b/packages/actions/src/Action.php index 6456f32add..cc62a0ed9b 100644 --- a/packages/actions/src/Action.php +++ b/packages/actions/src/Action.php @@ -2,18 +2,28 @@ namespace Filament\Actions; +use Exception; +use Filament\Components\Actions\ActionContainer; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Js; class Action extends MountableAction implements Contracts\Groupable, Contracts\HasRecord { + use Concerns\BelongsToComponent; use Concerns\CanSubmitForm; use Concerns\HasMountableArguments; use Concerns\InteractsWithRecord; public function getLivewireCallMountedActionName(): string { - return 'callMountedAction'; + return $this->getComponent() ? + 'callMountedFormComponentAction' : + 'callMountedAction'; + } + + public function getLivewire(): object + { + return $this->getComponent()?->getLivewire() ?? parent::getLivewire(); } public function getLivewireClickHandler(): ?string @@ -37,7 +47,21 @@ class Action extends MountableAction implements Contracts\Groupable, Contracts\H $argumentsParameter .= Js::from($arguments); } - return "mountAction('{$this->getName()}'{$argumentsParameter})"; + $component = $this->getComponent(); + + if (! $component) { + return "mountAction('{$this->getName()}'{$argumentsParameter})"; + } + + $componentKey = $component->getKey(); + + if (blank($componentKey)) { + $componentClass = $this->getComponent()::class; + + throw new Exception("The component [{$componentClass}] must have a [key()] set in order to use actions. This [key()] must be a unique identifier for the component."); + } + + return "mountFormComponentAction('{$componentKey}', '{$this->getName()}'{$argumentsParameter})"; } /** @@ -46,8 +70,13 @@ class Action extends MountableAction implements Contracts\Groupable, Contracts\H protected function resolveDefaultClosureDependencyForEvaluationByName(string $parameterName): array { return match ($parameterName) { - 'model' => [$this->getModel()], - 'record' => [$this->getRecord()], + 'component' => [$this->getComponent()], + 'context', 'operation' => [$this->getComponent()->getContainer()->getOperation()], + 'get' => [$this->getComponent()->makeGetUtility()], + 'model' => [$this->getModel() ?? $this->getComponent()?->getModel()], + 'record' => [$this->getRecord() ?? $this->getComponent()?->getRecord()], + 'set' => [$this->getComponent()->makeSetUtility()], + 'state' => [$this->getComponent()->getState()], default => parent::resolveDefaultClosureDependencyForEvaluationByName($parameterName), }; } @@ -57,7 +86,7 @@ class Action extends MountableAction implements Contracts\Groupable, Contracts\H */ protected function resolveDefaultClosureDependencyForEvaluationByType(string $parameterType): array { - $record = $this->getRecord(); + $record = $this->getRecord() ?? $this->getComponent()?->getRecord(); if (! $record) { return parent::resolveDefaultClosureDependencyForEvaluationByType($parameterType); @@ -85,6 +114,17 @@ class Action extends MountableAction implements Contracts\Groupable, Contracts\H public function getInfolistName(): string { - return 'mountedActionInfolist'; + return $this->getComponent() ? + 'mountedFormComponentActionInfolist' : + 'mountedActionInfolist'; + } + + public function toFormComponent(): ActionContainer + { + $component = ActionContainer::make($this); + + $this->component($component); + + return $component; } } diff --git a/packages/actions/src/Concerns/BelongsToComponent.php b/packages/actions/src/Concerns/BelongsToComponent.php new file mode 100644 index 0000000000..97e0fb63c8 --- /dev/null +++ b/packages/actions/src/Concerns/BelongsToComponent.php @@ -0,0 +1,23 @@ +component = $component; + + return $this; + } + + public function getComponent(): ?Component + { + return $this->component; + } +} diff --git a/packages/forms/docs/03-fields/03-select.md b/packages/forms/docs/03-fields/03-select.md index e32090b200..4696682c59 100644 --- a/packages/forms/docs/03-fields/03-select.md +++ b/packages/forms/docs/03-fields/03-select.md @@ -624,8 +624,7 @@ This field uses action objects for easy customization of buttons within it. You Here is an example of how you might customize an action: ```php -use Filament\Forms\Components\Actions\Action; -use Filament\Forms\Components\Select; +use Filament\Actions\Action;use Filament\Forms\Components\Select; Select::make('author_id') ->relationship(name: 'author', titleAttribute: 'name') diff --git a/packages/forms/docs/03-fields/06-checkbox-list.md b/packages/forms/docs/03-fields/06-checkbox-list.md index c6155c4983..ef7d4bcfc4 100644 --- a/packages/forms/docs/03-fields/06-checkbox-list.md +++ b/packages/forms/docs/03-fields/06-checkbox-list.md @@ -309,8 +309,7 @@ This field uses action objects for easy customization of buttons within it. You Here is an example of how you might customize an action: ```php -use Filament\Forms\Components\Actions\Action; -use Filament\Forms\Components\CheckboxList; +use Filament\Actions\Action;use Filament\Forms\Components\CheckboxList; CheckboxList::make('technologies') ->options([ diff --git a/packages/forms/docs/03-fields/12-repeater.md b/packages/forms/docs/03-fields/12-repeater.md index a3e3cd10f2..dcf6177204 100644 --- a/packages/forms/docs/03-fields/12-repeater.md +++ b/packages/forms/docs/03-fields/12-repeater.md @@ -581,8 +581,7 @@ This field uses action objects for easy customization of buttons within it. You Here is an example of how you might customize an action: ```php -use Filament\Forms\Components\Actions\Action; -use Filament\Forms\Components\Repeater; +use Filament\Actions\Action;use Filament\Forms\Components\Repeater; Repeater::make('members') ->schema([ @@ -598,8 +597,7 @@ Repeater::make('members') You can confirm actions with a modal by using the `requiresConfirmation()` method on the action object. You may use any [modal customization method](../../actions/modals) to change its content and behaviour: ```php -use Filament\Forms\Components\Actions\Action; -use Filament\Forms\Components\Repeater; +use Filament\Actions\Action;use Filament\Forms\Components\Repeater; Repeater::make('members') ->schema([ @@ -617,10 +615,7 @@ Repeater::make('members') You may add new [action buttons](../actions) to the header of each repeater item by passing `Action` objects into `extraItemActions()`: ```php -use Filament\Forms\Components\Actions\Action; -use Filament\Forms\Components\Repeater; -use Filament\Forms\Components\TextInput; -use Illuminate\Support\Facades\Mail; +use Filament\Actions\Action;use Filament\Forms\Components\Repeater;use Filament\Forms\Components\TextInput;use Illuminate\Support\Facades\Mail; Repeater::make('members') ->schema([ diff --git a/packages/forms/docs/03-fields/13-builder.md b/packages/forms/docs/03-fields/13-builder.md index 8e065c58ea..61f0f22f6b 100644 --- a/packages/forms/docs/03-fields/13-builder.md +++ b/packages/forms/docs/03-fields/13-builder.md @@ -373,8 +373,7 @@ This field uses action objects for easy customization of buttons within it. You Here is an example of how you might customize an action: ```php -use Filament\Forms\Components\Actions\Action; -use Filament\Forms\Components\Builder; +use Filament\Actions\Action;use Filament\Forms\Components\Builder; Builder::make('content') ->blocks([ @@ -390,8 +389,7 @@ Builder::make('content') You can confirm actions with a modal by using the `requiresConfirmation()` method on the action object. You may use any [modal customization method](../../actions/modals) to change its content and behaviour: ```php -use Filament\Forms\Components\Actions\Action; -use Filament\Forms\Components\Builder; +use Filament\Actions\Action;use Filament\Forms\Components\Builder; Builder::make('content') ->blocks([ @@ -409,10 +407,7 @@ Builder::make('content') You may add new [action buttons](../actions) to the header of each builder item by passing `Action` objects into `extraItemActions()`: ```php -use Filament\Forms\Components\Actions\Action; -use Filament\Forms\Components\Builder; -use Filament\Forms\Components\TextInput; -use Illuminate\Support\Facades\Mail; +use Filament\Actions\Action;use Filament\Forms\Components\Builder;use Filament\Forms\Components\TextInput;use Illuminate\Support\Facades\Mail; Builder::make('content') ->blocks([ diff --git a/packages/forms/docs/03-fields/16-key-value.md b/packages/forms/docs/03-fields/16-key-value.md index 309d770838..1a0e32b7a3 100644 --- a/packages/forms/docs/03-fields/16-key-value.md +++ b/packages/forms/docs/03-fields/16-key-value.md @@ -165,8 +165,7 @@ This field uses action objects for easy customization of buttons within it. You Here is an example of how you might customize an action: ```php -use Filament\Forms\Components\Actions\Action; -use Filament\Forms\Components\KeyValue; +use Filament\Actions\Action;use Filament\Forms\Components\KeyValue; KeyValue::make('meta') ->deleteAction( diff --git a/packages/forms/docs/04-layout/05-wizard.md b/packages/forms/docs/04-layout/05-wizard.md index 0fd7fa3fc7..c1baa26aa9 100644 --- a/packages/forms/docs/04-layout/05-wizard.md +++ b/packages/forms/docs/04-layout/05-wizard.md @@ -213,8 +213,7 @@ This component uses action objects for easy customization of buttons within it. Here is an example of how you might customize an action: ```php -use Filament\Forms\Components\Actions\Action; -use Filament\Forms\Components\Wizard; +use Filament\Actions\Action;use Filament\Forms\Components\Wizard; Wizard::make([ // ... diff --git a/packages/forms/docs/04-layout/06-section.md b/packages/forms/docs/04-layout/06-section.md index 5ca9a248e4..adeda54f63 100644 --- a/packages/forms/docs/04-layout/06-section.md +++ b/packages/forms/docs/04-layout/06-section.md @@ -41,8 +41,7 @@ Sections can have actions in their [header](#adding-actions-to-the-sections-head You may add [actions](../actions) to the section's header using the `headerActions()` method: ```php -use Filament\Forms\Components\Actions\Action; -use Filament\Forms\Components\Section; +use Filament\Actions\Action;use Filament\Forms\Components\Section; Section::make('Rate limiting') ->headerActions([ @@ -65,8 +64,7 @@ Section::make('Rate limiting') In addition to [header actions](#adding-an-icon-to-the-sections-header), you may add [actions](../actions) to the section's footer using the `footerActions()` method: ```php -use Filament\Forms\Components\Actions\Action; -use Filament\Forms\Components\Section; +use Filament\Actions\Action;use Filament\Forms\Components\Section; Section::make('Rate limiting') ->schema([ @@ -89,9 +87,7 @@ Section::make('Rate limiting') Footer actions are aligned to the inline start by default. You may customize the alignment using the `footerActionsAlignment()` method: ```php -use Filament\Forms\Components\Actions\Action; -use Filament\Forms\Components\Section; -use Filament\Support\Enums\Alignment; +use Filament\Actions\Action;use Filament\Forms\Components\Section;use Filament\Support\Enums\Alignment; Section::make('Rate limiting') ->schema([ diff --git a/packages/forms/docs/06-actions.md b/packages/forms/docs/06-actions.md index 6c66562768..9c39dc89dc 100644 --- a/packages/forms/docs/06-actions.md +++ b/packages/forms/docs/06-actions.md @@ -12,8 +12,7 @@ Filament's forms can use [Actions](../actions). They are buttons that can be add Action objects inside a form component are instances of `Filament/Forms/Components/Actions/Action`. You must pass a unique name to the action's `make()` method, which is used to identify it amongst others internally within Filament. You can [customize the trigger button](../actions/trigger-button) of an action, and even [open a modal](../actions/modals) with little effort: ```php -use App\Actions\ResetStars; -use Filament\Forms\Components\Actions\Action; +use App\Actions\ResetStars;use Filament\Actions\Action; Action::make('resetStars') ->icon('heroicon-m-x-mark') @@ -36,7 +35,7 @@ Certain fields support "affix actions", which are buttons that can be placed bef To define an affix action, you can pass it to either `prefixAction()` or `suffixAction()`: ```php -use Filament\Components\Utilities\Set;use Filament\Forms\Components\Actions\Action;use Filament\Forms\Components\TextInput; +use Filament\Actions\Action;use Filament\Components\Utilities\Set;use Filament\Forms\Components\TextInput; TextInput::make('cost') ->prefix('€') @@ -59,8 +58,7 @@ Notice `$set` and `$state` injected into the `action()` function in this example You may pass multiple affix actions to a field by passing them in an array to either `prefixActions()` or `suffixActions()`. Either method can be used, or both at once, Filament will render all the registered actions in order: ```php -use Filament\Forms\Components\Actions\Action; -use Filament\Forms\Components\TextInput; +use Filament\Actions\Action;use Filament\Forms\Components\TextInput; TextInput::make('cost') ->prefix('€') @@ -80,7 +78,7 @@ TextInput::make('cost') All fields support "hint actions", which are rendered aside the field's [hint](fields/getting-started#adding-a-hint-next-to-the-label). To add a hint action to a field, you may pass it to `hintAction()`: ```php -use Filament\Components\Utilities\Set;use Filament\Forms\Components\Actions\Action;use Filament\Forms\Components\TextInput; +use Filament\Actions\Action;use Filament\Components\Utilities\Set;use Filament\Forms\Components\TextInput; TextInput::make('cost') ->prefix('€') @@ -103,8 +101,7 @@ Notice `$set` and `$state` injected into the `action()` function in this example You may pass multiple hint actions to a field by passing them in an array to `hintActions()`. Filament will render all the registered actions in order: ```php -use Filament\Forms\Components\Actions\Action; -use Filament\Forms\Components\TextInput; +use Filament\Actions\Action;use Filament\Forms\Components\TextInput; TextInput::make('cost') ->prefix('€') @@ -120,7 +117,7 @@ TextInput::make('cost') If you wish to render an action within a custom form component, `ViewField` object, or `View` component object, you may do so using the `registerActions()` method: ```php -use Filament\Components\Utilities\Set;use Filament\Forms\Components\Actions\Action;use Filament\Forms\Components\ViewField; +use Filament\Actions\Action;use Filament\Components\Utilities\Set;use Filament\Forms\Components\ViewField; ViewField::make('rating') ->view('filament.forms.components.range-slider') @@ -150,10 +147,7 @@ Now, to render the action in the view of the custom component, you need to call You may use an `Actions` component to render a set of actions anywhere in the form, avoiding the need to register them to any particular component: ```php -use App\Actions\Star; -use App\Actions\ResetStars; -use Filament\Forms\Components\Actions; -use Filament\Forms\Components\Actions\Action; +use App\Actions\ResetStars;use App\Actions\Star;use Filament\Actions\Action;use Filament\Components\Actions; Actions::make([ Action::make('star') @@ -179,7 +173,7 @@ Actions::make([ You can stretch the independent form actions to consume the full width of the form using `fullWidth()`: ```php -use Filament\Forms\Components\Actions; +use Filament\Components\Actions; Actions::make([ // ... @@ -193,8 +187,7 @@ Actions::make([ Independent form actions are aligned to the start of the component by default. You may change this by passing `Alignment::Center` or `Alignment::End` to `alignment()`: ```php -use Filament\Forms\Components\Actions; -use Filament\Support\Enums\Alignment; +use Filament\Components\Actions;use Filament\Support\Enums\Alignment; Actions::make([ // ... @@ -208,8 +201,7 @@ Actions::make([ Independent form actions are vertically aligned to the start of the component by default. You may change this by passing `Alignment::Center` or `Alignment::End` to `verticalAlignment()`: ```php -use Filament\Forms\Components\Actions; -use Filament\Support\Enums\VerticalAlignment; +use Filament\Components\Actions;use Filament\Support\Enums\VerticalAlignment; Actions::make([ // ... @@ -223,7 +215,7 @@ Actions::make([ If an action is attached to a form component, the `action()` function is able to [inject utilities](advanced#form-component-utility-injection) directly from that form component. For instance, you can inject [`$set`](advanced#injecting-a-function-to-set-the-state-of-another-field) and [`$state`](advanced#injecting-the-current-state-of-a-field): ```php -use Filament\Components\Utilities\Set;use Filament\Forms\Components\Actions\Action; +use Filament\Actions\Action;use Filament\Components\Utilities\Set; Action::make('copyCostToPrice') ->icon('heroicon-m-clipboard') diff --git a/packages/forms/resources/views/components/builder.blade.php b/packages/forms/resources/views/components/builder.blade.php index d8aa30628e..0b8e4883ce 100644 --- a/packages/forms/resources/views/components/builder.blade.php +++ b/packages/forms/resources/views/components/builder.blade.php @@ -1,5 +1,5 @@ @php - use Filament\Forms\Components\Actions\Action; + use Filament\Actions\Action; $containers = $getChildComponentContainers(); $blockPickerBlocks = $getBlockPickerBlocks(); diff --git a/packages/forms/resources/views/components/field-wrapper/index.blade.php b/packages/forms/resources/views/components/field-wrapper/index.blade.php index b4b5aa5537..edeeb3b4f4 100644 --- a/packages/forms/resources/views/components/field-wrapper/index.blade.php +++ b/packages/forms/resources/views/components/field-wrapper/index.blade.php @@ -43,7 +43,7 @@ $hintActions = array_filter( $hintActions ?? [], - fn (\Filament\Forms\Components\Actions\Action $hintAction): bool => $hintAction->isVisible(), + fn (\Filament\Actions\Action $hintAction): bool => $hintAction->isVisible(), ); $hasError = filled($statePath) && ($errors->has($statePath) || ($hasNestedRecursiveValidationRules && $errors->has("{$statePath}.*"))); diff --git a/packages/forms/resources/views/components/repeater/index.blade.php b/packages/forms/resources/views/components/repeater/index.blade.php index 9d94205272..b17c582de8 100644 --- a/packages/forms/resources/views/components/repeater/index.blade.php +++ b/packages/forms/resources/views/components/repeater/index.blade.php @@ -1,5 +1,5 @@ @php - use Filament\Forms\Components\Actions\Action; + use Filament\Actions\Action; $containers = $getChildComponentContainers(); diff --git a/packages/forms/src/Components/Actions/Action.php b/packages/forms/src/Components/Actions/Action.php deleted file mode 100644 index ce4847036b..0000000000 --- a/packages/forms/src/Components/Actions/Action.php +++ /dev/null @@ -1,101 +0,0 @@ -isLivewireClickHandlerEnabled()) { - return null; - } - - if (is_string($this->action)) { - return $this->action; - } - - if ($event = $this->getLivewireEventClickHandler()) { - return $event; - } - - $argumentsParameter = ''; - - if (count($arguments = $this->getArguments())) { - $argumentsParameter .= ', '; - $argumentsParameter .= Js::from($arguments); - $argumentsParameter .= ''; - } - - $componentKey = $this->getComponent()->getKey(); - - if (blank($componentKey)) { - $componentClass = $this->getComponent()::class; - - throw new Exception("The form component [{$componentClass}] must have a [key()] set in order to use actions. This [key()] must be a unique identifier for the component."); - } - - return "mountFormComponentAction('{$componentKey}', '{$this->getName()}'{$argumentsParameter})"; - } - - public function toFormComponent(): ActionContainer - { - $component = ActionContainer::make($this); - - $this->component($component); - - return $component; - } - - /** - * @return array - */ - protected function resolveDefaultClosureDependencyForEvaluationByName(string $parameterName): array - { - return match ($parameterName) { - 'component' => [$this->getComponent()], - 'context', 'operation' => [$this->getComponent()->getContainer()->getOperation()], - 'get' => [$this->getComponent()->getGetCallback()], - 'model' => [$this->getComponent()->getModel()], - 'record' => [$this->getComponent()->getRecord()], - 'set' => [$this->getComponent()->getSetCallback()], - 'state' => [$this->getComponent()->getState()], - default => parent::resolveDefaultClosureDependencyForEvaluationByName($parameterName), - }; - } - - /** - * @return array - */ - protected function resolveDefaultClosureDependencyForEvaluationByType(string $parameterType): array - { - $record = $this->getComponent()->getRecord(); - - if (! $record) { - return parent::resolveDefaultClosureDependencyForEvaluationByType($parameterType); - } - - return match ($parameterType) { - Model::class, $record::class => [$record], - default => parent::resolveDefaultClosureDependencyForEvaluationByType($parameterType), - }; - } - - public function getInfolistName(): string - { - return 'mountedFormComponentActionInfolist'; - } -} diff --git a/packages/forms/src/Components/Actions/Concerns/BelongsToComponent.php b/packages/forms/src/Components/Actions/Concerns/BelongsToComponent.php deleted file mode 100644 index d9070f538a..0000000000 --- a/packages/forms/src/Components/Actions/Concerns/BelongsToComponent.php +++ /dev/null @@ -1,28 +0,0 @@ -component = $component; - - return $this; - } - - public function getComponent(): Component - { - return $this->component; - } - - public function getLivewire(): HasForms - { - return $this->getComponent()->getLivewire(); - } -} diff --git a/packages/forms/src/Components/Builder.php b/packages/forms/src/Components/Builder.php index 44a68451b7..273a5c8e68 100644 --- a/packages/forms/src/Components/Builder.php +++ b/packages/forms/src/Components/Builder.php @@ -3,8 +3,8 @@ namespace Filament\Forms\Components; use Closure; +use Filament\Actions\Action; use Filament\ComponentContainer; -use Filament\Forms\Components\Actions\Action; use Filament\Forms\Components\Builder\Block; use Filament\Support\Concerns\HasReorderAnimationDuration; use Filament\Support\Enums\ActionSize; diff --git a/packages/forms/src/Components/CheckboxList.php b/packages/forms/src/Components/CheckboxList.php index fc9576fb8b..7a2859c97f 100644 --- a/packages/forms/src/Components/CheckboxList.php +++ b/packages/forms/src/Components/CheckboxList.php @@ -3,7 +3,7 @@ namespace Filament\Forms\Components; use Closure; -use Filament\Forms\Components\Actions\Action; +use Filament\Actions\Action; use Filament\Support\Enums\ActionSize; use Filament\Support\Services\RelationshipJoiner; use Illuminate\Contracts\Support\Htmlable; diff --git a/packages/forms/src/Components/Concerns/HasAffixes.php b/packages/forms/src/Components/Concerns/HasAffixes.php index 8758faeaff..175f427cb6 100644 --- a/packages/forms/src/Components/Concerns/HasAffixes.php +++ b/packages/forms/src/Components/Concerns/HasAffixes.php @@ -3,7 +3,7 @@ namespace Filament\Forms\Components\Concerns; use Closure; -use Filament\Forms\Components\Actions\Action; +use Filament\Actions\Action; use Filament\Support\Enums\ActionSize; use Illuminate\Contracts\Support\Htmlable; use Illuminate\Support\Arr; diff --git a/packages/forms/src/Components/Concerns/HasExtraItemActions.php b/packages/forms/src/Components/Concerns/HasExtraItemActions.php index f53d8af67b..539bca7e70 100644 --- a/packages/forms/src/Components/Concerns/HasExtraItemActions.php +++ b/packages/forms/src/Components/Concerns/HasExtraItemActions.php @@ -3,7 +3,7 @@ namespace Filament\Forms\Components\Concerns; use Closure; -use Filament\Forms\Components\Actions\Action; +use Filament\Actions\Action; use Filament\Support\Enums\ActionSize; use Illuminate\Support\Arr; diff --git a/packages/forms/src/Components/Concerns/HasFooterActions.php b/packages/forms/src/Components/Concerns/HasFooterActions.php index bc852a5621..e081b0d533 100644 --- a/packages/forms/src/Components/Concerns/HasFooterActions.php +++ b/packages/forms/src/Components/Concerns/HasFooterActions.php @@ -3,7 +3,7 @@ namespace Filament\Forms\Components\Concerns; use Closure; -use Filament\Forms\Components\Actions\Action; +use Filament\Actions\Action; use Filament\Support\Concerns\HasFooterActionsAlignment; use Illuminate\Support\Arr; diff --git a/packages/forms/src/Components/Concerns/HasHeaderActions.php b/packages/forms/src/Components/Concerns/HasHeaderActions.php index 34aa0b27d0..8b377f32ee 100644 --- a/packages/forms/src/Components/Concerns/HasHeaderActions.php +++ b/packages/forms/src/Components/Concerns/HasHeaderActions.php @@ -3,7 +3,7 @@ namespace Filament\Forms\Components\Concerns; use Closure; -use Filament\Forms\Components\Actions\Action; +use Filament\Actions\Action; use Illuminate\Support\Arr; trait HasHeaderActions diff --git a/packages/forms/src/Components/Concerns/HasHint.php b/packages/forms/src/Components/Concerns/HasHint.php index 9417476310..87c70f75f8 100644 --- a/packages/forms/src/Components/Concerns/HasHint.php +++ b/packages/forms/src/Components/Concerns/HasHint.php @@ -3,7 +3,7 @@ namespace Filament\Forms\Components\Concerns; use Closure; -use Filament\Forms\Components\Actions\Action; +use Filament\Actions\Action; use Filament\Support\Enums\ActionSize; use Illuminate\Contracts\Support\Htmlable; use Illuminate\Support\Arr; diff --git a/packages/forms/src/Components/Contracts/HasAffixActions.php b/packages/forms/src/Components/Contracts/HasAffixActions.php index 5533e92c4f..6d064f0939 100644 --- a/packages/forms/src/Components/Contracts/HasAffixActions.php +++ b/packages/forms/src/Components/Contracts/HasAffixActions.php @@ -2,7 +2,7 @@ namespace Filament\Forms\Components\Contracts; -use Filament\Forms\Components\Actions\Action; +use Filament\Actions\Action; interface HasAffixActions { diff --git a/packages/forms/src/Components/Contracts/HasExtraItemActions.php b/packages/forms/src/Components/Contracts/HasExtraItemActions.php index c73feed53f..908b1b267b 100644 --- a/packages/forms/src/Components/Contracts/HasExtraItemActions.php +++ b/packages/forms/src/Components/Contracts/HasExtraItemActions.php @@ -2,7 +2,7 @@ namespace Filament\Forms\Components\Contracts; -use Filament\Forms\Components\Actions\Action; +use Filament\Actions\Action; interface HasExtraItemActions { diff --git a/packages/forms/src/Components/Contracts/HasFooterActions.php b/packages/forms/src/Components/Contracts/HasFooterActions.php index b0d6e6aeff..dac4fa399b 100644 --- a/packages/forms/src/Components/Contracts/HasFooterActions.php +++ b/packages/forms/src/Components/Contracts/HasFooterActions.php @@ -2,7 +2,7 @@ namespace Filament\Forms\Components\Contracts; -use Filament\Forms\Components\Actions\Action; +use Filament\Actions\Action; interface HasFooterActions { diff --git a/packages/forms/src/Components/Contracts/HasHeaderActions.php b/packages/forms/src/Components/Contracts/HasHeaderActions.php index d26903e1d3..62fb3be1bf 100644 --- a/packages/forms/src/Components/Contracts/HasHeaderActions.php +++ b/packages/forms/src/Components/Contracts/HasHeaderActions.php @@ -2,7 +2,7 @@ namespace Filament\Forms\Components\Contracts; -use Filament\Forms\Components\Actions\Action; +use Filament\Actions\Action; interface HasHeaderActions { diff --git a/packages/forms/src/Components/Contracts/HasHintActions.php b/packages/forms/src/Components/Contracts/HasHintActions.php index fc19469999..e64177128b 100644 --- a/packages/forms/src/Components/Contracts/HasHintActions.php +++ b/packages/forms/src/Components/Contracts/HasHintActions.php @@ -2,7 +2,7 @@ namespace Filament\Forms\Components\Contracts; -use Filament\Forms\Components\Actions\Action; +use Filament\Actions\Action; interface HasHintActions { diff --git a/packages/forms/src/Components/KeyValue.php b/packages/forms/src/Components/KeyValue.php index ae06722665..15594cdeb1 100644 --- a/packages/forms/src/Components/KeyValue.php +++ b/packages/forms/src/Components/KeyValue.php @@ -3,7 +3,7 @@ namespace Filament\Forms\Components; use Closure; -use Filament\Forms\Components\Actions\Action; +use Filament\Actions\Action; use Filament\Support\Concerns\HasExtraAlpineAttributes; use Filament\Support\Concerns\HasReorderAnimationDuration; use Filament\Support\Enums\ActionSize; diff --git a/packages/forms/src/Components/Repeater.php b/packages/forms/src/Components/Repeater.php index 2f020573b6..87abfebdfe 100644 --- a/packages/forms/src/Components/Repeater.php +++ b/packages/forms/src/Components/Repeater.php @@ -3,8 +3,8 @@ namespace Filament\Forms\Components; use Closure; +use Filament\Actions\Action; use Filament\ComponentContainer; -use Filament\Forms\Components\Actions\Action; use Filament\Forms\Contracts\HasForms; use Filament\Support\Concerns\HasReorderAnimationDuration; use Filament\Support\Enums\ActionSize; diff --git a/packages/forms/src/Components/Select.php b/packages/forms/src/Components/Select.php index 8bef056942..fbbf1dba22 100644 --- a/packages/forms/src/Components/Select.php +++ b/packages/forms/src/Components/Select.php @@ -4,9 +4,9 @@ namespace Filament\Forms\Components; use Closure; use Exception; +use Filament\Actions\Action; use Filament\ComponentContainer; use Filament\Components\Component; -use Filament\Forms\Components\Actions\Action; use Filament\Forms\Form; use Filament\Support\Concerns\HasExtraAlpineAttributes; use Filament\Support\Facades\FilamentIcon; diff --git a/packages/forms/src/Components/TextInput/Actions/HidePasswordAction.php b/packages/forms/src/Components/TextInput/Actions/HidePasswordAction.php index daf35ca306..b438601ad6 100644 --- a/packages/forms/src/Components/TextInput/Actions/HidePasswordAction.php +++ b/packages/forms/src/Components/TextInput/Actions/HidePasswordAction.php @@ -2,7 +2,7 @@ namespace Filament\Forms\Components\TextInput\Actions; -use Filament\Forms\Components\Actions\Action; +use Filament\Actions\Action; use Filament\Support\Facades\FilamentIcon; class HidePasswordAction extends Action diff --git a/packages/forms/src/Components/TextInput/Actions/ShowPasswordAction.php b/packages/forms/src/Components/TextInput/Actions/ShowPasswordAction.php index 471fa84eff..b1e149c95c 100644 --- a/packages/forms/src/Components/TextInput/Actions/ShowPasswordAction.php +++ b/packages/forms/src/Components/TextInput/Actions/ShowPasswordAction.php @@ -2,7 +2,7 @@ namespace Filament\Forms\Components\TextInput\Actions; -use Filament\Forms\Components\Actions\Action; +use Filament\Actions\Action; use Filament\Support\Facades\FilamentIcon; class ShowPasswordAction extends Action diff --git a/packages/forms/src/Components/Wizard.php b/packages/forms/src/Components/Wizard.php index f47a3a5eda..de91ef17ab 100644 --- a/packages/forms/src/Components/Wizard.php +++ b/packages/forms/src/Components/Wizard.php @@ -3,8 +3,8 @@ namespace Filament\Forms\Components; use Closure; +use Filament\Actions\Action; use Filament\Components\Component; -use Filament\Forms\Components\Actions\Action; use Filament\Forms\Components\Wizard\Step; use Filament\Support\Concerns; use Filament\Support\Enums\IconPosition; diff --git a/packages/forms/src/Concerns/HasFormComponentActions.php b/packages/forms/src/Concerns/HasFormComponentActions.php index 61fd3dbff7..1f1112a800 100644 --- a/packages/forms/src/Concerns/HasFormComponentActions.php +++ b/packages/forms/src/Concerns/HasFormComponentActions.php @@ -2,9 +2,9 @@ namespace Filament\Forms\Concerns; +use Filament\Actions\Action; use Filament\ComponentContainer; use Filament\Components\Component; -use Filament\Forms\Components\Actions\Action; use Filament\Forms\Form; use Filament\Support\Exceptions\Cancel; use Filament\Support\Exceptions\Halt; diff --git a/packages/panels/docs/03-resources/04-editing-records.md b/packages/panels/docs/03-resources/04-editing-records.md index ee5a1ab4b2..c64b6af960 100644 --- a/packages/panels/docs/03-resources/04-editing-records.md +++ b/packages/panels/docs/03-resources/04-editing-records.md @@ -183,10 +183,7 @@ Alternatively, if you're editing records in a modal action, check out the [Actio You may want to allow the user to save a part of the form independently of the rest of the form. One way to do this is with a [section action in the header or footer](../../forms/layout/section#adding-actions-to-the-sections-header-or-footer). From the `action()` method, you can call `saveFormComponentOnly()`, passing in the `Section` component that you want to save: ```php -use Filament\Forms\Components\Actions\Action; -use Filament\Forms\Components\Section; -use Filament\Notifications\Notification; -use Filament\Resources\Pages\EditRecord; +use Filament\Actions\Action;use Filament\Forms\Components\Section;use Filament\Notifications\Notification;use Filament\Resources\Pages\EditRecord; Section::make('Rate limiting') ->schema([ diff --git a/packages/forms/resources/views/components/actions.blade.php b/packages/schema/resources/views/components/actions.blade.php similarity index 100% rename from packages/forms/resources/views/components/actions.blade.php rename to packages/schema/resources/views/components/actions.blade.php diff --git a/packages/forms/resources/views/components/actions/action-container.blade.php b/packages/schema/resources/views/components/actions/action-container.blade.php similarity index 100% rename from packages/forms/resources/views/components/actions/action-container.blade.php rename to packages/schema/resources/views/components/actions/action-container.blade.php diff --git a/packages/schema/src/ComponentContainer.php b/packages/schema/src/ComponentContainer.php index c4583ed5fc..93fe1c5fb1 100644 --- a/packages/schema/src/ComponentContainer.php +++ b/packages/schema/src/ComponentContainer.php @@ -29,7 +29,7 @@ class ComponentContainer extends ViewComponent use Components\Concerns\HasStateBindingModifiers; use HasExtraAttributes; - protected string $view = 'filament::component-container'; + protected string $view = 'filament-schema::component-container'; protected string $evaluationIdentifier = 'container'; diff --git a/packages/forms/src/Components/Actions.php b/packages/schema/src/Components/Actions.php similarity index 86% rename from packages/forms/src/Components/Actions.php rename to packages/schema/src/Components/Actions.php index 0ea0d54cdc..fd0f85d428 100644 --- a/packages/forms/src/Components/Actions.php +++ b/packages/schema/src/Components/Actions.php @@ -1,10 +1,9 @@ [$this->getContainer()->getOperation()], - 'get' => [$this->getGetCallback()], + 'get' => [$this->makeGetUtility()], 'livewire' => [$this->getLivewire()], 'model' => [$this->getModel()], 'record' => [$this->getRecord()], - 'set' => [$this->getSetCallback()], + 'set' => [$this->makeSetUtility()], 'state' => [$this->getState()], default => parent::resolveDefaultClosureDependencyForEvaluationByName($parameterName), }; diff --git a/packages/schema/src/Components/Concerns/HasActions.php b/packages/schema/src/Components/Concerns/HasActions.php index 8d9215fee5..b0eb5c77d7 100644 --- a/packages/schema/src/Components/Concerns/HasActions.php +++ b/packages/schema/src/Components/Concerns/HasActions.php @@ -3,7 +3,7 @@ namespace Filament\Components\Concerns; use Closure; -use Filament\Forms\Components\Actions\Action; +use Filament\Actions\Action; use Filament\Forms\Components\Contracts\HasAffixActions; use Filament\Forms\Components\Contracts\HasExtraItemActions; use Filament\Forms\Components\Contracts\HasFooterActions; diff --git a/packages/schema/src/Components/Concerns/HasState.php b/packages/schema/src/Components/Concerns/HasState.php index cb8d2e4222..2f82bfd05f 100644 --- a/packages/schema/src/Components/Concerns/HasState.php +++ b/packages/schema/src/Components/Concerns/HasState.php @@ -455,16 +455,32 @@ trait HasState return ! $this->isDehydratedWhenHidden(); } - public function getGetCallback(): Get + public function makeGetUtility(): Get { return new Get($this); } - public function getSetCallback(): Set + public function makeSetUtility(): Set { return new Set($this); } + /** + * @deprecated Use `makeGetUtility()` instead. + */ + public function getGetCallback(): Get + { + return $this->makeGetUtility(); + } + + /** + * @deprecated Use `makeSetUtility()` instead. + */ + public function getSetCallback(): Set + { + return $this->makeSetUtility(); + } + public function generateRelativeStatePath(string | Component $path, bool $isAbsolute = false): string { if ($path instanceof Component) { diff --git a/packages/schema/src/SchemaServiceProvider.php b/packages/schema/src/SchemaServiceProvider.php index 068f611c2f..e34ea59c59 100644 --- a/packages/schema/src/SchemaServiceProvider.php +++ b/packages/schema/src/SchemaServiceProvider.php @@ -13,7 +13,7 @@ class SchemaServiceProvider extends PackageServiceProvider public function configurePackage(Package $package): void { $package - ->name('filament') + ->name('filament-schema') ->hasCommands($this->getCommands()) ->hasTranslations() ->hasViews(); diff --git a/packages/schema/src/Testing/TestsComponentActions.php b/packages/schema/src/Testing/TestsComponentActions.php index fcb1442c14..62f9dc8641 100644 --- a/packages/schema/src/Testing/TestsComponentActions.php +++ b/packages/schema/src/Testing/TestsComponentActions.php @@ -3,8 +3,8 @@ namespace Filament\Testing; use Closure; +use Filament\Actions\Action; use Filament\ComponentContainer; -use Filament\Forms\Components\Actions\Action; use Filament\Forms\Contracts\HasForms; use Illuminate\Support\Arr; use Illuminate\Testing\Assert; diff --git a/packages/support/resources/views/components/input/wrapper.blade.php b/packages/support/resources/views/components/input/wrapper.blade.php index d4111b8452..9e1fe66e65 100644 --- a/packages/support/resources/views/components/input/wrapper.blade.php +++ b/packages/support/resources/views/components/input/wrapper.blade.php @@ -20,12 +20,12 @@ @php $prefixActions = array_filter( $prefixActions, - fn (\Filament\Forms\Components\Actions\Action $prefixAction): bool => $prefixAction->isVisible(), + fn (\Filament\Actions\Action $prefixAction): bool => $prefixAction->isVisible(), ); $suffixActions = array_filter( $suffixActions, - fn (\Filament\Forms\Components\Actions\Action $suffixAction): bool => $suffixAction->isVisible(), + fn (\Filament\Actions\Action $suffixAction): bool => $suffixAction->isVisible(), ); $hasPrefix = count($prefixActions) || $prefixIcon || filled($prefix); diff --git a/packages/tables/src/Actions/ButtonAction.php b/packages/tables/src/Actions/ButtonAction.php index 610ae4b5ee..e6dde36029 100644 --- a/packages/tables/src/Actions/ButtonAction.php +++ b/packages/tables/src/Actions/ButtonAction.php @@ -2,6 +2,8 @@ namespace Filament\Tables\Actions; +use Filament\Actions\Action; + /** * @deprecated Use `\Filament\Tables\Actions\Action` instead, with the `button()` method. * @see Action diff --git a/packages/tables/src/Actions/IconButtonAction.php b/packages/tables/src/Actions/IconButtonAction.php index beeca996fc..a2dd085f96 100644 --- a/packages/tables/src/Actions/IconButtonAction.php +++ b/packages/tables/src/Actions/IconButtonAction.php @@ -2,6 +2,8 @@ namespace Filament\Tables\Actions; +use Filament\Actions\Action; + /** * @deprecated Use `\Filament\Tables\Actions\Action` instead, with the `iconButton()` method. * @see Action diff --git a/packages/tables/src/Filters/QueryBuilder/Forms/Components/RuleBuilder.php b/packages/tables/src/Filters/QueryBuilder/Forms/Components/RuleBuilder.php index ea6ec8d2fe..1d0170a0db 100644 --- a/packages/tables/src/Filters/QueryBuilder/Forms/Components/RuleBuilder.php +++ b/packages/tables/src/Filters/QueryBuilder/Forms/Components/RuleBuilder.php @@ -3,9 +3,9 @@ namespace Filament\Tables\Filters\QueryBuilder\Forms\Components; use Exception; +use Filament\Actions\Action; use Filament\ComponentContainer; use Filament\Components\Component; -use Filament\Forms\Components\Actions\Action; use Filament\Forms\Components\Builder; use Filament\Forms\Components\Repeater; use Filament\Tables\Filters\QueryBuilder\Concerns\HasConstraints; diff --git a/packages/upgrade/src/rector.php b/packages/upgrade/src/rector.php index 60b5b10493..580dc869a4 100644 --- a/packages/upgrade/src/rector.php +++ b/packages/upgrade/src/rector.php @@ -93,13 +93,20 @@ return static function (RectorConfig $rectorConfig): void { 'Filament\\Forms\\Components\\Concerns\\HasMeta' => 'Filament\\Components\\Concerns\\HasMeta', 'Filament\\Forms\\Components\\Concerns\\HasState' => 'Filament\\Components\\Concerns\\HasState', 'Filament\\Forms\\Components\\Concerns\\ListensToEvents' => 'Filament\\Components\\Concerns\\ListensToEvents', + 'Filament\\Forms\\Components\\Actions\\Concerns\\BelongsToComponent' => 'Filament\\Actions\\Concerns\\BelongsToComponent', + 'Filament\\Forms\\Components\\Actions' => 'Filament\\Components\\Actions', + 'Filament\\Forms\\Components\\Actions\\Action' => 'Filament\\Actions\\Action', + 'Filament\\Forms\\Components\\Actions\\ActionContainer' => 'Filament\\Components\\Actions\\ActionContainer', + 'Filament\\Forms\\Components\\Actions\\ActionContainer' => 'Filament\\Components\\Actions\\ActionContainer', ], ); $rectorConfig->ruleWithConfiguration( RenameStringRector::class, [ - 'filament-forms::component-container' => 'filament::component-container', + 'filament-forms::component-container' => 'filament-schema::component-container', + 'filament-forms::components.actions' => 'filament-schema::components.actions', + 'filament-forms::components.actions.action-container' => 'filament-schema::components.actions.action-container', ], ); }; diff --git a/tests/src/Forms/ActionTest.php b/tests/src/Forms/ActionTest.php index 230ba49880..f8c742b48d 100644 --- a/tests/src/Forms/ActionTest.php +++ b/tests/src/Forms/ActionTest.php @@ -1,6 +1,6 @@