Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion modules/dataquery/jsx/definefilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -73,6 +74,43 @@ function DefineFilters(props: {
const [modalQueryGroup, setModalGroup] = useState(props.query);
const [deleteItemIndex, setDeleteItemIndex] = useState<number|null>(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 = (
<ButtonElement
label={t('Remove all filters', {ns: 'dataquery'})}
columnSize="col-sm-12"
buttonClass='btn btn-danger btn-remove'
onUserInput={clearAllFilters}
/>
);

useEffect(() => {
setQueryMatches(null);
if (!props.fields || props.fields.length === 0) {
Expand Down Expand Up @@ -320,7 +358,11 @@ function DefineFilters(props: {
style={{cursor: 'pointer'}} />
</div>
</div>
<div>
<div style={{
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
}}>
<div style={bGroupStyle}>
<ButtonElement
label={t('Add "and" condition', {ns: 'dataquery'})}
Expand All @@ -339,6 +381,9 @@ function DefineFilters(props: {
props.query.operator = 'or';
}} />
</div>
<div style={{marginTop: '1ex'}}>
{removeFiltersButton}
</div>
</div>
{toggleAdvancedButton}
{advancedButtons}
Expand Down Expand Up @@ -369,6 +414,7 @@ function DefineFilters(props: {
newGroup={props.addNewQueryGroup}
fulldictionary={props.fulldictionary}
setDeleteItemIndex={setDeleteItemIndex}
extraButton={removeFiltersButton}
/>
</fieldset>
</form>
Expand Down
28 changes: 23 additions & 5 deletions modules/dataquery/jsx/querytree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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<number|null>(null);
const {t} = useTranslation('dataquery');
Expand Down Expand Up @@ -185,7 +187,7 @@ function QueryTree(props: {
switch (props.items.group.length) {
case 0:
warning = <div className="alert alert-warning"
style={{display: 'flex'}}>
style={{display: 'flex', marginBottom: 0}}>
<i className="fas fa-exclamation-triangle"
style={{
fontSize: '1.5em',
Expand All @@ -199,7 +201,7 @@ function QueryTree(props: {
break;
case 1:
warning = <div className="alert alert-warning"
style={{display: 'flex'}}>
style={{display: 'flex', marginBottom: 0}}>
<i className="fas fa-exclamation-triangle"
style={{
fontSize: '1.5em',
Expand Down Expand Up @@ -263,6 +265,14 @@ function QueryTree(props: {
margin: 0,
padding: 0,
};

const emptyGroupStyle: React.CSSProperties = {
display: 'flex',
justifyContent: 'center',
gap: '4px',
marginBottom: '20px',
};

return (
<div style={style}>
<ul style={marginStyle}>
Expand All @@ -288,9 +298,17 @@ function QueryTree(props: {
columnSize='col-sm-12'
/>
</div>
{warning}
{deleteGroupHTML}
</div></li>
<div style={emptyGroupStyle}>
{warning}
{deleteGroupHTML}
</div>
{props.extraButton ? (
<div style={{margin: '5px 0 0 auto'}}>
{props.extraButton}
</div>
) : null}
</div>
</li>
</ul>
</div>
);
Expand Down
6 changes: 6 additions & 0 deletions modules/dataquery/locale/dataquery.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""

Expand Down
6 changes: 6 additions & 0 deletions modules/dataquery/locale/fr/LC_MESSAGES/dataquery.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 6 additions & 0 deletions modules/dataquery/locale/hi/LC_MESSAGES/dataquery.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 "आइटम हटाएँ"

Expand Down
6 changes: 6 additions & 0 deletions modules/dataquery/locale/ja/LC_MESSAGES/dataquery.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 "アイテムを削除"

Expand Down
6 changes: 6 additions & 0 deletions modules/dataquery/locale/zh/LC_MESSAGES/dataquery.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 "删除项目"

Expand Down
Loading