From 3e5c21e7dd92bf32469702f71acd1bb3bf6da3e3 Mon Sep 17 00:00:00 2001 From: Amey Mudras Date: Tue, 28 Nov 2023 10:03:18 +0530 Subject: [PATCH 1/4] CIVIC-1449: Fixed automated list filter issue. --- .../civictheme/includes/automated_list.inc | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/web/themes/contrib/civictheme/includes/automated_list.inc b/web/themes/contrib/civictheme/includes/automated_list.inc index ad9a1f23a..e4f931715 100644 --- a/web/themes/contrib/civictheme/includes/automated_list.inc +++ b/web/themes/contrib/civictheme/includes/automated_list.inc @@ -193,9 +193,23 @@ function _civictheme_automated_list__update_view(ViewExecutable $view): void { $view->display_handler->setOption('row', $view_mode_options); } - // @todo Implement hiding of the filters that were not selected. - $show_filters = !empty(array_filter(explode(', ', $settings['filters_exp']))); - if (!$show_filters) { + // Exposed filters. + $exposed_filter = explode(', ', $settings['filters_exp']); + $show_filters = !empty(array_filter($exposed_filter)); + + if ($show_filters) { + // Disable filters based on the component settings. + $view_filters = $view->display_handler->getOption('filters'); + foreach ($view_filters as $key => $filter) { + if (isset($filter['exposed']) && + $filter['exposed'] && + !in_array($filter['expose']['identifier'], $exposed_filter)) { + unset($view_filters[$key]); + } + } + $view->display_handler->setOption('filters', $view_filters); + } + else { $view->display_handler->has_exposed = FALSE; } From 407cafc881f54facc3ac1dce8f437aa37d8cc3c4 Mon Sep 17 00:00:00 2001 From: Amey Mudras Date: Tue, 5 Dec 2023 16:01:27 +0530 Subject: [PATCH 2/4] CIVIC-1449: Fixed automated list filter issue. --- ...h.civictheme_automated_list.render.feature | 54 +++++++++++++++++++ .../civictheme/includes/automated_list.inc | 12 ++--- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/tests/behat/features/paragraph.civictheme_automated_list.render.feature b/tests/behat/features/paragraph.civictheme_automated_list.render.feature index cd863ee52..f23177da9 100644 --- a/tests/behat/features/paragraph.civictheme_automated_list.render.feature +++ b/tests/behat/features/paragraph.civictheme_automated_list.render.feature @@ -284,3 +284,57 @@ Feature: Automated list render And I see field "Title" And should see an "input[name='title']" element And should not see an "input[name='title'].required" element + + @api @testmode + Scenario: Automated list, All filters selected + Given "civictheme_page" content: + | title | created | status | + | [TEST] Page 18 | [relative:-5 days] | 1 | + | [TEST] Page 19 | [relative:-5 days] | 1 | + + And "field_c_n_components" in "civictheme_page" "node" with "title" of "Test page with Automated list content" has "civictheme_automated_list" paragraph: + | field_c_p_title | [TEST] Automated list title | + | field_c_p_list_limit_type | unlimited | + | field_c_p_list_filters_exp | title, topic, type | + + When I visit "civictheme_page" "Test page with Automated list content" + Then I should see an ".ct-list__filters" element + And I should see an ".ct-group-filter__filters .ct-form-element--topic" element + And I should see an ".ct-group-filter__filters .ct-form-element--type" element + And I should see an ".ct-group-filter__filters .ct-form-element--title" element + + @api @testmode + Scenario: Automated list, No filters selected + Given "civictheme_page" content: + | title | created | status | + | [TEST] Page 20 | [relative:-5 days] | 1 | + | [TEST] Page 21 | [relative:-5 days] | 1 | + + And "field_c_n_components" in "civictheme_page" "node" with "title" of "Test page with Automated list content" has "civictheme_automated_list" paragraph: + | field_c_p_title | [TEST] Automated list title | + | field_c_p_list_limit_type | unlimited | + | field_c_p_list_filters_exp | | + + When I visit "civictheme_page" "Test page with Automated list content" + Then I should not see an ".ct-list__filters" element + And I should not see an ".ct-group-filter__filters .ct-form-element--topic" element + And I should not see an ".ct-group-filter__filters .ct-form-element--type" element + And I should not see an ".ct-group-filter__filters .ct-form-element--title" element + + @api @testmode + Scenario: Automated list, Some filters selected + Given "civictheme_page" content: + | title | created | status | + | [TEST] Page 22 | [relative:-5 days] | 1 | + | [TEST] Page 23 | [relative:-5 days] | 1 | + + And "field_c_n_components" in "civictheme_page" "node" with "title" of "Test page with Automated list content" has "civictheme_automated_list" paragraph: + | field_c_p_title | [TEST] Automated list title | + | field_c_p_list_limit_type | unlimited | + | field_c_p_list_filters_exp | title, topic | + + When I visit "civictheme_page" "Test page with Automated list content" + Then I should see an ".ct-list__filters" element + And I should see an ".ct-group-filter__filters .ct-form-element--topic" element + And I should not see an ".ct-group-filter__filters .ct-form-element--type" element + And I should see an ".ct-group-filter__filters .ct-form-element--title" element diff --git a/web/themes/contrib/civictheme/includes/automated_list.inc b/web/themes/contrib/civictheme/includes/automated_list.inc index e4f931715..27395507c 100644 --- a/web/themes/contrib/civictheme/includes/automated_list.inc +++ b/web/themes/contrib/civictheme/includes/automated_list.inc @@ -194,17 +194,15 @@ function _civictheme_automated_list__update_view(ViewExecutable $view): void { } // Exposed filters. - $exposed_filter = explode(', ', $settings['filters_exp']); - $show_filters = !empty(array_filter($exposed_filter)); + $exposed_filters = explode(', ', $settings['filters_exp']); + $show_filters = count($exposed_filters) > 0; if ($show_filters) { // Disable filters based on the component settings. $view_filters = $view->display_handler->getOption('filters'); - foreach ($view_filters as $key => $filter) { - if (isset($filter['exposed']) && - $filter['exposed'] && - !in_array($filter['expose']['identifier'], $exposed_filter)) { - unset($view_filters[$key]); + foreach ($view_filters as $filter_identifier => $filter) { + if (!empty($filter['exposed']) && !in_array($filter['expose']['identifier'], $exposed_filters)) { + unset($view_filters[$filter_identifier]); } } $view->display_handler->setOption('filters', $view_filters); From a2a40b4303d6017929bb80de177518ed1fdec1c8 Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Thu, 7 Dec 2023 09:38:11 +1100 Subject: [PATCH 3/4] Resolved phpstan issues. --- .../contrib/civictheme/includes/automated_list.inc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/web/themes/contrib/civictheme/includes/automated_list.inc b/web/themes/contrib/civictheme/includes/automated_list.inc index 27395507c..2363e889b 100644 --- a/web/themes/contrib/civictheme/includes/automated_list.inc +++ b/web/themes/contrib/civictheme/includes/automated_list.inc @@ -194,15 +194,14 @@ function _civictheme_automated_list__update_view(ViewExecutable $view): void { } // Exposed filters. - $exposed_filters = explode(', ', $settings['filters_exp']); - $show_filters = count($exposed_filters) > 0; - + $exposed_filters = array_filter(explode(', ', $settings['filters_exp'] ?? '')); + $show_filters = !empty($exposed_filters); if ($show_filters) { // Disable filters based on the component settings. $view_filters = $view->display_handler->getOption('filters'); - foreach ($view_filters as $filter_identifier => $filter) { - if (!empty($filter['exposed']) && !in_array($filter['expose']['identifier'], $exposed_filters)) { - unset($view_filters[$filter_identifier]); + foreach ($view_filters as $view_filter_id => $view_filter) { + if (!empty($view_filter['exposed']) && !in_array($view_filter['expose']['identifier'], $exposed_filters)) { + unset($view_filters[$view_filter_id]); } } $view->display_handler->setOption('filters', $view_filters); From ea72ce48b9371779d20600564462e223b0e8b7b6 Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Thu, 7 Dec 2023 10:03:54 +1100 Subject: [PATCH 4/4] Updated tests. --- ...h.civictheme_automated_list.render.feature | 33 +++++-------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/tests/behat/features/paragraph.civictheme_automated_list.render.feature b/tests/behat/features/paragraph.civictheme_automated_list.render.feature index f23177da9..45fa78c1c 100644 --- a/tests/behat/features/paragraph.civictheme_automated_list.render.feature +++ b/tests/behat/features/paragraph.civictheme_automated_list.render.feature @@ -285,14 +285,9 @@ Feature: Automated list render And should see an "input[name='title']" element And should not see an "input[name='title'].required" element - @api @testmode - Scenario: Automated list, All filters selected - Given "civictheme_page" content: - | title | created | status | - | [TEST] Page 18 | [relative:-5 days] | 1 | - | [TEST] Page 19 | [relative:-5 days] | 1 | - - And "field_c_n_components" in "civictheme_page" "node" with "title" of "Test page with Automated list content" has "civictheme_automated_list" paragraph: + @api + Scenario: Automated list, all filters shown + Given "field_c_n_components" in "civictheme_page" "node" with "title" of "Test page with Automated list content" has "civictheme_automated_list" paragraph: | field_c_p_title | [TEST] Automated list title | | field_c_p_list_limit_type | unlimited | | field_c_p_list_filters_exp | title, topic, type | @@ -303,14 +298,9 @@ Feature: Automated list render And I should see an ".ct-group-filter__filters .ct-form-element--type" element And I should see an ".ct-group-filter__filters .ct-form-element--title" element - @api @testmode - Scenario: Automated list, No filters selected - Given "civictheme_page" content: - | title | created | status | - | [TEST] Page 20 | [relative:-5 days] | 1 | - | [TEST] Page 21 | [relative:-5 days] | 1 | - - And "field_c_n_components" in "civictheme_page" "node" with "title" of "Test page with Automated list content" has "civictheme_automated_list" paragraph: + @api + Scenario: Automated list, no filters shown + Given "field_c_n_components" in "civictheme_page" "node" with "title" of "Test page with Automated list content" has "civictheme_automated_list" paragraph: | field_c_p_title | [TEST] Automated list title | | field_c_p_list_limit_type | unlimited | | field_c_p_list_filters_exp | | @@ -321,14 +311,9 @@ Feature: Automated list render And I should not see an ".ct-group-filter__filters .ct-form-element--type" element And I should not see an ".ct-group-filter__filters .ct-form-element--title" element - @api @testmode - Scenario: Automated list, Some filters selected - Given "civictheme_page" content: - | title | created | status | - | [TEST] Page 22 | [relative:-5 days] | 1 | - | [TEST] Page 23 | [relative:-5 days] | 1 | - - And "field_c_n_components" in "civictheme_page" "node" with "title" of "Test page with Automated list content" has "civictheme_automated_list" paragraph: + @api + Scenario: Automated list, some filters shown + Given "field_c_n_components" in "civictheme_page" "node" with "title" of "Test page with Automated list content" has "civictheme_automated_list" paragraph: | field_c_p_title | [TEST] Automated list title | | field_c_p_list_limit_type | unlimited | | field_c_p_list_filters_exp | title, topic |