Skip to content

Commit 2d91437

Browse files
committed
feat(tags): add alphabetical sort button to TagsPanel
- Introduce the handleSortAlphabetically action in TagsTree to recursively sort tags by name. - Add a new ToolbarButton to trigger the sort functionality in the panel header.
1 parent 14c2d6f commit 2d91437

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/frontend/containers/Outliner/TagsPanel/TagsTree.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,22 @@ const TagsTree = observer((props: Partial<MultiSplitPaneProps>) => {
535535
}
536536
});
537537

538+
// NEW: Action to sort the tags alphabetically (recursively)
539+
const handleSortAlphabetically = useAction(() => {
540+
// Recursive sorting function
541+
const sortTags = (tags: ClientTag[]) => {
542+
// First, sort children of each tag
543+
tags.forEach(tag => {
544+
if (tag.subTags && tag.subTags.length > 0) {
545+
sortTags(tag.subTags);
546+
}
547+
});
548+
// Then sort the array in place
549+
tags.sort((a, b) => a.name.localeCompare(b.name));
550+
};
551+
sortTags(tagStore.root.subTags);
552+
});
553+
538554
const handleBranchOnKeyDown = useAction(
539555
(event: React.KeyboardEvent<HTMLLIElement>, nodeData: ClientTag, treeData: ITreeData) =>
540556
createBranchOnKeyDown(
@@ -597,6 +613,13 @@ const TagsTree = observer((props: Partial<MultiSplitPaneProps>) => {
597613
tooltip="Add a new tag"
598614
/>
599615
)}
616+
{/* NEW: Sort button */}
617+
<ToolbarButton
618+
icon={IconSet.SORT} // make sure IconSet.SORT exists, or replace with an existing sort icon
619+
text="Sort"
620+
onClick={handleSortAlphabetically}
621+
tooltip="Sort tags alphabetically"
622+
/>
600623
</Toolbar>
601624
}
602625
{...props}

0 commit comments

Comments
 (0)