Skip to content

Commit

Permalink
Merge pull request #44441 from devguest07/43379
Browse files Browse the repository at this point in the history
Add pendingAction to MultiLevelTags
  • Loading branch information
AndrewGable authored Jul 9, 2024
2 parents f3ef92e + c67f2d4 commit 3688ed3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/pages/workspace/tags/WorkspaceTagsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<FullScreenNavigatorParamList, typeof SCREENS.WORKSPACE.TAGS>;

Expand Down Expand Up @@ -71,6 +72,15 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
setSelectedTags({});
}, [isFocused]);

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<TagListItem[]>(() => {
if (isMultiLevelTags) {
return policyTagLists.map((policyTagList) => ({
Expand All @@ -79,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: (
Expand Down
28 changes: 27 additions & 1 deletion src/pages/workspace/tags/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
import type {ListItem} from '@components/SelectionList/types';
import type {Errors, PendingAction} from '@src/types/onyx/OnyxCommon';

type TagListItem = ListItem & {
value: string;
enabled: boolean;
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<string, PolicyTag>;

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};

0 comments on commit 3688ed3

Please sign in to comment.