Skip to content
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
31 changes: 23 additions & 8 deletions src/libs/actions/Policy/Tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ function clearPolicyTagErrors(policyID: string, tagName: string, tagListIndex: n
});
}

function clearPolicyTagListError(policyID: string, tagListIndex: number, errorField: string) {
function clearPolicyTagListErrorField(policyID: string, tagListIndex: number, errorField: string) {
const policyTag = PolicyUtils.getTagLists(allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {})?.[tagListIndex] ?? {};

if (!policyTag.name) {
Expand All @@ -379,6 +379,20 @@ function clearPolicyTagListError(policyID: string, tagListIndex: number, errorFi
});
}

function clearPolicyTagListErrors(policyID: string, tagListIndex: number) {
const policyTag = PolicyUtils.getTagLists(allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {})?.[tagListIndex] ?? {};

if (!policyTag.name) {
return;
}

Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`, {
[policyTag.name]: {
errors: null,
},
});
}

function renamePolicyTag(policyID: string, policyTag: {oldName: string; newName: string}, tagListIndex: number) {
const tagList = PolicyUtils.getTagLists(allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {})?.[tagListIndex] ?? {};
const tag = tagList.tags?.[policyTag.oldName];
Expand Down Expand Up @@ -569,7 +583,7 @@ function renamePolicyTaglist(policyID: string, policyTagListName: {oldName: stri
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`,
value: {
[newName]: {...oldPolicyTags, name: newName, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD},
[newName]: {...oldPolicyTags, name: newName, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, errors: null},
[oldName]: null,
},
},
Expand All @@ -589,12 +603,12 @@ function renamePolicyTaglist(policyID: string, policyTagListName: {oldName: stri
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`,
value: {
errors: {
[oldName]: oldName,
[newName]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.tags.genericFailureMessage'),
},
[newName]: null,
[oldName]: oldPolicyTags,
[oldName]: {
...oldPolicyTags,
pendingAction: null,
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.tags.genericFailureMessage'),
},
},
},
],
Expand Down Expand Up @@ -725,7 +739,8 @@ export {
setPolicyTagsRequired,
createPolicyTag,
clearPolicyTagErrors,
clearPolicyTagListError,
clearPolicyTagListErrors,
clearPolicyTagListErrorField,
deletePolicyTags,
enablePolicyTags,
openPolicyTagsPage,
Expand Down
10 changes: 6 additions & 4 deletions src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,22 @@ type WorkspaceTagsSettingsPageOnyxProps = {
type WorkspaceTagsSettingsPageProps = WorkspaceTagsSettingsPageOnyxProps & StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.TAGS_SETTINGS>;

function WorkspaceTagsSettingsPage({route, policyTags}: WorkspaceTagsSettingsPageProps) {
const policyID = route.params.policyID;
const styles = useThemeStyles();
const {translate} = useLocalize();
const [policyTagLists, isMultiLevelTags] = useMemo(() => [PolicyUtils.getTagLists(policyTags), PolicyUtils.isMultiLevelTags(policyTags)], [policyTags]);
const hasEnabledOptions = OptionsListUtils.hasEnabledOptions(Object.values(policyTags ?? {}).flatMap(({tags}) => Object.values(tags)));
const updateWorkspaceRequiresTag = useCallback(
(value: boolean) => {
Tag.setPolicyRequiresTag(route.params.policyID, value);
Tag.setPolicyRequiresTag(policyID, value);
},
[route.params.policyID],
[policyID],
);

return (
<AccessOrNotFoundWrapper
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]}
policyID={route.params.policyID}
policyID={policyID}
featureName={CONST.POLICY.MORE_FEATURES.ARE_TAGS_ENABLED}
>
{({policy}) => (
Expand Down Expand Up @@ -75,13 +76,14 @@ function WorkspaceTagsSettingsPage({route, policyTags}: WorkspaceTagsSettingsPag
{!isMultiLevelTags && (
<OfflineWithFeedback
errors={policyTags?.[policyTagLists[0].name]?.errors}
onClose={() => Tag.clearPolicyTagListErrors(policyID, policyTagLists[0].orderWeight)}
pendingAction={policyTags?.[policyTagLists[0].name]?.pendingAction}
errorRowStyles={styles.mh5}
>
<MenuItemWithTopDescription
title={policyTagLists[0].name}
description={translate(`workspace.tags.customTagName`)}
onPress={() => Navigation.navigate(ROUTES.WORKSPACE_EDIT_TAGS.getRoute(route.params.policyID, policyTagLists[0].orderWeight))}
onPress={() => Navigation.navigate(ROUTES.WORKSPACE_EDIT_TAGS.getRoute(policyID, policyTagLists[0].orderWeight))}
shouldShowRightIcon
/>
</OfflineWithFeedback>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/tags/WorkspaceViewTagsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) {
onToggle={(on) => Tag.setPolicyTagsRequired(policyID, on, route.params.orderWeight)}
pendingAction={currentPolicyTag.pendingFields?.required}
errors={currentPolicyTag?.errorFields?.required ?? undefined}
onCloseError={() => Tag.clearPolicyTagListError(policyID, route.params.orderWeight, 'required')}
onCloseError={() => Tag.clearPolicyTagListErrorField(policyID, route.params.orderWeight, 'required')}
disabled={!currentPolicyTag?.required && !Object.values(currentPolicyTag?.tags ?? {}).some((tag) => tag.enabled)}
/>
</View>
Expand Down
2 changes: 1 addition & 1 deletion tests/actions/PolicyTagTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ describe('actions/Policy', () => {

expect(policyTags?.[newTagListName]).toBeFalsy();
expect(policyTags?.[oldTagListName]).toBeTruthy();
expect(policyTags?.errors).toBeTruthy();
expect(policyTags?.[oldTagListName]?.errors).toBeTruthy();

resolve();
},
Expand Down