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

[DISP-72] Fix sorting in Ideas Map #1766

Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## Next release

/
### Fixed

- Fixed bug in Ideas Map view that caused an infinite loop of requests when Idea sort order was changed

## 2022-03-29

Expand Down
10 changes: 7 additions & 3 deletions front/app/hooks/useIdeaMarkers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,29 @@ export default function useIdeaMarkers({
IIdeaMarkerData[] | undefined | null
>(undefined);

// Stringifying the project IDs and topics to make useEffect dependency array happy
const stringifiedProjectIds = JSON.stringify(projectIds);
const stringifiedTopics = JSON.stringify(topics);

useEffect(() => {
setIdeaMarkers(undefined);

const subscription = ideasMarkersStream({
queryParameters: {
'page[size]': 2000,
location_required: true,
projects: projectIds,
projects: JSON.parse(stringifiedProjectIds),
phase: phaseId,
sort: sort || ideaDefaultSortMethodFallback,
search: search || undefined,
topics: topics || undefined,
topics: JSON.parse(stringifiedTopics) || undefined,
},
}).observable.subscribe((response) => {
setIdeaMarkers(!isNilOrError(response) ? response.data : null);
});

return () => subscription.unsubscribe();
}, [phaseId, projectIds, sort, search, topics]);
}, [phaseId, stringifiedProjectIds, sort, search, stringifiedTopics]);

return ideaMarkers;
}