Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on Tags page error #38096

Merged
merged 5 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading