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

Conversation

kevin-wu01
Copy link
Collaborator

@kevin-wu01 kevin-wu01 commented Sep 23, 2024

Description

This PR fixes the issue where clicking "clear all filters" in the filter modal has no effect in updating the filters. The changes are based on a previous PR #3218 with some additional edits. I explored an alternative solution in #3440 that clears the filters using a useEffect in every filter but I figured this method of handling the logic in one place would be better.

Jira link: LF-4226

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Tested changes on the following pages: crop catalogue, crop variety, documents, tasks

  • Passes test case
  • UI components visually reviewed on desktop view
  • UI components visually reviewed on mobile view
  • Other (please explain)

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • The precommit and linting ran successfully
  • I have added or updated language tags for text that's part of the UI
  • I have added "MISSING" for all new language tags to languages I don't speak
  • I have added the GNU General Public License to all new files

@@ -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

@@ -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.

@kevin-wu01 kevin-wu01 self-assigned this Sep 24, 2024
@kevin-wu01 kevin-wu01 marked this pull request as ready for review September 24, 2024 18:58
@kevin-wu01 kevin-wu01 requested review from a team as code owners September 24, 2024 18:58
@kevin-wu01 kevin-wu01 requested review from antsgar and kathyavini and removed request for a team September 24, 2024 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant