Skip to content

Commit

Permalink
Merge pull request #38096 from Expensify/cmartins-fixErrorsInTagsPage
Browse files Browse the repository at this point in the history
  • Loading branch information
blimpich authored Mar 12, 2024
2 parents 5f520f1 + c394083 commit 48b4de2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2710,6 +2710,11 @@ function setPolicyRequiresTag(policyID: string, requiresTag: boolean) {
function renamePolicyTaglist(policyID: string, policyTagListName: {oldName: string; newName: string}, policyTags: OnyxEntry<PolicyTagList>) {
const newName = policyTagListName.newName;
const oldName = policyTagListName.oldName;

if (oldName === newName) {
return;
}

const oldPolicyTags = policyTags?.[oldName] ?? {};
const onyxData: OnyxData = {
optimisticData: [
Expand All @@ -2728,7 +2733,6 @@ function renamePolicyTaglist(policyID: string, policyTagListName: {oldName: stri
key: `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`,
value: {
[newName]: {pendingAction: null},
[oldName]: null,
},
},
],
Expand All @@ -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')},
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/tags/WorkspaceTagsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -66,6 +66,12 @@ function WorkspaceTagsSettingsPage({route, policyTags}: WorkspaceTagsSettingsPag
/>
</View>
</View>
</OfflineWithFeedback>
<OfflineWithFeedback
errors={policyTags?.[policyTagName]?.errors}
pendingAction={policyTags?.[policyTagName]?.pendingAction}
errorRowStyles={styles.mh5}
>
<MenuItemWithTopDescription
title={policyTagName}
description={translate(`workspace.tags.customTagName`)}
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/PolicyTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ type PolicyTagList<T extends string = string> = Record<

/** Index by which the tag appears in the hierarchy of tags */
orderWeight: number;

/** A list of errors keyed by microtime */
errors?: OnyxCommon.Errors;
}>
>;

Expand Down

0 comments on commit 48b4de2

Please sign in to comment.