diff --git a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx index fbd0c12d1..9ec1031c2 100644 --- a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/index.tsx @@ -22,12 +22,12 @@ import { import { classNames, removeCountFromString, - sensitiveSort, } from "../../../../utils/utils"; import DisclosureComponent from "../DisclosureComponent"; import ParentDisclosureComponent from "../ParentDisclosureComponent"; import SidebarDraggableComponent from "./sideBarDraggableComponent"; import { sortKeys } from "./utils"; +import sensitiveSort from "./utils/sensitive-sort"; export default function ExtraSidebar(): JSX.Element { const data = useTypesStore((state) => state.data); diff --git a/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/utils/sensitive-sort.tsx b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/utils/sensitive-sort.tsx new file mode 100644 index 000000000..c0e7bd265 --- /dev/null +++ b/src/frontend/src/pages/FlowPage/components/extraSidebarComponent/utils/sensitive-sort.tsx @@ -0,0 +1,25 @@ +export default function sensitiveSort(a: string, b: string): number { + // Extract the name and number from each string using regular expressions + const regex = /(.+) \((\w+)\)/; + const matchA = a.match(regex); + const matchB = b.match(regex); + + if (matchA && matchB) { + // Compare the names alphabetically + const nameA = matchA[1]; + const nameB = matchB[1]; + if (nameA !== nameB) { + return nameA.localeCompare(nameB); + } + + // If the names are the same, compare the numbers numerically + const numberA = parseInt(matchA[2]); + const numberB = parseInt(matchB[2]); + return numberA - numberB; + } else { + // Handle cases where one or both strings do not match the expected pattern + // Simple strings are treated as pure alphabetical comparisons + return a.localeCompare(b); + } +} + \ No newline at end of file