Skip to content

Commit

Permalink
fix: sort group by for catalog alphabetically
Browse files Browse the repository at this point in the history
Closes #1384
  • Loading branch information
mainawycliffe committed Oct 18, 2023
1 parent d47b62f commit 2acbbbc
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/components/GroupByDropdown/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect } from "react";
import { useMemo } from "react";
import { BiLabel } from "react-icons/bi";
import { useSearchParams } from "react-router-dom";
import { useAllConfigsQuery } from "../../api/query-hooks";
Expand Down Expand Up @@ -66,12 +66,13 @@ export default function GroupByDropdown({
params.get("groupByProp") || params.get("groupBy") || "type"
);

const [groupByOptions, setGroupByOptions] = useState<GroupOptionsType>();
const { data: allConfigs, isLoading } = useAllConfigsQuery({}, {});

useEffect(() => {
const groupByOptions = useMemo(() => {
if (!allConfigs?.data) {
setGroupByOptions(items);
return Object.values(items).sort((a, b) => {
return a.name.localeCompare(b.name);
});
}
const newItems = items;
allConfigs?.data?.forEach((d) => {
Expand All @@ -90,8 +91,10 @@ export default function GroupByDropdown({
};
});
});
setGroupByOptions({ ...newItems });
}, [allConfigs?.data, isLoading]);
return Object.values({ ...newItems }).sort((a, b) => {
return a.name.localeCompare(b.name);
});
}, [allConfigs?.data]);

const groupByChange = (value: string | undefined) => {
const options = groupByOptions as any;
Expand All @@ -117,6 +120,7 @@ export default function GroupByDropdown({
return (
<ReactSelectDropdown
name="group"
isLoading={isLoading}
items={groupByOptions}
onChange={groupByChange}
value={groupType}
Expand Down

0 comments on commit 2acbbbc

Please sign in to comment.