mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Use "state snapshot" for repeaters and builders
This commit is contained in:
@@ -1135,7 +1135,7 @@ class Builder extends Field implements CanConcealComponents, HasExtraItemActions
|
||||
*/
|
||||
public function getRawItemState(string $key): array
|
||||
{
|
||||
return $this->getChildSchema($key)->getRawState();
|
||||
return $this->getChildSchema($key)->getStateSnapshot();
|
||||
}
|
||||
|
||||
public function getHeadingsCount(): int
|
||||
|
||||
@@ -1163,7 +1163,7 @@ class Repeater extends Field implements CanConcealComponents, HasExtraItemAction
|
||||
'item' => $container,
|
||||
'key' => $key,
|
||||
'schema' => $container,
|
||||
'state' => $container->getRawState(),
|
||||
'state' => $container->getStateSnapshot(),
|
||||
'uuid' => $key,
|
||||
]);
|
||||
}
|
||||
@@ -1350,7 +1350,7 @@ class Repeater extends Field implements CanConcealComponents, HasExtraItemAction
|
||||
*/
|
||||
public function getRawItemState(string $key): array
|
||||
{
|
||||
return $this->getChildSchema($key)->getRawState();
|
||||
return $this->getChildSchema($key)->getStateSnapshot();
|
||||
}
|
||||
|
||||
public function getHeadingsCount(): int
|
||||
|
||||
@@ -448,6 +448,34 @@ trait HasState
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Do not use this method outside the internals of Filament. It is subject to breaking changes in minor and patch releases.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getStateSnapshot(): array
|
||||
{
|
||||
return Component::withVisibilityCache(function (): array {
|
||||
$statePath = $this->getStatePath();
|
||||
|
||||
if (filled($statePath)) {
|
||||
$state = [];
|
||||
data_set($state, $statePath, $this->getRawState());
|
||||
} else {
|
||||
$state = $this->getRawState();
|
||||
}
|
||||
|
||||
$this->dehydrateState($state);
|
||||
$this->mutateDehydratedState($state);
|
||||
|
||||
if ($statePath) {
|
||||
$state = data_get($state, $statePath) ?? [];
|
||||
}
|
||||
|
||||
return $state;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed> | Arrayable
|
||||
*/
|
||||
|
||||
@@ -90,7 +90,7 @@ class RuleBuilder extends Builder
|
||||
throw new LogicException('No block component found.');
|
||||
}
|
||||
|
||||
return $block->getLabel($schema->getRawState(), $blockUuid);
|
||||
return $block->getLabel($schema->getStateSnapshot(), $blockUuid);
|
||||
});
|
||||
|
||||
if ($blockLabels->isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user