Skip to content

Commit

Permalink
feat(tags): add alphabetical sort button to TagsPanel
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Xavier-LB committed Feb 10, 2025
1 parent 14c2d6f commit 2d91437
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/frontend/containers/Outliner/TagsPanel/TagsTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,22 @@ const TagsTree = observer((props: Partial<MultiSplitPaneProps>) => {
}
});

// NEW: Action to sort the tags alphabetically (recursively)
const handleSortAlphabetically = useAction(() => {
// Recursive sorting function
const sortTags = (tags: ClientTag[]) => {
// First, sort children of each tag
tags.forEach(tag => {
if (tag.subTags && tag.subTags.length > 0) {
sortTags(tag.subTags);
}
});
// Then sort the array in place
tags.sort((a, b) => a.name.localeCompare(b.name));
};
sortTags(tagStore.root.subTags);
});

const handleBranchOnKeyDown = useAction(
(event: React.KeyboardEvent<HTMLLIElement>, nodeData: ClientTag, treeData: ITreeData) =>
createBranchOnKeyDown(
Expand Down Expand Up @@ -597,6 +613,13 @@ const TagsTree = observer((props: Partial<MultiSplitPaneProps>) => {
tooltip="Add a new tag"
/>
)}
{/* NEW: Sort button */}
<ToolbarButton
icon={IconSet.SORT} // make sure IconSet.SORT exists, or replace with an existing sort icon
text="Sort"
onClick={handleSortAlphabetically}
tooltip="Sort tags alphabetically"
/>
</Toolbar>
}
{...props}
Expand Down

0 comments on commit 2d91437

Please sign in to comment.