sort transaction tags by name (#487)

This commit is contained in:
MaysWind
2026-03-01 22:03:38 +08:00
parent a84f48ae8a
commit f5a7e2e2d6
22 changed files with 123 additions and 1 deletions
+52
View File
@@ -151,6 +151,57 @@ export const useTransactionTagsStore = defineStore('transactionTags', () => {
allTransactionTagGroups.value.splice(to, 0, allTransactionTagGroups.value.splice(from, 1)[0] as TransactionTagGroup);
}
function sortTagDisplayOrderByTagName(groupId: string, desc: boolean): boolean {
// update in the group list
const tagsInGroup = allTransactionTagsByGroupMap.value[groupId];
if (!tagsInGroup) {
return false;
}
const oldTagsInGroup: TransactionTag[] = [...tagsInGroup];
if (!desc) {
tagsInGroup.sort((a, b) => a.name.localeCompare(b.name, undefined, { // asc
numeric: true,
sensitivity: 'base'
}));
} else {
tagsInGroup.sort((a, b) => b.name.localeCompare(a.name, undefined, { // desc
numeric: true,
sensitivity: 'base'
}));
}
const isOrderChanged = !isEquals(oldTagsInGroup, tagsInGroup);
if (!isOrderChanged) {
return false;
}
// update in the main list
for (const [oldTag, oldIndex] of itemAndIndex(oldTagsInGroup)) {
const newTag = tagsInGroup[oldIndex];
if (!newTag || newTag.id === oldTag.id) {
continue;
}
for (const [tag, index] of itemAndIndex(allTransactionTags.value)) {
if (tag.id === oldTag.id) {
allTransactionTags.value.splice(index, 1, newTag);
break;
}
}
}
if (!transactionTagListStateInvalid.value) {
updateTransactionTagListInvalidState(true);
}
return true;
}
function updateTagDisplayOrderInTransactionTagList({ groupId, from, to }: { groupId: string, from: number, to: number }): void {
// update in the group list
const tagsInGroup = allTransactionTagsByGroupMap.value[groupId];
@@ -757,6 +808,7 @@ export const useTransactionTagsStore = defineStore('transactionTags', () => {
// computed states
allAvailableTagsCount,
// functions
sortTagDisplayOrderByTagName,
updateTransactionTagListInvalidState,
resetTransactionTags,
loadAllTagGroups,