Skip to content

Commit

Permalink
Merge pull request #266 from MetaCell/feature/AREG-148
Browse files Browse the repository at this point in the history
Feature/areg-148 - Filters should not be persisted between my submissions and all antibodies
  • Loading branch information
filippomc authored Sep 30, 2024
2 parents c211955 + 65c1b3f commit 7c7bc0b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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;
}

Expand All @@ -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)
Expand Down Expand Up @@ -709,6 +713,7 @@ const AntibodiesTable = (props) => {
pagination={true}
paginationMode="server"
sortingMode="server"
sortModel={sortModel}
onSortModelChange={(model) => addSortingColumn(model)}
checkboxSelection
disableRowSelectionOnClick
Expand All @@ -732,7 +737,7 @@ const AntibodiesTable = (props) => {
filterPanel: () => CustomFilterPanel({
columns,
filterModel,
applyFilters,
applyFilterAndSortModels,
setFilterModel,
}),
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const CustomFilterPanel = (
columns,
filterModel,
setFilterModel,
applyFilters,
applyFilterAndSortModels,
}) => {

const { activeSearch } = useContext(searchContext);
Expand Down Expand Up @@ -93,7 +93,7 @@ export const CustomFilterPanel = (
variant="outlined"
color="primary"
onClick={() => {
applyFilters(filterModel, activeSearch);
applyFilterAndSortModels(filterModel, activeSearch);
}}
sx={{ m: 1 }}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export default function Searchbar(props) {
loader,
activeSearch,
filterModel,
setFilterModel,
sortModel,
setSortModel,
setActiveSearch
} = useContext(SearchContext)

Expand All @@ -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) ?
Expand Down

0 comments on commit 7c7bc0b

Please sign in to comment.