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

feat: filter pills #422

Merged
merged 12 commits into from
Mar 14, 2025
Merged

feat: filter pills #422

merged 12 commits into from
Mar 14, 2025

Conversation

marcellmueller
Copy link
Contributor

@marcellmueller marcellmueller commented Mar 4, 2025

#307

  • Add Filter Chips
  • Added Tanstack Store
  • Refactored some search page components to use the searchResultsStore

@marcellmueller marcellmueller force-pushed the feat/filter-pills branch 2 times, most recently from b6294a1 to fcdbe52 Compare March 6, 2025 19:38
@marcellmueller marcellmueller marked this pull request as ready for review March 6, 2025 19:42
@marcellmueller marcellmueller force-pushed the feat/filter-pills branch 2 times, most recently from b344858 to d5771ce Compare March 7, 2025 20:47
@marcellmueller marcellmueller changed the title feat/filter pills feat: filter pills Mar 7, 2025
@marcellmueller marcellmueller force-pushed the feat/filter-pills branch 4 times, most recently from a083fb8 to cda6aed Compare March 11, 2025 15:26
} else {
filterChipStore.setState((prevState) =>
prevState.filter((filter) => filter.id !== id),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

(nit): When adding a filter to filterChipStore, there's no check to prevent duplicates

if (!filterChipStore.state.some((filter) => filter.id === id)) {
  filterChipStore.setState((prevState) => [...prevState, { param, id, label }]);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch thanks!

[...searchParams].filter(([key]) => !['filter', 'page'].includes(key)),
);

if (Object.keys(filterParams).length === 0) return;
Copy link
Contributor

Choose a reason for hiding this comment

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

(nit): This is redundant because filters.forEach() will automatically skip iteration if filterParams is empty

Copy link
Contributor Author

@marcellmueller marcellmueller Mar 14, 2025

Choose a reason for hiding this comment

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

hmm I looked into this and definitely think it's intentional so we don't loop through the whole filter side menu list that comes from the search store. It is iterating through them so we can get filter data like the label and add it to the chip, since we don't have that just from the param on page load.

I tried removing this and my tests failed with this:

AssertionError: expected "spy" to not be called at all, but actually been called 1 times
...
expect(filterChipStore.setState).not.toHaveBeenCalled();

});
});

filterChipStore.setState(() => [...filterChipList]);
Copy link
Contributor

Choose a reason for hiding this comment

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

(nit): The function replaces the entire state instead of merging it with existing values - is that intentional? If we want to preserve the existing chips we should do something like this

filterChipStore.setState((prevState) => [...prevState, ...filterChipList]);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This hook is used when either reloading the page, or when visiting the url with filter params, so there's no current state.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah makes sense. Ignore the suggestion than :) Thank you!

<div className="filter-chips-container">
{filterChips.map((filterChip) => {
const { id, label, param } = filterChip;
return <FilterChip key={label} param={param} id={id} label={label} />;
Copy link
Contributor

Choose a reason for hiding this comment

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

(nit): The key for each FilterChip is set to label which might not be unique. can we please use id instead.

@marcellmueller marcellmueller merged commit 9552a4e into main Mar 14, 2025
32 checks passed
@marcellmueller marcellmueller deleted the feat/filter-pills branch March 14, 2025 18:31
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.

2 participants