Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LF-4226 fix clear filters button does not clear filters #3474

Open
wants to merge 7 commits into
base: integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export function FilterDate({ defaultValue, onChange, subject, shouldReset, props
useEffect(() => {
if (shouldReset) {
setDate('');
onChange('');
}
}, [shouldReset]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const FilterMultiSelectV2 = ({

useEffect(() => {
if (shouldReset) {
setValue(options.filter((option) => option.default));
setValue([]);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default filters in options are the filters that were initially active when the filter modal is opened, empty array removes all selected options

}
}, [shouldReset]);

Expand Down
39 changes: 34 additions & 5 deletions packages/webapp/src/components/FilterPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,33 @@ const PureFilterPage = ({
const resetFilter = () => {
triggerReset();
setIsDirty(true);
setTempFilter(
(() => {
const newTempFilter: ReduxFilterEntity = {};

filters.forEach((item) => {
if (item.filterKey === 'DATE_RANGE') {
newTempFilter['FROM_DATE'] = undefined;
newTempFilter['TO_DATE'] = undefined;
} else if (item.filterKey === 'VALID_ON') {
newTempFilter['VALID_ON'] = undefined;
} else {
newTempFilter[item.filterKey] = {};

if (item.options && item.options.length > 0) {
item.options.forEach((option) => {
newTempFilter[item.filterKey][option.value] = {
active: false,
label: option.label,
};
});
}
}
});

return newTempFilter;
})(),
);
};

const [isDirty, setIsDirty] = useState(false);
Expand All @@ -75,11 +102,13 @@ const PureFilterPage = ({
filters={filters}
onChange={(filterKey, filterState) => {
if (filterKey === 'DATE_RANGE') {
setTempFilter({
...tempFilter,
...(filterState.fromDate && { FROM_DATE: filterState.fromDate }),
...(filterState.toDate && { TO_DATE: filterState.toDate }),
});
setTempFilter(
Object.assign(
{ ...tempFilter },
filterState.fromDate ? { FROM_DATE: filterState.fromDate } : {},
filterState.toDate ? { TO_DATE: filterState.toDate } : {},
),
);
} else {
setTempFilter({
...tempFilter,
Expand Down
9 changes: 8 additions & 1 deletion packages/webapp/src/containers/Filter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@
*/

// In tempStateReducer > filterReducer
export type ReduxFilterEntity<FilterKey extends string = string> = Record<FilterKey, FilterState>;
export type ReduxFilterEntity<FilterKey extends string = string> = Record<FilterKey, FilterState> &
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike the other filters, the date filters have a string type. In order to set the filter inactive the filter value needs to be set to undefined rather than using an active flag. I need to explicitly specify this type here in order to reset to undefined in FilterPage/index.tsx.

DateFilterState;

interface DateFilterState {
FROM_DATE?: string;
TO_DATE?: string;
VALID_ON?: string;
}

export interface FilterState {
[filterOptionId: string]: /* e.g. ABANDONED, COMPLETED */ {
Expand Down
Loading