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: wire up search and filter on Team page #4265

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Changes from all 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
19 changes: 16 additions & 3 deletions editor.planx.uk/src/pages/Team.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@ const Team: React.FC = () => {
const [filteredFlows, setFilteredFlows] = useState<FlowSummary[] | null>(
null,
);
const [searchedFlows, setSearchedFlows] = useState<FlowSummary[] | null>(
null,
);
const [matchingFlows, setMatchingflows] = useState<FlowSummary[] | null>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Going through a few iterations, this seemed the easiest to read, while functionally working as expected.

null,
);

useEffect(() => {
const diffFlows =
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an intersection we're checking for, not a difference.

An intersection is an item which is in both lists, a difference would be items in one list but not the other.

searchedFlows?.filter((flow) => filteredFlows?.includes(flow)) || null;
setMatchingflows(diffFlows);
}, [searchedFlows, filteredFlows]);

const sortOptions: SortableFields<FlowSummary>[] = [
{
Expand Down Expand Up @@ -223,6 +235,7 @@ const Team: React.FC = () => {
);
setFlows(sortedFlows);
setFilteredFlows(sortedFlows);
setSearchedFlows(sortedFlows);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't need to setMatchedFlows since this will happen when these two state variables are set

});
}, [teamId, setFlows, getFlows]);

Expand Down Expand Up @@ -262,7 +275,7 @@ const Team: React.FC = () => {
{hasFeatureFlag("SORT_FLOWS") && flows && (
<SearchBox<FlowSummary>
records={flows}
setRecords={setFilteredFlows}
setRecords={setSearchedFlows}
searchKey={["name", "slug"]}
/>
)}
Expand Down Expand Up @@ -294,9 +307,9 @@ const Team: React.FC = () => {
/>
)}
</Box>
{filteredFlows && flows && (
{matchingFlows && flows && (
<DashboardList>
{filteredFlows.map((flow) => (
{matchingFlows.map((flow) => (
<FlowCard
flow={flow}
flows={flows}
Expand Down