Skip to content

Commit a1866a4

Browse files
committed
Make sure we preserve tag level order according to orderWeight
1 parent 7dc19ff commit a1866a4

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/pages/workspace/tags/WorkspaceTagsPage.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,17 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
248248
const normalizeSearchInput = StringUtils.normalize(searchInput.toLowerCase());
249249
return tagText.includes(normalizeSearchInput) || tagValue.includes(normalizeSearchInput);
250250
}, []);
251-
const sortTags = useCallback((tags: TagListItem[]) => tags.sort((a, b) => localeCompare(a.value, b.value)), []);
251+
const sortTags = useCallback(
252+
(tags: TagListItem[]) => {
253+
// For multi-level tags, preserve the policy order (by orderWeight) instead of sorting alphabetically
254+
if (hasDependentTags || isMultiLevelTags) {
255+
return tags.sort((a, b) => (a.orderWeight ?? 0) - (b.orderWeight ?? 0));
256+
}
257+
// For other cases, sort alphabetically by name
258+
return tags.sort((a, b) => localeCompare(a.value, b.value));
259+
},
260+
[hasDependentTags, isMultiLevelTags],
261+
);
252262
const [inputValue, setInputValue, filteredTagList] = useSearchResults(tagList, filterTag, sortTags);
253263

254264
const filteredTagListKeyedByName = useMemo(

0 commit comments

Comments
 (0)