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

Add pendingAction to MultiLevelTags #44441

Merged
merged 4 commits into from
Jul 9, 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
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 = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reuse types from src/types/onyx/PolicyTag.ts ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devguest07 What do you think about the comment above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reuse types from src/types/onyx/PolicyTag.ts ?

The types defined in PolicyTags are similar to the required ones, but they don't cover all properties. Some are missing, which resulted in TypeScript errors when I attempted to use them.

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