Skip to content

Commit

Permalink
Merge pull request #38332 from allroundexperts/fix-38289
Browse files Browse the repository at this point in the history
fix: allow selection list to be greyed for tags
  • Loading branch information
luacmartins authored Mar 15, 2024
2 parents 6719621 + 861fa37 commit be9a682
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2884,7 +2884,6 @@ function createPolicyTag(policyID: string, tagName: string) {
tags: {
[tagName]: {
errors: ErrorUtils.getMicroSecondOnyxError('workspace.tags.genericFailureMessage'),
pendingAction: null,
},
},
},
Expand All @@ -2901,6 +2900,36 @@ function createPolicyTag(policyID: string, tagName: string) {
API.write(WRITE_COMMANDS.CREATE_POLICY_TAG, parameters, onyxData);
}

function clearPolicyTagErrors(policyID: string, tagName: string) {
const tagListName = Object.keys(allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {})[0];
const tag = allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`]?.[tagListName].tags?.[tagName];
if (!tag) {
return;
}

if (tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`, {
[tagListName]: {
tags: {
[tagName]: null,
},
},
});
return;
}

Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`, {
[tagListName]: {
tags: {
[tagName]: {
errors: null,
pendingAction: null,
},
},
},
});
}

function setWorkspaceRequiresCategory(policyID: string, requiresCategory: boolean) {
const onyxData: OnyxData = {
optimisticData: [
Expand Down Expand Up @@ -3665,6 +3694,7 @@ export {
openPolicyDistanceRatesPage,
openPolicyMoreFeaturesPage,
createPolicyTag,
clearPolicyTagErrors,
clearWorkspaceReimbursementErrors,
deleteWorkspaceCategories,
};
3 changes: 3 additions & 0 deletions src/pages/workspace/tags/WorkspaceTagsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) {
text: value.name,
keyForList: value.name,
isSelected: !!selectedTags[value.name],
pendingAction: value.pendingAction,
errors: value.errors ?? undefined,
rightElement: (
<View style={styles.flexRow}>
<Text style={[styles.textSupporting, styles.alignSelfCenter, styles.pl2, styles.label]}>
Expand Down Expand Up @@ -188,6 +190,7 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) {
ListItem={TableListItem}
customListHeader={getCustomListHeader()}
listHeaderWrapperStyle={[styles.ph9, styles.pv3, styles.pb5]}
onDismissError={(item) => Policy.clearPolicyTagErrors(route.params.policyID, item.value)}
/>
)}
</ScreenWrapper>
Expand Down

0 comments on commit be9a682

Please sign in to comment.