diff --git a/applications/portal/backend/api/repositories/filter_repository.py b/applications/portal/backend/api/repositories/filter_repository.py index d41047e3..4c395f0b 100644 --- a/applications/portal/backend/api/repositories/filter_repository.py +++ b/applications/portal/backend/api/repositories/filter_repository.py @@ -12,7 +12,7 @@ def plain_filter_antibodies(page: int = 1, size: int = 10, filters=None): antibodies_count = filtered_antibodies.count() if antibodies_count == 0: - return [] + return [], antibodies_count if antibodies_count < MAX_SORTED: filtered_antibodies = apply_plain_sorting( diff --git a/applications/portal/frontend/src/components/Home/AntibodiesTable.tsx b/applications/portal/frontend/src/components/Home/AntibodiesTable.tsx index cb6b2c9a..2cfea705 100644 --- a/applications/portal/frontend/src/components/Home/AntibodiesTable.tsx +++ b/applications/portal/frontend/src/components/Home/AntibodiesTable.tsx @@ -402,21 +402,24 @@ const AntibodiesTable = (props) => { getAntibodyList, filterModel, setFilterModel, + sortModel, setSortModel, } = useContext(SearchContext); - const applyFilters = (filtermodel, query) => { - // Also does the applyFilters from the CustomFilterPanel - when apply button is clicked + const applyFilterAndSortModels = (filtermodel, query, sortmodel = sortModel) => { + // Also does the applyFilterAndSortModels from the CustomFilterPanel - when apply button is clicked const searchmode = (props.activeTab === MYSUBMISSIONS) ? SEARCH_MODES.MY_FILTERED_AND_SEARCHED_ANTIBODIES : SEARCH_MODES.ALL_FILTERED_AND_SEARCHED_ANTIBODIES getAntibodyList( searchmode, query, 1, - filtermodel + filtermodel, + sortmodel ) filtermodel !== filterModel ? setFilterModel(filtermodel) : null; + sortmodel !== sortModel ? setSortModel(sortmodel) : null; } const addSortingColumn = (sortmodel) => { @@ -445,9 +448,9 @@ const AntibodiesTable = (props) => { useEffect(() => { const isSearchInMySubmission = (props.activeTab === MYSUBMISSIONS && activeSearch) - // NOTE: LOGIC below - if no filters exist or search query exists in my submission - don't proceed, + // NOTE: LOGIC below - if no filters/sortmodel exist or search query exists in my submission - don't proceed, // since this is handled in separate useEffect - if (filterModel.items.length > 0 || isSearchInMySubmission) { + if (filterModel.items.length > 0 || sortModel.length > 0 || isSearchInMySubmission) { return; } @@ -466,25 +469,26 @@ const AntibodiesTable = (props) => { // if filters exist in All Results - apply with search query if (activeSearch && filterModel.items.length > 0) { if (props.activeTab === MYSUBMISSIONS) { - applyFilters(filterModel, '') + applyFilterAndSortModels(filterModel, '') } else { - applyFilters(filterModel, searchQuery || activeSearch) + applyFilterAndSortModels(filterModel, searchQuery || activeSearch) } } }, [activeSearch]); useEffect(() => { // NOTE: LOGIC below - whenever tab is changed - // if filters exist in My Submission - apply with empty search - // if filters exist in All Results - apply with search query - // if no filters exist in My Submission - get My Submissions - // if no filters exist in All Results - this case is handled in the first useEffect - if (filterModel.items.length > 0) { + // if filters/sortmodel exist in My Submission - apply with empty search and empty filters/sortmodel + // if filters/sortmodel exist in All Results - apply with search query but empty filters/sortmodel + // if no filters/sortmodel exist in My Submission - get My Submissions + // if no filters/sortmodel exist in All Results - this case is handled in the first useEffect + if (filterModel.items.length > 0 || sortModel.length > 0) { if (props.activeTab === MYSUBMISSIONS) { - applyFilters(filterModel, '') + applyFilterAndSortModels({ items: [] }, '', []) } else { - applyFilters(filterModel, searchQuery || activeSearch) + applyFilterAndSortModels({ items: [] }, searchQuery || activeSearch, []) } + } else { if (props.activeTab === MYSUBMISSIONS) { getAntibodyList(SEARCH_MODES.MY_ANTIBODIES) @@ -709,6 +713,7 @@ const AntibodiesTable = (props) => { pagination={true} paginationMode="server" sortingMode="server" + sortModel={sortModel} onSortModelChange={(model) => addSortingColumn(model)} checkboxSelection disableRowSelectionOnClick @@ -732,7 +737,7 @@ const AntibodiesTable = (props) => { filterPanel: () => CustomFilterPanel({ columns, filterModel, - applyFilters, + applyFilterAndSortModels, setFilterModel, }), }} diff --git a/applications/portal/frontend/src/components/Home/CustomFilterPanel.tsx b/applications/portal/frontend/src/components/Home/CustomFilterPanel.tsx index 8d34b88c..b8e7f791 100644 --- a/applications/portal/frontend/src/components/Home/CustomFilterPanel.tsx +++ b/applications/portal/frontend/src/components/Home/CustomFilterPanel.tsx @@ -16,7 +16,7 @@ export const CustomFilterPanel = ( columns, filterModel, setFilterModel, - applyFilters, + applyFilterAndSortModels, }) => { const { activeSearch } = useContext(searchContext); @@ -93,7 +93,7 @@ export const CustomFilterPanel = ( variant="outlined" color="primary" onClick={() => { - applyFilters(filterModel, activeSearch); + applyFilterAndSortModels(filterModel, activeSearch); }} sx={{ m: 1 }} > diff --git a/applications/portal/frontend/src/components/NavBar/Searchbar.tsx b/applications/portal/frontend/src/components/NavBar/Searchbar.tsx index 41263e4f..230db5d2 100644 --- a/applications/portal/frontend/src/components/NavBar/Searchbar.tsx +++ b/applications/portal/frontend/src/components/NavBar/Searchbar.tsx @@ -48,7 +48,9 @@ export default function Searchbar(props) { loader, activeSearch, filterModel, + setFilterModel, sortModel, + setSortModel, setActiveSearch } = useContext(SearchContext) @@ -70,6 +72,8 @@ export default function Searchbar(props) { } else { if (props.activeTab === MYSUBMISSIONS) { setActiveSearch(e.target.value) + setFilterModel({ items: [] }) + setSortModel([]) history.push('') } else { isFilterAndSortModelEmpty(filterModel, sortModel) ?