From 21784affc6d0afe13d6c28b534834ed6965d64a9 Mon Sep 17 00:00:00 2001 From: Iosif Chatzimichail Date: Thu, 25 Jan 2024 00:33:31 +0200 Subject: [PATCH] Fixes #8 --- src/Http/Livewire/Traits/IsLivewireFilter.php | 4 ++++ tests/Feature/LfCheckboxFilterTest.php | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/Http/Livewire/Traits/IsLivewireFilter.php b/src/Http/Livewire/Traits/IsLivewireFilter.php index c28c92e..f4d54e7 100644 --- a/src/Http/Livewire/Traits/IsLivewireFilter.php +++ b/src/Http/Livewire/Traits/IsLivewireFilter.php @@ -74,6 +74,10 @@ protected function getParamKey() return 'taxonomy:'.$this->field.':'.$this->modifier; } + if ($this->condition === 'query_scope') { + return $this->modifier.':'.$this->field; + } + return $this->field.':'.$this->condition; } } diff --git a/tests/Feature/LfCheckboxFilterTest.php b/tests/Feature/LfCheckboxFilterTest.php index 7c5f717..3ac8eaa 100644 --- a/tests/Feature/LfCheckboxFilterTest.php +++ b/tests/Feature/LfCheckboxFilterTest.php @@ -191,6 +191,15 @@ public function it_loads_a_param_that_is_preset() ->assertSet('selected', ['option1']); } + /** @test */ + public function it_loads_a_param_that_is_preset_for_a_query_scope() + { + Livewire::test(LfCheckboxFilter::class, ['field' => 'item_options', 'collection' => 'pages', 'blueprint' => 'pages.pages', 'condition' => 'query_scope', 'modifier' => 'multiselect']) + ->assertSet('selected', []) + ->dispatch('preset-params', ['multiselect:item_options' => 'option1', 'query_scope' => 'multiselect']) + ->assertSet('selected', ['option1']); + } + protected function makeEntry($collection, $slug) { return EntryFactory::id($slug)->collection($collection)->slug($slug)->make();