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 "Create Tag" page #38158

Merged
merged 13 commits into from
Mar 12, 2024
1 change: 0 additions & 1 deletion src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,6 @@ const CONST = {
MAX_64BIT_MIDDLE_PART: 7203685,
MAX_64BIT_RIGHT_PART: 4775807,
INVALID_CATEGORY_NAME: '###',
INVALID_TAG_NAME: '###',

// When generating a random value to fit in 7 digits (for the `middle` or `right` parts above), this is the maximum value to multiply by Math.random().
MAX_INT_FOR_RANDOM_7_DIGIT_VALUE: 10000000,
Expand Down
4 changes: 2 additions & 2 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ const ROUTES = {
getRoute: (policyID: string) => `workspace/${policyID}/tags` as const,
},
WORKSPACE_TAG_CREATE: {
route: 'workspace/:policyID/tag/new',
getRoute: (policyID: string) => `workspace/${policyID}/tag/new` as const,
route: 'workspace/:policyID/tags/new',
getRoute: (policyID: string) => `workspace/${policyID}/tags/new` as const,
},
WORKSPACE_TAGS_SETTINGS: {
route: 'workspace/:policyID/tags/settings',
Expand Down
1 change: 0 additions & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1842,7 +1842,6 @@ export default {
},
tagRequiredError: 'Tag name is required.',
existingTagError: 'A tag with this name already exists.',
invalidTagName: 'Invalid tag name.',
genericFailureMessage: 'An error occurred while updating the tag, please try again.',
},
emptyWorkspace: {
Expand Down
1 change: 0 additions & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,6 @@ export default {
},
tagRequiredError: 'Tag name is required.',
allroundexperts marked this conversation as resolved.
Show resolved Hide resolved
existingTagError: 'A tag with this name already exists.',
allroundexperts marked this conversation as resolved.
Show resolved Hide resolved
invalidTagName: 'Invalid tag name.',
genericFailureMessage: 'Se produjo un error al actualizar la etiqueta, inténtelo nuevamente.',
},
emptyWorkspace: {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/API/parameters/CreateWorkspaceTagsParams.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type CreateWorkspaceTagsParams = {
type CreatePolicyTagsParams = {
policyID: string;
/**
* Stringified JSON object with type of following structure:
Expand All @@ -7,4 +7,4 @@ type CreateWorkspaceTagsParams = {
tags: string;
};

export default CreateWorkspaceTagsParams;
export default CreatePolicyTagsParams;
2 changes: 1 addition & 1 deletion src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,4 @@
export type {default as JoinPolicyInviteLinkParams} from './JoinPolicyInviteLink';
export type {default as OpenPolicyWorkflowsPageParams} from './OpenPolicyWorkflowsPageParams';
export type {default as OpenPolicyDistanceRatesPageParams} from './OpenPolicyDistanceRatesPageParams';
export type {default as CreateWorkspaceTagsParams} from './CreateWorkspaceTagsParams';
export type {default as CreatePolicyTagsParams} from './CreatePolicyTagsParams';

Check failure on line 176 in src/libs/API/parameters/index.ts

View workflow job for this annotation

GitHub Actions / typecheck

Cannot find module './CreatePolicyTagsParams' or its corresponding type declarations.
4 changes: 2 additions & 2 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const WRITE_COMMANDS = {
CREATE_WORKSPACE_FROM_IOU_PAYMENT: 'CreateWorkspaceFromIOUPayment',
SET_WORKSPACE_CATEGORIES_ENABLED: 'SetWorkspaceCategoriesEnabled',
CREATE_WORKSPACE_CATEGORIES: 'CreateWorkspaceCategories',
CREATE_WORKSPACE_TAG: 'CreatePolicyTag',
CREATE_POLICY_TAG: 'CreatePolicyTag',
SET_WORKSPACE_REQUIRES_CATEGORY: 'SetWorkspaceRequiresCategory',
SET_POLICY_REQUIRES_TAG: 'SetPolicyRequiresTag',
RENAME_POLICY_TAG_LIST: 'RenamePolicyTaglist',
Expand Down Expand Up @@ -284,7 +284,7 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.SET_WORKSPACE_REQUIRES_CATEGORY]: Parameters.SetWorkspaceRequiresCategoryParams;
[WRITE_COMMANDS.SET_POLICY_REQUIRES_TAG]: Parameters.SetPolicyRequiresTag;
[WRITE_COMMANDS.RENAME_POLICY_TAG_LIST]: Parameters.RenamePolicyTaglist;
[WRITE_COMMANDS.CREATE_WORKSPACE_TAG]: Parameters.CreateWorkspaceTagsParams;
[WRITE_COMMANDS.CREATE_POLICY_TAG]: Parameters.CreatePolicyTagsParams;
[WRITE_COMMANDS.CREATE_TASK]: Parameters.CreateTaskParams;
[WRITE_COMMANDS.CANCEL_TASK]: Parameters.CancelTaskParams;
[WRITE_COMMANDS.EDIT_TASK_ASSIGNEE]: Parameters.EditTaskAssigneeParams;
Expand Down
21 changes: 15 additions & 6 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2758,10 +2758,10 @@ function createPolicyTag(policyID: string, tagName: string) {
[tagName]: {
name: tagName,
enabled: false,
errors: null,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
},
errors: null,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
},
},
Expand All @@ -2772,8 +2772,12 @@ function createPolicyTag(policyID: string, tagName: string) {
key: `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`,
value: {
Tag: {
errors: null,
pendingAction: null,
tags: {
[tagName]: {
errors: null,
pendingAction: null,
},
},
},
},
},
Expand All @@ -2784,7 +2788,12 @@ function createPolicyTag(policyID: string, tagName: string) {
key: `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`,
value: {
Tag: {
errors: ErrorUtils.getMicroSecondOnyxError('workspace.tags.genericFailureMessage'),
tags: {
[tagName]: {
errors: ErrorUtils.getMicroSecondOnyxError('workspace.tags.genericFailureMessage'),
pendingAction: null,
},
},
},
},
},
Expand All @@ -2796,7 +2805,7 @@ function createPolicyTag(policyID: string, tagName: string) {
tags: JSON.stringify([{name: tagName}]),
};

API.write(WRITE_COMMANDS.CREATE_WORKSPACE_TAG, parameters, onyxData);
API.write(WRITE_COMMANDS.CREATE_POLICY_TAG, parameters, onyxData);
}

function setWorkspaceRequiresCategory(policyID: string, requiresCategory: boolean) {
Expand Down
2 changes: 0 additions & 2 deletions src/pages/workspace/tags/WorkspaceCreateTagPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ function CreateTagPage({route, policyTags}: CreateTagPageProps) {
errors.tagName = 'workspace.tags.tagRequiredError';
} else if (policyTags?.Tag?.tags?.[tagName]) {
errors.tagName = 'workspace.tags.existingTagError';
} else if (tagName === CONST.INVALID_TAG_NAME) {
errors.tagName = 'workspace.tags.invalidTagName';
} else if ([...tagName].length > CONST.TAG_NAME_LIMIT) {
// Uses the spread syntax to count the number of Unicode code points instead of the number of UTF-16 code units.
ErrorUtils.addErrorMessage(errors, 'tagName', ['common.error.characterLimitExceedCounter', {length: [...tagName].length, limit: CONST.TAG_NAME_LIMIT}]);
Expand Down
5 changes: 4 additions & 1 deletion src/types/onyx/PolicyTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ type PolicyTag = {
/** "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;

/** A list of errors keyed by microtime */
errors?: OnyxCommon.Errors;
};

type PolicyTags = Record<string, PolicyTag>;
type PolicyTags = Record<string, OnyxCommon.OnyxValueWithOfflineFeedback<PolicyTag>>;

type PolicyTagList<T extends string = string> = Record<
T,
Expand Down
Loading