From edc5747a160becb1148799504bce2b2b8f2e8655 Mon Sep 17 00:00:00 2001 From: devguest Date: Wed, 26 Jun 2024 11:32:32 +0100 Subject: [PATCH 1/2] Add pendingAction to MultiLevelTags --- src/pages/workspace/tags/WorkspaceTagsPage.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index 0c9da8fbe90e..c944edf83639 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -71,6 +71,8 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { setSelectedTags({}); }, [isFocused]); + // hasPendingAction should cover main and child tags + const tagList = useMemo(() => { if (isMultiLevelTags) { return policyTagLists.map((policyTagList) => ({ From 92f83e26bbaaddfcc64ca96987646c7dd6d4d523 Mon Sep 17 00:00:00 2001 From: devguest Date: Mon, 1 Jul 2024 12:28:33 +0100 Subject: [PATCH 2/2] update pendingAction logic --- .../workspace/tags/WorkspaceTagsPage.tsx | 13 +++++++-- src/pages/workspace/tags/types.ts | 28 ++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index c944edf83639..8b9e57e485d2 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -34,8 +34,9 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; +import type {PendingAction} from '@src/types/onyx/OnyxCommon'; import type DeepValueOf from '@src/types/utils/DeepValueOf'; -import type {TagListItem} from './types'; +import type {PolicyTag, PolicyTagList, TagListItem} from './types'; type WorkspaceTagsPageProps = StackScreenProps; @@ -71,7 +72,14 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { setSelectedTags({}); }, [isFocused]); - // hasPendingAction should cover main and child tags + const getPendingAction = (policyTagList: PolicyTagList): PendingAction | undefined => { + if (!policyTagList) { + return undefined; + } + return (policyTagList.pendingAction as PendingAction) ?? Object.values(policyTagList.tags).some((tag: PolicyTag) => tag.pendingAction) + ? CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE + : undefined; + }; const tagList = useMemo(() => { if (isMultiLevelTags) { @@ -81,6 +89,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { text: PolicyUtils.getCleanedTagName(policyTagList.name), keyForList: String(policyTagList.orderWeight), isSelected: selectedTags[policyTagList.name], + pendingAction: getPendingAction(policyTagList), enabled: true, required: policyTagList.required, rightElement: ( diff --git a/src/pages/workspace/tags/types.ts b/src/pages/workspace/tags/types.ts index b601ce458ce4..cae0e5c4e3dd 100644 --- a/src/pages/workspace/tags/types.ts +++ b/src/pages/workspace/tags/types.ts @@ -1,4 +1,5 @@ import type {ListItem} from '@components/SelectionList/types'; +import type {Errors, PendingAction} from '@src/types/onyx/OnyxCommon'; type TagListItem = ListItem & { value: string; @@ -6,5 +7,30 @@ type TagListItem = ListItem & { orderWeight?: number; }; +type PolicyTag = { + name: string; + enabled: boolean; + previousTagName?: string; + /** "General Ledger code" that corresponds to this tag in an accounting system. Similar to an ID. */ + // eslint-disable-next-line @typescript-eslint/naming-convention + 'GL Code'?: string; + errors?: Errors | null; + rules?: { + parentTagsFilter?: string; + }; + parentTagsFilter?: string; + pendingAction?: PendingAction | null; +}; + +type PolicyTags = Record; + +type PolicyTagList = { + name: string; + orderWeight: number; + required: boolean; + tags: PolicyTags; + pendingAction?: PendingAction | null; +}; + // eslint-disable-next-line import/prefer-default-export -export type {TagListItem}; +export type {TagListItem, PolicyTag, PolicyTagList};