diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index b55efc2afff..85572ebe04a 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -2710,6 +2710,11 @@ function setPolicyRequiresTag(policyID: string, requiresTag: boolean) { function renamePolicyTaglist(policyID: string, policyTagListName: {oldName: string; newName: string}, policyTags: OnyxEntry) { const newName = policyTagListName.newName; const oldName = policyTagListName.oldName; + + if (oldName === newName) { + return; + } + const oldPolicyTags = policyTags?.[oldName] ?? {}; const onyxData: OnyxData = { optimisticData: [ @@ -2728,7 +2733,6 @@ function renamePolicyTaglist(policyID: string, policyTagListName: {oldName: stri key: `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`, value: { [newName]: {pendingAction: null}, - [oldName]: null, }, }, ], @@ -2737,12 +2741,8 @@ function renamePolicyTaglist(policyID: string, policyTagListName: {oldName: stri onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`, value: { - errors: { - [oldName]: oldName, - [newName]: ErrorUtils.getMicroSecondOnyxError('workspace.tags.genericFailureMessage'), - }, [newName]: null, - [oldName]: oldPolicyTags, + [oldName]: {...oldPolicyTags, errors: ErrorUtils.getMicroSecondOnyxError('workspace.tags.genericFailureMessage')}, }, }, ], diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index d0905ab6e80..cc809892d45 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -68,7 +68,7 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { () => policyTagLists .map((policyTagList) => - Object.values(policyTagList.tags).map((value) => ({ + Object.values(policyTagList.tags || []).map((value) => ({ value: value.name, text: value.name, keyForList: value.name, diff --git a/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx index d67ca5eb5fe..deac804980e 100644 --- a/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx @@ -31,7 +31,7 @@ type WorkspaceTagsSettingsPageProps = WorkspaceTagsSettingsPageOnyxProps & Stack function WorkspaceTagsSettingsPage({route, policyTags}: WorkspaceTagsSettingsPageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); - const policyTagName = useMemo(() => PolicyUtils.getTagLists(policyTags)[0]?.name ?? '', [policyTags]); + const policyTagName = useMemo(() => PolicyUtils.getTagLists(policyTags)?.[0]?.name ?? '', [policyTags]); const updateWorkspaceRequiresTag = useCallback( (value: boolean) => { @@ -66,6 +66,12 @@ function WorkspaceTagsSettingsPage({route, policyTags}: WorkspaceTagsSettingsPag /> + + = Record< /** Index by which the tag appears in the hierarchy of tags */ orderWeight: number; + + /** A list of errors keyed by microtime */ + errors?: OnyxCommon.Errors; }> >;