Skip to content

Commit

Permalink
used sorted keys on other places
Browse files Browse the repository at this point in the history
  • Loading branch information
FitseTLT committed Mar 26, 2024
1 parent 65d1759 commit 9012606
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ function getIneligibleInvitees(policyMembers: OnyxEntry<PolicyMembers>, personal
return memberEmailsToExclude;
}

function getSortedTagKeys(policyTagList: OnyxEntry<PolicyTagList>): Array<keyof PolicyTagList> {
if (isEmptyObject(policyTagList)) {
return [];
}

return Object.keys(policyTagList).sort((key1, key2) => policyTagList[key1].orderWeight - policyTagList[key2].orderWeight);
}

/**
* Gets a tag name of policy tags based on a tag index.
*/
Expand All @@ -178,7 +186,7 @@ function getTagListName(policyTagList: OnyxEntry<PolicyTagList>, tagIndex: numbe
return '';
}

const policyTagKeys = Object.keys(policyTagList ?? {});
const policyTagKeys = getSortedTagKeys(policyTagList ?? {});
const policyTagKey = policyTagKeys[tagIndex] ?? '';

return policyTagList?.[policyTagKey]?.name ?? '';
Expand All @@ -197,14 +205,6 @@ function getTagLists(policyTagList: OnyxEntry<PolicyTagList>): Array<PolicyTagLi
.sort((tagA, tagB) => tagA.orderWeight - tagB.orderWeight);
}

function getSortedTagKeys(policyTagList: OnyxEntry<PolicyTagList>): Array<keyof PolicyTagList> {
if (isEmptyObject(policyTagList)) {
return [];
}

return Object.keys(policyTagList).sort((key1, key2) => policyTagList[key1].orderWeight - policyTagList[key2].orderWeight);
}

/**
* Gets a tag list of a policy by a tag index
*/
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2228,7 +2228,7 @@ function buildOptimisticPolicyRecentlyUsedTags(policyID?: string, transactionTag
}

const policyTags = allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {};
const policyTagKeys = Object.keys(policyTags);
const policyTagKeys = PolicyUtils.getSortedTagKeys(policyTags);
const policyRecentlyUsedTags = allRecentlyUsedTags?.[`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${policyID}`] ?? {};
const newOptimisticPolicyRecentlyUsedTags: RecentlyUsedTags = {};

Expand All @@ -2238,7 +2238,7 @@ function buildOptimisticPolicyRecentlyUsedTags(policyID?: string, transactionTag
}

const tagListKey = policyTagKeys[index];
newOptimisticPolicyRecentlyUsedTags[tagListKey] = [...new Set([...tag, ...(policyRecentlyUsedTags[tagListKey] ?? [])])];
newOptimisticPolicyRecentlyUsedTags[tagListKey] = [...new Set([tag, ...(policyRecentlyUsedTags[tagListKey] ?? [])])];
});

return newOptimisticPolicyRecentlyUsedTags;
Expand Down

0 comments on commit 9012606

Please sign in to comment.