From d9e2bcfcf9b46074ebeeceaef47e376a49a7b90f Mon Sep 17 00:00:00 2001 From: Sky Rubenstein Date: Thu, 14 Nov 2024 10:57:57 -0500 Subject: [PATCH] Clear selected filters code --- .../data_search/DatasetFilterList.jsx | 15 +++++--- .../data_search/DatasetSearchTable.jsx | 35 +++++++++++-------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/components/data_search/DatasetFilterList.jsx b/src/components/data_search/DatasetFilterList.jsx index 530776bb6..66a7ae5a4 100644 --- a/src/components/data_search/DatasetFilterList.jsx +++ b/src/components/data_search/DatasetFilterList.jsx @@ -6,7 +6,7 @@ import ListItemButton from '@mui/material/ListItemButton'; import ListItemIcon from '@mui/material/ListItemIcon'; import ListItemText from '@mui/material/ListItemText'; import Divider from '@mui/material/Divider'; -import { Typography } from '@mui/material'; +import { Button, Typography } from '@mui/material' import { Checkbox } from '@mui/material'; import { flatten, uniq, compact, capitalize, orderBy } from 'lodash'; @@ -43,7 +43,7 @@ export const FilterItemList = (props) => { }; export const DatasetFilterList = (props) => { - const { datasets, filters, filterHandler, isFiltered } = props; + const { datasets, filters, filterHandler, isFiltered, onClear } = props; const accessManagementFilters = uniq(compact(datasets.map((dataset) => dataset.accessManagement))); const dataUseFilters = uniq(compact(flatten(datasets.map((dataset) => dataset.dataUse?.primary))).map((dataUse) => dataUse.code)); @@ -51,9 +51,14 @@ export const DatasetFilterList = (props) => { return ( - - Filters - + + + Filters + + + { const { datasets, history, icon, title } = props; const [exportableDatasets, setExportableDatasets] = useState({}); - const [filters, setFilters] = useState(defaultFilters); + const [filters, setFilters] = useState(_.clone(defaultFilters)); const [filtered, setFiltered] = useState([]); const [selected, setSelected] = useState([]); const [selectedTable, setSelectedTable] = useState(datasetSearchTableTabs.study); @@ -167,8 +167,20 @@ export const DatasetSearchTable = (props) => { }; }; + const search = (searchFilters) => { + const fullQuery = assembleFullQuery(searchFilters); + try { + DataSet.searchDatasetIndex(fullQuery).then((filteredDatasets) => { + var newFiltered = datasets.filter(value => filteredDatasets.some(item => _.isEqual(item, value))); + setFiltered(newFiltered); + }); + } catch (error) { + Notifications.showError({ text: 'Failed to load Elasticsearch index' }); + } + } + const filterHandler = (event, data, category, filter) => { - var newFilters = defaultFilters; + var newFilters = _.clone(filters); if (category === 'search') { newFilters[category] = []; setSearchTerm(filter); @@ -180,18 +192,7 @@ export const DatasetSearchTable = (props) => { } setFilters(newFilters); - const fullQuery = assembleFullQuery(newFilters); - const doSearch = async () => { - try { - await DataSet.searchDatasetIndex(fullQuery).then((filteredDatasets) => { - var newFiltered = datasets.filter(value => filteredDatasets.some(item => _.isEqual(item, value))); - setFiltered(newFiltered); - }); - } catch (error) { - Notifications.showError({ text: 'Failed to load Elasticsearch index' }); - } - }; - doSearch(); + search(newFilters); }; const applyForAccess = async () => { try { @@ -270,7 +271,11 @@ export const DatasetSearchTable = (props) => { - + { + const newFilters = { ...defaultFilters, search: filters.search } + setFilters(newFilters) + search(newFilters); + }}/> {(() => {