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

Filter bookmark #1010

Draft
wants to merge 33 commits into
base: master
Choose a base branch
from

Conversation

SuspenseFallback
Copy link
Contributor

@SuspenseFallback SuspenseFallback commented Jan 23, 2023

Description

Introduces filter persistence and linkability for the following tools:

  • Verify
  • Captures
  • Growers

When a user applies a filter in one of these tools, the URL search parameters are updated with the filter values and pagination parameters. This provides several benefits:

  • Filters and pagination persist on page refresh
  • A common filter can be bookmarked in the browser
  • Tools can easily link to each other with filtered views, e.g., unverified captures for a specific grower can be linked directly from the Grower card or Grower Detail drawer. No more copying and pasting IDs 😃
  • Changes in filter and pagination are added to the history, so the user can return to a previous filter configuration by going back in the browser

Issue(s) addressed

Note that filters for Capture Matching, Earnings, Payments and Stakeholders are not yet supported.
These can be addressed under separate issues using the same pattern and utility functions.

What kind of change(s) does this PR introduce?

  • Enhancement

Please check if the PR fulfils these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Issue

What is the current behavior?

Filters do not persist.

What is the new behavior?

Filters stay in the URL.

Breaking change

Does this PR introduce a breaking change?

No.

Other useful information

Screenshot 2023-02-26 at 22 14 29

Screenshot 2023-02-26 at 22 17 38

Screenshot 2023-02-26 at 22 18 05

@nmcharlton nmcharlton marked this pull request as ready for review February 26, 2023 22:19
@nmcharlton nmcharlton requested a review from a team as a code owner February 26, 2023 22:19
@nmcharlton nmcharlton requested a review from gwynndp February 26, 2023 22:19
@nmcharlton
Copy link
Collaborator

Still to do before merging:

  • Add some tests

);

useEffect(() => {
handleQuerySearchParams({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this need to be inside a conditional like in the Verify and Grower contexts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's the others that are incorrect.
I suspect the if (searchParams) check is an artefact of a previous way of doing this.
We probably shouldn't check it as we're not using it within this useEffect. I'll do some more testing.

gwynndp
gwynndp previously approved these changes Feb 27, 2023
Copy link
Collaborator

@gwynndp gwynndp left a comment

Choose a reason for hiding this comment

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

Nice solution!

@gwynndp gwynndp dismissed their stale review February 27, 2023 21:26

Found a bug

@gwynndp
Copy link
Collaborator

gwynndp commented Feb 27, 2023

When testing out the back button with the Capture Filter the filter fields aren't being updated to match the url filters

Test filter data:

startDate: 2023-02-17
endDate: 2023-02-18
device_identifier: something
wallet: gwynn
organization: test1
organization_id: ["8b2628b3-733b-4962-943d-95ebea918c9d"]
grower_account_id: 93a026d2-a511-404f-958c-a0a36892af0f
tag: Any
whereNotNulls: ["tag_id"]
captureUUID: f41f8c5a-c6ad-4c76-a747-46b710e94838
captureRefId: 999939

Before back button:
https://monosnap.com/file/Jl3tF7djMaCiCz9uLFdCpc4NzrIz83

After back button (the capture reference id and capture uuid fields should be filled):
https://monosnap.com/file/YuLh586z47GWshCQj4BhY37fA3UdAJ

URL filter string:
http://localhost:3001/captures ?uuid=f41f8c5a-c6ad-4c76-a747-46b710e94838 &captureId=999939 &startDate=2023-02-17 &endDate=2023-02-18 &grower_account_id=93a026d2-a511-404f-958c-a0a36892af0f &device_identifier=something &wallet=gweeple%40yahoo.com &species_id=ALL_SPECIES &organization_id=8b2628b3-733b-4962-943d-95ebea918c9d &tokenId=All

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants