From 0d02281eb109dc4ffafa48d9b1b866ce05251583 Mon Sep 17 00:00:00 2001 From: Mario Martins Date: Wed, 29 Jul 2026 13:59:02 +0000 Subject: [PATCH] add remove all filters buttons to dataquery module at the filtering step --- modules/dataquery/jsx/definefilters.tsx | 48 ++++++++++++++++++- modules/dataquery/jsx/querytree.tsx | 28 +++++++++-- modules/dataquery/locale/dataquery.pot | 6 +++ .../locale/fr/LC_MESSAGES/dataquery.po | 6 +++ .../locale/hi/LC_MESSAGES/dataquery.po | 6 +++ .../locale/ja/LC_MESSAGES/dataquery.po | 6 +++ .../locale/zh/LC_MESSAGES/dataquery.po | 6 +++ 7 files changed, 100 insertions(+), 6 deletions(-) diff --git a/modules/dataquery/jsx/definefilters.tsx b/modules/dataquery/jsx/definefilters.tsx index 8e3a566ccd..f46d33caf0 100644 --- a/modules/dataquery/jsx/definefilters.tsx +++ b/modules/dataquery/jsx/definefilters.tsx @@ -12,6 +12,7 @@ import {calcPayload} from './calcpayload'; import {CategoriesAPIReturn} from './hooks/usedatadictionary'; import React from 'react'; import {Trans, useTranslation} from 'react-i18next'; +import swal from 'sweetalert2'; /** * The define filters tab of the DQT @@ -73,6 +74,43 @@ function DefineFilters(props: { const [modalQueryGroup, setModalGroup] = useState(props.query); const [deleteItemIndex, setDeleteItemIndex] = useState(null); const [queryMatches, setQueryMatches] = useState(null); + + /** + * Clear all the filters currently added + * + * @param e - React Mouse Event + */ + const clearAllFilters = (e: React.MouseEvent) => { + e.preventDefault(); + swal.fire({ + title: t('Are you sure?', {ns: 'loris'}), + text: t( + 'This will remove all currently selected filters', + {ns: 'dataquery'}, + ), + type: 'warning', + focusCancel: true, + showCancelButton: true, + confirmButtonText: t('Yes', {ns: 'loris'}), + cancelButtonText: t('Cancel', {ns: 'loris'}), + }).then((result) => { + if (result.value) { + const emptyQuery = new QueryGroup('and'); + props.setQuery(emptyQuery); + setModalGroup(emptyQuery); + } + }); + }; + + const removeFiltersButton = ( + + ); + useEffect(() => { setQueryMatches(null); if (!props.fields || props.fields.length === 0) { @@ -320,7 +358,11 @@ function DefineFilters(props: { style={{cursor: 'pointer'}} /> -
+
+
+ {removeFiltersButton} +
{toggleAdvancedButton} {advancedButtons} @@ -369,6 +414,7 @@ function DefineFilters(props: { newGroup={props.addNewQueryGroup} fulldictionary={props.fulldictionary} setDeleteItemIndex={setDeleteItemIndex} + extraButton={removeFiltersButton} /> diff --git a/modules/dataquery/jsx/querytree.tsx b/modules/dataquery/jsx/querytree.tsx index f77142f323..25ef9aaeb4 100644 --- a/modules/dataquery/jsx/querytree.tsx +++ b/modules/dataquery/jsx/querytree.tsx @@ -41,6 +41,7 @@ function alternateColour(c: string): string { * @param {object} props.mapCategoryName - Function to map the backend category name to a user friendly name * @param {object} props.fulldictionary - The dictionary of all modules that have been loaded * @param {function} props.setDeleteItemIndex - Callback to set or clear the index of the item marked for deletion + * @param {React.ReactElement} props.extraButton - Adds a button the far right on the row as the other two buttons * @returns {React.ReactElement} - the react element */ function QueryTree(props: { @@ -61,6 +62,7 @@ function QueryTree(props: { fulldictionary: FullDictionary, mapModuleName: (module: string) => string, mapCategoryName: (module: string, category: string) => string, + extraButton?: React.ReactNode, }) { const [deleteItemIndex, setDeleteItemIndex] = useState(null); const {t} = useTranslation('dataquery'); @@ -185,7 +187,7 @@ function QueryTree(props: { switch (props.items.group.length) { case 0: warning =
+ style={{display: 'flex', marginBottom: 0}}> + style={{display: 'flex', marginBottom: 0}}>
    @@ -288,9 +298,17 @@ function QueryTree(props: { columnSize='col-sm-12' />
- {warning} - {deleteGroupHTML} -
+
+ {warning} + {deleteGroupHTML} +
+ {props.extraButton ? ( +
+ {props.extraButton} +
+ ) : null} + + ); diff --git a/modules/dataquery/locale/dataquery.pot b/modules/dataquery/locale/dataquery.pot index 46f10901b9..17f4888e78 100644 --- a/modules/dataquery/locale/dataquery.pot +++ b/modules/dataquery/locale/dataquery.pot @@ -190,6 +190,12 @@ msgstr "" msgid "Add \"or\" condition" msgstr "" +msgid "This will remove all currently selected filters" +msgstr "" + +msgid "Remove all filters" +msgstr "" + msgid "Delete Item" msgstr "" diff --git a/modules/dataquery/locale/fr/LC_MESSAGES/dataquery.po b/modules/dataquery/locale/fr/LC_MESSAGES/dataquery.po index 46c60addf0..555c0dbf14 100644 --- a/modules/dataquery/locale/fr/LC_MESSAGES/dataquery.po +++ b/modules/dataquery/locale/fr/LC_MESSAGES/dataquery.po @@ -277,6 +277,12 @@ msgstr "Ajouter la condition « et »" msgid "Add \"or\" condition" msgstr "Ajouter la condition « ou »" +msgid "This will remove all currently selected filters" +msgstr "Ceci supprimera tous les filtres actuellement sélectionnés." + +msgid "Remove all filters" +msgstr "Supprimer tous les filtres" + msgid "Delete Item" msgstr "Supprimer l'élément" diff --git a/modules/dataquery/locale/hi/LC_MESSAGES/dataquery.po b/modules/dataquery/locale/hi/LC_MESSAGES/dataquery.po index b0a9f46d8e..b58a4f0b50 100644 --- a/modules/dataquery/locale/hi/LC_MESSAGES/dataquery.po +++ b/modules/dataquery/locale/hi/LC_MESSAGES/dataquery.po @@ -190,6 +190,12 @@ msgstr "\"and\" शर्त जोड़ें" msgid "Add \"or\" condition" msgstr "\"or\" शर्त जोड़ें" +msgid "This will remove all currently selected filters" +msgstr "यह वर्तमान में चयनित सभी फ़िल्टर हटा देगा।" + +msgid "Remove all filters" +msgstr "सभी फ़िल्टर हटाएँ" + msgid "Delete Item" msgstr "आइटम हटाएँ" diff --git a/modules/dataquery/locale/ja/LC_MESSAGES/dataquery.po b/modules/dataquery/locale/ja/LC_MESSAGES/dataquery.po index 50b511ce9d..b77ec7b2aa 100644 --- a/modules/dataquery/locale/ja/LC_MESSAGES/dataquery.po +++ b/modules/dataquery/locale/ja/LC_MESSAGES/dataquery.po @@ -199,6 +199,12 @@ msgstr "「and」条件を追加する" msgid "Add \"or\" condition" msgstr "「または」条件を追加する" +msgid "This will remove all currently selected filters" +msgstr "これにより、現在選択されているすべてのフィルターが削除されます。" + +msgid "Remove all filters" +msgstr "すべてのフィルターを削除" + msgid "Delete Item" msgstr "アイテムを削除" diff --git a/modules/dataquery/locale/zh/LC_MESSAGES/dataquery.po b/modules/dataquery/locale/zh/LC_MESSAGES/dataquery.po index d7ff1352d5..990dc64638 100644 --- a/modules/dataquery/locale/zh/LC_MESSAGES/dataquery.po +++ b/modules/dataquery/locale/zh/LC_MESSAGES/dataquery.po @@ -199,6 +199,12 @@ msgstr "添加“与”条件" msgid "Add \"or\" condition" msgstr "添加“或”条件" +msgid "This will remove all currently selected filters" +msgstr "这将删除当前选中的所有筛选条件。" + +msgid "Remove all filters" +msgstr "删除所有筛选条件" + msgid "Delete Item" msgstr "删除项目"