From fd2266fb4cba699a7dd0a56648f26bbd9d379395 Mon Sep 17 00:00:00 2001 From: Michael Kimsal Date: Sun, 6 Apr 2025 16:43:44 -0400 Subject: [PATCH 1/3] fix: Add support for customizable tree key in SelectTree Introduce a `treeKey` property and associated methods to allow customization of the tree identifier. Updated Blade template to use the specified tree key for the `wire:key` attribute to ensure predictable component rendering. This is to address issue #141. --- resources/views/select-tree.blade.php | 2 +- src/SelectTree.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/resources/views/select-tree.blade.php b/resources/views/select-tree.blade.php index f963279..3a07576 100644 --- a/resources/views/select-tree.blade.php +++ b/resources/views/select-tree.blade.php @@ -12,7 +12,7 @@
treeKey = $treeKey; + + return $this; + } + + public function getTreeKey(): string + { + return $this->evaluate($this->treeKey); + } } From 8ccde12714089bad8d6bcc27e59734f661b6dba7 Mon Sep 17 00:00:00 2001 From: Michael Kimsal Date: Sun, 6 Apr 2025 17:41:45 -0400 Subject: [PATCH 2/3] Refine SPA mode check in select-tree view. Updated the `FilamentView::hasSpaMode` method to include the current URL as a parameter. This ensures the SPA mode condition is evaluated more precisely based on the current context. --- resources/views/select-tree.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/select-tree.blade.php b/resources/views/select-tree.blade.php index 3a07576..4fb9414 100644 --- a/resources/views/select-tree.blade.php +++ b/resources/views/select-tree.blade.php @@ -15,7 +15,7 @@ wire:key="{{ $getTreeKey() }}" wire:ignore x-ignore - @if (FilamentView::hasSpaMode()) + @if (FilamentView::hasSpaMode(url()->current())) ax-load="visible" @else ax-load From d7d388ebfd02c1494b5e6b53876afef079068d7e Mon Sep 17 00:00:00 2001 From: Michael Kimsal Date: Tue, 8 Apr 2025 21:55:39 -0400 Subject: [PATCH 3/3] Set dynamic default for treeKey property Updated the treeKey property to use a dynamic default value, ensuring more flexibility. Also adjusted the setUp method to initialize treeKey with a randomized suffix for uniqueness. --- src/SelectTree.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/SelectTree.php b/src/SelectTree.php index 1eefdd4..aeb1aa0 100644 --- a/src/SelectTree.php +++ b/src/SelectTree.php @@ -88,7 +88,7 @@ class SelectTree extends Field implements HasAffixActions protected Closure|array|null $prepend = null; - protected Closure|string|null $treeKey = 'defaultTreeKey'; + protected Closure|string|null $treeKey = 'treeKey'; protected function setUp(): void { @@ -147,6 +147,8 @@ protected function setUp(): void $this->suffixActions([ static fn (SelectTree $component): ?Action => $component->getCreateOptionAction(), ]); + + $this->treeKey('treeKey-'.rand()); } protected function buildTree(): Collection