Skip to content

Commit

Permalink
Rename schema params to match type
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Feb 4, 2025
1 parent fc3ce96 commit c4b831b
Show file tree
Hide file tree
Showing 33 changed files with 268 additions and 131 deletions.
4 changes: 2 additions & 2 deletions packages/actions/src/AssociateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function setUp(): void

$this->form(fn (): array => [$this->getRecordSelect()]);

$this->action(function (array $arguments, array $data, Schema $form, Table $table): void {
$this->action(function (array $arguments, array $data, Schema $schema, Table $table): void {
/** @var HasMany | MorphMany $relationship */
$relationship = Relation::noConstraints(fn () => $table->getRelationship());

Expand Down Expand Up @@ -99,7 +99,7 @@ protected function setUp(): void

$this->record(null);

$form->fill();
$schema->fill();

$this->halt();

Expand Down
4 changes: 2 additions & 2 deletions packages/actions/src/AttachAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function setUp(): void

$this->form(fn (): array => [$this->getRecordSelect()]);

$this->action(function (array $arguments, array $data, Schema $form, Table $table): void {
$this->action(function (array $arguments, array $data, Schema $schema, Table $table): void {
/** @var BelongsToMany $relationship */
$relationship = Relation::noConstraints(fn () => $table->getRelationship());

Expand Down Expand Up @@ -101,7 +101,7 @@ protected function setUp(): void

$this->record(null);

$form->fill();
$schema->fill();

$this->halt();

Expand Down
10 changes: 5 additions & 5 deletions packages/actions/src/Concerns/CanBeMounted.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ public function mountUsing(?Closure $callback): static
*/
public function fillForm(array | Closure $data): static
{
$this->mountUsing(function (?Schema $form) use ($data): void {
$form?->fill($this->evaluate($data));
$this->mountUsing(function (?Schema $schema) use ($data): void {
$schema?->fill($this->evaluate($data));
});

return $this;
}

public function getMountUsing(): Closure
{
return $this->mountUsing ?? static function (?Schema $form = null): void {
if (! $form) {
return $this->mountUsing ?? static function (?Schema $schema = null): void {
if (! $schema) {
return;
}

$form->fill();
$schema->fill();
};
}
}
4 changes: 2 additions & 2 deletions packages/actions/src/Concerns/HasForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public function form(array | Closure | null $form): static
/**
* @deprecated Use `getSchema()` instead.
*/
public function getForm(Schema $form): ?Schema
public function getForm(Schema $schema): ?Schema
{
return $this->getSchema($form);
return $this->getSchema($schema);
}

public function mutateFormDataUsing(?Closure $callback): static
Expand Down
14 changes: 7 additions & 7 deletions packages/actions/src/CreateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ protected function setUp(): void

$this->record(null);

$this->action(function (array $arguments, Schema $form): void {
$this->action(function (array $arguments, Schema $schema): void {
if ($arguments['another'] ?? false) {
$preserveRawState = $this->evaluate($this->preserveFormDataWhenCreatingAnotherUsing, [
'data' => $form->getRawState(),
'data' => $schema->getRawState(),
]) ?? [];
}

Expand Down Expand Up @@ -104,7 +104,7 @@ protected function setUp(): void
});

$this->record($record);
$form->model($record)->saveRelationships();
$schema->model($record)->saveRelationships();

if ($arguments['another'] ?? false) {
$this->callAfter();
Expand All @@ -113,12 +113,12 @@ protected function setUp(): void
$this->record(null);

// Ensure that the form record is anonymized so that relationships aren't loaded.
$form->model($model);
$schema->model($model);

$form->fill();
$schema->fill();

$form->rawState([
...$form->getRawState(),
$schema->rawState([
...$schema->getRawState(),
...$preserveRawState ?? [],
]);

Expand Down
34 changes: 17 additions & 17 deletions packages/forms/src/Components/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,19 +281,19 @@ public function getCreateOptionAction(): ?Action

$action = Action::make($this->getCreateOptionActionName())
->label(__('filament-forms::components.select.actions.create_option.label'))
->form(function (Select $component, Schema $form): array | Schema | null {
return $component->getCreateOptionActionForm($form->model(
->form(function (Select $component, Schema $schema): array | Schema | null {
return $component->getCreateOptionActionForm($schema->model(
$component->getRelationship() ? $component->getRelationship()->getModel()::class : null,
));
})
->action(static function (Action $action, array $arguments, Select $component, array $data, Schema $form): void {
->action(static function (Action $action, array $arguments, Select $component, array $data, Schema $schema): void {
if (! $component->getCreateOptionUsing()) {
throw new Exception("Select field [{$component->getStatePath()}] must have a [createOptionUsing()] closure set.");
}

$createdOptionKey = $component->evaluate($component->getCreateOptionUsing(), [
'data' => $data,
'form' => $form,
'form' => $schema,
]);

$state = $component->isMultiple()
Expand All @@ -312,7 +312,7 @@ public function getCreateOptionAction(): ?Action

$action->callAfter();

$form->fill();
$schema->fill();

$action->halt();
})
Expand Down Expand Up @@ -365,9 +365,9 @@ public function editOptionAction(?Closure $callback): static
/**
* @return array<Component | Action | ActionGroup> | Schema | null
*/
public function getCreateOptionActionForm(Schema $form): array | Schema | null
public function getCreateOptionActionForm(Schema $schema): array | Schema | null
{
return $this->evaluate($this->createOptionActionForm, ['form' => $form]);
return $this->evaluate($this->createOptionActionForm, ['form' => $schema]);
}

public function hasCreateOptionActionFormSchema(): bool
Expand All @@ -378,9 +378,9 @@ public function hasCreateOptionActionFormSchema(): bool
/**
* @return array<Component | Action | ActionGroup> | Schema | null
*/
public function getEditOptionActionForm(Schema $form): array | Schema | null
public function getEditOptionActionForm(Schema $schema): array | Schema | null
{
return $this->evaluate($this->editOptionActionForm, ['form' => $form]);
return $this->evaluate($this->editOptionActionForm, ['form' => $schema]);
}

public function hasEditOptionActionFormSchema(): bool
Expand Down Expand Up @@ -436,20 +436,20 @@ public function getEditOptionAction(): ?Action

$action = Action::make($this->getEditOptionActionName())
->label(__('filament-forms::components.select.actions.edit_option.label'))
->form(function (Select $component, Schema $form): array | Schema | null {
->form(function (Select $component, Schema $schema): array | Schema | null {
return $component->getEditOptionActionForm(
$form->model($component->getSelectedRecord()),
$schema->model($component->getSelectedRecord()),
);
})
->fillForm($this->getEditOptionActionFormData())
->action(static function (Action $action, array $arguments, Select $component, array $data, Schema $form): void {
->action(static function (Action $action, array $arguments, Select $component, array $data, Schema $schema): void {
if (! $component->getUpdateOptionUsing()) {
throw new Exception("Select field [{$component->getStatePath()}] must have a [updateOptionUsing()] closure set.");
}

$component->evaluate($component->getUpdateOptionUsing(), [
'data' => $data,
'form' => $form,
'form' => $schema,
]);

$component->refreshSelectedOptionLabel();
Expand Down Expand Up @@ -1061,12 +1061,12 @@ public function relationship(string | Closure | null $name = null, string | Clos
$relationship->syncWithPivotValues($state, $pivotData, detaching: false);
});

$this->createOptionUsing(static function (Select $component, array $data, Schema $form) {
$this->createOptionUsing(static function (Select $component, array $data, Schema $schema) {
$record = $component->getRelationship()->getRelated();
$record->fill($data);
$record->save();

$form->model($record)->saveRelationships();
$schema->model($record)->saveRelationships();

return $record->getKey();
});
Expand All @@ -1075,8 +1075,8 @@ public function relationship(string | Closure | null $name = null, string | Clos
return $component->getSelectedRecord()?->attributesToArray();
});

$this->updateOptionUsing(static function (array $data, Schema $form): void {
$form->getRecord()?->update($data);
$this->updateOptionUsing(static function (array $data, Schema $schema): void {
$schema->getRecord()?->update($data);
});

$this->dehydrated(fn (Select $component): bool => ! $component->isMultiple());
Expand Down
6 changes: 3 additions & 3 deletions packages/forms/src/Concerns/InteractsWithForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function cacheForms(): array
return [$form => $this->{$form}($this->makeSchema())];
})
->forget('')
->map(fn (Schema $form, string $formName) => $form->key($formName))
->map(fn (Schema $schema, string $formName) => $schema->key($formName))
->all(),
];

Expand Down Expand Up @@ -140,9 +140,9 @@ protected function getForms(): array
];
}

public function form(Schema $form): Schema
public function form(Schema $schema): Schema
{
return $form
return $schema
->schema($this->getFormSchema())
->model($this->getFormModel())
->statePath($this->getFormStatePath())
Expand Down
4 changes: 2 additions & 2 deletions packages/infolists/src/Concerns/InteractsWithInfolists.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public function getInfolist(string $name): ?Schema
/**
* @deprecated Use `cacheSchema()` instead.
*/
protected function cacheInfolist(string $name, Schema $infolist): ?Schema
protected function cacheInfolist(string $name, Schema $schema): ?Schema
{
return $this->cacheSchema($name, $infolist);
return $this->cacheSchema($name, $schema);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/panels/src/Auth/Pages/EditProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,9 @@ protected function getCurrentPasswordFormComponent(): Component
->dehydrated(false);
}

public function form(Schema $form): Schema
public function form(Schema $schema): Schema
{
return $form;
return $schema;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/panels/src/Auth/Pages/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ protected function throwFailureValidationException(): never
]);
}

public function form(Schema $form): Schema
public function form(Schema $schema): Schema
{
return $form;
return $schema;
}

public function multiFactorChallengeForm(Schema $form): Schema
public function multiFactorChallengeForm(Schema $schema): Schema
{
return $form;
return $schema;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ protected function getRateLimitedNotification(TooManyRequestsException $exceptio
->danger();
}

public function form(Schema $form): Schema
public function form(Schema $schema): Schema
{
return $form;
return $schema;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ protected function getRateLimitedNotification(TooManyRequestsException $exceptio
->danger();
}

public function form(Schema $form): Schema
public function form(Schema $schema): Schema
{
return $form
return $schema
->schema([
$this->getEmailFormComponent(),
$this->getPasswordFormComponent(),
Expand Down
4 changes: 2 additions & 2 deletions packages/panels/src/Auth/Pages/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ protected function sendEmailVerificationNotification(Model $user): void
$user->notify($notification);
}

public function form(Schema $form): Schema
public function form(Schema $schema): Schema
{
return $form;
return $schema;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ protected function getHasFiltersForms(): array
];
}

public function filtersForm(Schema $form): Schema
public function filtersForm(Schema $schema): Schema
{
return $form;
return $schema;
}

public function getFiltersForm(): Schema
Expand Down
4 changes: 2 additions & 2 deletions packages/panels/src/Pages/Tenancy/EditTenantProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ protected function getRedirectUrl(): ?string
return null;
}

public function form(Schema $form): Schema
public function form(Schema $schema): Schema
{
return $form;
return $schema;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/panels/src/Pages/Tenancy/RegisterTenant.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ protected function getRedirectUrl(): ?string
return Filament::getUrl($this->tenant);
}

public function form(Schema $form): Schema
public function form(Schema $schema): Schema
{
return $form;
return $schema;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,30 @@ public static function getRelationshipName(): string
return static::getRelatedResource()::getParentResourceRegistration()->getRelationshipName();
}

public function configureForm(Schema $form): Schema
public function configureForm(Schema $schema): Schema
{
$form->columns(2);
$schema->columns(2);

if (static::getRelatedResource()) {
static::getRelatedResource()::form($form);
static::getRelatedResource()::form($schema);
}

$this->form($form);
$this->form($schema);

return $form;
return $schema;
}

public function configureInfolist(Schema $infolist): Schema
public function configureInfolist(Schema $schema): Schema
{
$infolist->columns(2);
$schema->columns(2);

if (static::getRelatedResource()) {
static::getRelatedResource()::infolist($infolist);
static::getRelatedResource()::infolist($schema);
}

$this->infolist($infolist);
$this->infolist($schema);

return $infolist;
return $schema;
}

protected function makeTable(): Table
Expand Down
Loading

0 comments on commit c4b831b

Please sign in to comment.