From 3566460ccd2aa92e0f78a9b82d31a21f2eb62016 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Wed, 20 Mar 2024 00:45:01 +0100 Subject: [PATCH 01/33] add multitag regex --- src/CONST.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/CONST.ts b/src/CONST.ts index 3c53f083abac..a3fd483255a4 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1655,6 +1655,10 @@ const CONST = { MERGED_ACCOUNT_PREFIX: /^(MERGED_\d+@)/, + get MULTI_LEVEL_TAG() { + return new RegExp("/\\{1,2}:/g"); + }, + ROUTES: { VALIDATE_LOGIN: /\/v($|(\/\/*))/, UNLINK_LOGIN: /\/u($|(\/\/*))/, From 04d2b5962b3d77bc25b65dc0053585427163658e Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Wed, 20 Mar 2024 00:59:48 +0100 Subject: [PATCH 02/33] introducted a new boolean agrument, defaulted to false, callled excludeMultiLevelTags for the getTagLists function --- src/libs/PolicyUtils.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 39e6c8932aad..45e5aa03760f 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -188,13 +188,15 @@ function getTagListName(policyTagList: OnyxEntry, tagIndex: numbe /** * Gets all tag lists of a policy */ -function getTagLists(policyTagList: OnyxEntry): Array { +function getTagLists(policyTagList: OnyxEntry, excludeMultiLevelTags = false): Array { if (isEmptyObject(policyTagList)) { return []; } + const regex = new RegExp(CONST.REGEX.MULTI_LEVEL_TAG, `/\\{1,2}:/g`); + return Object.values(policyTagList) - .filter((policyTagListValue) => policyTagListValue !== null) + .filter((policyTagListValue) => policyTagListValue !== null && (!excludeMultiLevelTags || regex.test(policyTagListValue.name))) .sort((tagA, tagB) => tagA.orderWeight - tagB.orderWeight); } From cbd67a509ec7230569bf924dec7a47bea45647bf Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Wed, 20 Mar 2024 01:31:18 +0100 Subject: [PATCH 03/33] introducted a new boolean agrument, defaulted to false, callled excludeMultiLevelTags for the getTagLists function --- src/libs/PolicyUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 45e5aa03760f..7a34ae22f023 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -196,7 +196,7 @@ function getTagLists(policyTagList: OnyxEntry, excludeMultiLevelT const regex = new RegExp(CONST.REGEX.MULTI_LEVEL_TAG, `/\\{1,2}:/g`); return Object.values(policyTagList) - .filter((policyTagListValue) => policyTagListValue !== null && (!excludeMultiLevelTags || regex.test(policyTagListValue.name))) + .filter((policyTagListValue) => !(!policyTagListValue || excludeMultiLevelTags || regex.test(policyTagListValue.name))) .sort((tagA, tagB) => tagA.orderWeight - tagB.orderWeight); } From 3dc48b4e97f9427f0d459a6da5fdce76df758e77 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Thu, 21 Mar 2024 15:55:25 +0300 Subject: [PATCH 04/33] Removing multitags --- src/pages/workspace/tags/WorkspaceTagsPage.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index 392d392c55ef..860b47d615ec 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -76,6 +76,7 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { policyTagLists .map((policyTagList) => Object.values(policyTagList.tags || []) + .filter((value) => value.name == getCleanTagName(value.name)) .sort((a, b) => localeCompare(a.name, b.name)) .map((value) => ({ value: value.name, From 3c73312640b3fe60b3d050a98ab76d60754b7b5f Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Thu, 21 Mar 2024 14:15:47 +0100 Subject: [PATCH 05/33] fix --- src/libs/PolicyUtils.ts | 34 +++---------------- .../workspace/tags/WorkspaceTagsPage.tsx | 2 +- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 7a34ae22f023..f7f83f1cfbcb 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -4,8 +4,7 @@ import type {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {PersonalDetailsList, Policy, PolicyCategories, PolicyMembers, PolicyTagList, PolicyTags, TaxRate} from '@src/types/onyx'; -import type {PolicyFeatureName} from '@src/types/onyx/Policy'; +import type {PersonalDetailsList, Policy, PolicyCategories, PolicyMembers, PolicyTagList, PolicyTags} from '@src/types/onyx'; import type {EmptyObject} from '@src/types/utils/EmptyObject'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import Navigation from './Navigation/Navigation'; @@ -35,7 +34,7 @@ function hasPolicyMemberError(policyMembers: OnyxEntry): boolean * Check if the policy has any tax rate errors. */ function hasTaxRateError(policy: OnyxEntry): boolean { - return Object.values(policy?.taxRates?.taxes ?? {}).some((taxRate) => Object.keys(taxRate?.errors ?? {}).length > 0 || Object.values(taxRate?.errorFields ?? {}).some(Boolean)); + return Object.values(policy?.taxRates?.taxes ?? {}).some((taxRate) => Object.keys(taxRate?.errors ?? {}).length > 0); } /** @@ -188,15 +187,13 @@ function getTagListName(policyTagList: OnyxEntry, tagIndex: numbe /** * Gets all tag lists of a policy */ -function getTagLists(policyTagList: OnyxEntry, excludeMultiLevelTags = false): Array { +function getTagLists(policyTagList: OnyxEntry ): Array { if (isEmptyObject(policyTagList)) { return []; } - const regex = new RegExp(CONST.REGEX.MULTI_LEVEL_TAG, `/\\{1,2}:/g`); - return Object.values(policyTagList) - .filter((policyTagListValue) => !(!policyTagListValue || excludeMultiLevelTags || regex.test(policyTagListValue.name))) + .filter((policyTagListValue) => policyTagListValue !== null) .sort((tagA, tagB) => tagA.orderWeight - tagB.orderWeight); } @@ -279,26 +276,6 @@ function goBackFromInvalidPolicy() { Navigation.navigate(ROUTES.SETTINGS_WORKSPACES); } -/** Get a tax with given ID from policy */ -function getTaxByID(policy: OnyxEntry, taxID: string): TaxRate | undefined { - return policy?.taxRates?.taxes?.[taxID]; -} - -/** - * Whether the tax rate can be deleted and disabled - */ -function canEditTaxRate(policy: Policy, taxID: string): boolean { - return policy.taxRates?.defaultExternalID !== taxID; -} - -function isPolicyFeatureEnabled(policy: OnyxEntry | EmptyObject, featureName: PolicyFeatureName): boolean { - if (featureName === CONST.POLICY.MORE_FEATURES.ARE_TAXES_ENABLED) { - return Boolean(policy?.tax?.trackingEnabled); - } - - return Boolean(policy?.[featureName]); -} - export { getActivePolicies, hasAccountingConnections, @@ -319,7 +296,6 @@ export { getIneligibleInvitees, getTagLists, getTagListName, - canEditTaxRate, getTagList, getCleanedTagName, getCountOfEnabledTagsOfList, @@ -330,9 +306,7 @@ export { getPathWithoutPolicyID, getPolicyMembersByIdWithoutCurrentUser, goBackFromInvalidPolicy, - isPolicyFeatureEnabled, hasTaxRateError, - getTaxByID, hasPolicyCategoriesError, }; diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index d19604608bbb..0b0758affd93 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -84,7 +84,7 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { policyTagLists .map((policyTagList) => Object.values(policyTagList.tags || []) - .filter((value) => value.name == getCleanTagName(value.name)) + .filter((value) => value.name === PolicyUtils.getCleanedTagName(value.name)) .sort((a, b) => localeCompare(a.name, b.name)) .map((value) => ({ value: value.name, From 6dbefcfad1a8b0189754aaee634b87d51cb59a51 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Thu, 21 Mar 2024 15:31:28 +0100 Subject: [PATCH 06/33] fix --- src/libs/PolicyUtils.ts | 2 +- src/pages/workspace/tags/WorkspaceTagsPage.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index f7f83f1cfbcb..675e268045c1 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -187,7 +187,7 @@ function getTagListName(policyTagList: OnyxEntry, tagIndex: numbe /** * Gets all tag lists of a policy */ -function getTagLists(policyTagList: OnyxEntry ): Array { +function getTagLists(policyTagList: OnyxEntry): Array { if (isEmptyObject(policyTagList)) { return []; } diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index 0b0758affd93..46417f445bf8 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -84,8 +84,8 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { policyTagLists .map((policyTagList) => Object.values(policyTagList.tags || []) - .filter((value) => value.name === PolicyUtils.getCleanedTagName(value.name)) .sort((a, b) => localeCompare(a.name, b.name)) + .filter((value) => PolicyUtils.getCleanedTagName(value.name) === value.name) .map((value) => ({ value: value.name, text: value.name, From cb96df9e670a724043bafa8b39e2c585b1ef37e8 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Thu, 21 Mar 2024 15:39:20 +0100 Subject: [PATCH 07/33] Refactoring ... --- src/pages/workspace/tags/WorkspaceTagsPage.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index a355cc062f3d..46417f445bf8 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -85,6 +85,7 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { .map((policyTagList) => Object.values(policyTagList.tags || []) .sort((a, b) => localeCompare(a.name, b.name)) + .filter((value) => PolicyUtils.getCleanedTagName(value.name) === value.name) .map((value) => ({ value: value.name, text: value.name, From b9722381fb84e6a32808147d988f43d6fca49ea2 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Wed, 27 Mar 2024 21:31:48 +0100 Subject: [PATCH 08/33] CONST.ts revert --- src/CONST.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 4eff4ee25502..47caa5e64a90 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1666,10 +1666,6 @@ const CONST = { MERGED_ACCOUNT_PREFIX: /^(MERGED_\d+@)/, - get MULTI_LEVEL_TAG() { - return new RegExp("/\\{1,2}:/g"); - }, - ROUTES: { VALIDATE_LOGIN: /\/v($|(\/\/*))/, UNLINK_LOGIN: /\/u($|(\/\/*))/, From 551d81d92882d6fb6324f55a1c453a912f17188c Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Wed, 27 Mar 2024 22:56:31 +0100 Subject: [PATCH 09/33] revert --- src/libs/PolicyUtils.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 7923533f8f6c..a16141dd3063 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -276,6 +276,11 @@ function goBackFromInvalidPolicy() { Navigation.navigate(ROUTES.SETTINGS_WORKSPACES); } +/** Get a tax with given ID from policy */ +function getTaxByID(policy: OnyxEntry, taxID: string): TaxRate | undefined { + return policy?.taxRates?.taxes?.[taxID]; +} + export { getActivePolicies, hasAccountingConnections, @@ -307,6 +312,7 @@ export { getPolicyMembersByIdWithoutCurrentUser, goBackFromInvalidPolicy, hasTaxRateError, + getTaxByID, hasPolicyCategoriesError, }; From fd16783e0aad8797c0b6f635fbf618f39ccda3d6 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Wed, 27 Mar 2024 23:45:57 +0100 Subject: [PATCH 10/33] reverting ... --- src/libs/PolicyUtils.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index a16141dd3063..43bda05c9e21 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -34,7 +34,7 @@ function hasPolicyMemberError(policyMembers: OnyxEntry): boolean * Check if the policy has any tax rate errors. */ function hasTaxRateError(policy: OnyxEntry): boolean { - return Object.values(policy?.taxRates?.taxes ?? {}).some((taxRate) => Object.keys(taxRate?.errors ?? {}).length > 0); + return Object.values(policy?.taxRates?.taxes ?? {}).some((taxRate) => Object.keys(taxRate?.errors ?? {}).length > 0 || Object.values(taxRate?.errorFields ?? {}).some(Boolean)); } /** @@ -281,6 +281,21 @@ function getTaxByID(policy: OnyxEntry, taxID: string): TaxRate | undefin return policy?.taxRates?.taxes?.[taxID]; } +/** + * Whether the tax rate can be deleted and disabled + */ +function canEditTaxRate(policy: Policy, taxID: string): boolean { + return policy.taxRates?.defaultExternalID !== taxID; +} + +function isPolicyFeatureEnabled(policy: OnyxEntry | EmptyObject, featureName: PolicyFeatureName): boolean { + if (featureName === CONST.POLICY.MORE_FEATURES.ARE_TAXES_ENABLED) { + return Boolean(policy?.tax?.trackingEnabled); + } + + return Boolean(policy?.[featureName]); +} + export { getActivePolicies, hasAccountingConnections, @@ -301,6 +316,7 @@ export { getIneligibleInvitees, getTagLists, getTagListName, + canEditTaxRate, getTagList, getCleanedTagName, getCountOfEnabledTagsOfList, @@ -311,6 +327,7 @@ export { getPathWithoutPolicyID, getPolicyMembersByIdWithoutCurrentUser, goBackFromInvalidPolicy, + isPolicyFeatureEnabled, hasTaxRateError, getTaxByID, hasPolicyCategoriesError, From 39e2defa88e2f8346cc9bc5df6261e8e4311fd55 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Fri, 29 Mar 2024 07:22:39 +0100 Subject: [PATCH 11/33] merge confilcts --- .../workspace/tags/WorkspaceTagsPage.tsx | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index 54cbe27b67d4..a3dd72389dde 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -84,33 +84,34 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { () => policyTagLists .map((policyTagList) => - lodashSortBy(Object.values(policyTagList.tags || []), 'name', localeCompare).map((value) => { - const tag = value as OnyxCommon.OnyxValueWithOfflineFeedback; - const isDisabled = tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; - return { - value: tag.name, - text: tag.name, - keyForList: tag.name, - isSelected: !!selectedTags[tag.name], - pendingAction: tag.pendingAction, - errors: tag.errors ?? undefined, - enabled: tag.enabled, - isDisabled, - rightElement: ( - - - {tag.enabled ? translate('workspace.common.enabled') : translate('workspace.common.disabled')} - - - + lodashSortBy(Object.values(policyTagList.tags || []).filter((value) => PolicyUtils.getCleanedTagName(value.name) === value.name), 'name', localeCompare) + .map((value) => { + const tag = value as OnyxCommon.OnyxValueWithOfflineFeedback; + const isDisabled = tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; + return { + value: tag.name, + text: tag.name, + keyForList: tag.name, + isSelected: !!selectedTags[tag.name], + pendingAction: tag.pendingAction, + errors: tag.errors ?? undefined, + enabled: tag.enabled, + isDisabled, + rightElement: ( + + + {tag.enabled ? translate('workspace.common.enabled') : translate('workspace.common.disabled')} + + + + - - ), - }; - }), + ), + }; + }), ) .flat(), [policyTagLists, selectedTags, styles.alignSelfCenter, styles.flexRow, styles.label, styles.p1, styles.pl2, styles.textSupporting, theme.icon, translate], From 8d56fad4abd4b4f0514467b3e17dce0649a8e740 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Fri, 29 Mar 2024 08:27:10 +0100 Subject: [PATCH 12/33] prettier... --- .../workspace/tags/WorkspaceTagsPage.tsx | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index a3dd72389dde..97ad17e47a48 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -84,34 +84,37 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { () => policyTagLists .map((policyTagList) => - lodashSortBy(Object.values(policyTagList.tags || []).filter((value) => PolicyUtils.getCleanedTagName(value.name) === value.name), 'name', localeCompare) - .map((value) => { - const tag = value as OnyxCommon.OnyxValueWithOfflineFeedback; - const isDisabled = tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; - return { - value: tag.name, - text: tag.name, - keyForList: tag.name, - isSelected: !!selectedTags[tag.name], - pendingAction: tag.pendingAction, - errors: tag.errors ?? undefined, - enabled: tag.enabled, - isDisabled, - rightElement: ( - - - {tag.enabled ? translate('workspace.common.enabled') : translate('workspace.common.disabled')} - - - - + lodashSortBy( + Object.values(policyTagList.tags || []).filter((value) => PolicyUtils.getCleanedTagName(value.name) === value.name), + 'name', + localeCompare, + ).map((value) => { + const tag = value as OnyxCommon.OnyxValueWithOfflineFeedback; + const isDisabled = tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; + return { + value: tag.name, + text: tag.name, + keyForList: tag.name, + isSelected: !!selectedTags[tag.name], + pendingAction: tag.pendingAction, + errors: tag.errors ?? undefined, + enabled: tag.enabled, + isDisabled, + rightElement: ( + + + {tag.enabled ? translate('workspace.common.enabled') : translate('workspace.common.disabled')} + + + - ), - }; - }), + + ), + }; + }), ) .flat(), [policyTagLists, selectedTags, styles.alignSelfCenter, styles.flexRow, styles.label, styles.p1, styles.pl2, styles.textSupporting, theme.icon, translate], From 821c0cc4e6bf5f231dac4967e7ee34e21b9f6497 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Fri, 5 Apr 2024 00:47:04 +0200 Subject: [PATCH 13/33] Showing only the first tags policyTagList --- src/pages/workspace/tags/WorkspaceTagsPage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index d158673b7ae3..5594935a378a 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -81,13 +81,13 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { fetchTags(); }, [fetchTags]), ); - const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags), [policyTags]); + const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags).slice(0, 1), [policyTags]); const tagList = useMemo( () => policyTagLists .map((policyTagList) => lodashSortBy( - Object.values(policyTagList.tags || []).filter((value) => PolicyUtils.getCleanedTagName(value.name) === value.name), + policyTagList?.tags ? Object.values(policyTagList.tags) : [], 'name', localeCompare, ).map((value) => { From 07df0acc76e18eb3cd1b64aae5debde59c95caf5 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Fri, 5 Apr 2024 01:19:42 +0200 Subject: [PATCH 14/33] prettier --- src/pages/workspace/tags/WorkspaceTagsPage.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index 5594935a378a..db003df6e5b1 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -86,11 +86,7 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { () => policyTagLists .map((policyTagList) => - lodashSortBy( - policyTagList?.tags ? Object.values(policyTagList.tags) : [], - 'name', - localeCompare, - ).map((value) => { + lodashSortBy(policyTagList?.tags ? Object.values(policyTagList.tags) : [], 'name', localeCompare).map((value) => { const tag = value as OnyxCommon.OnyxValueWithOfflineFeedback; const isDisabled = tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; return { From 993b1ed29a8d3221424a2d20e1d531a9153ff18b Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Fri, 5 Apr 2024 20:15:35 +0200 Subject: [PATCH 15/33] Cleaning tag names --- src/pages/workspace/tags/WorkspaceTagsPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index db003df6e5b1..305e0d99b65a 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -91,7 +91,7 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { const isDisabled = tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; return { value: tag.name, - text: tag.name, + text: PolicyUtils.getCleanedTagName(tag.name), keyForList: tag.name, isSelected: !!selectedTags[tag.name], pendingAction: tag.pendingAction, From e1e663005a35ebf533b92a8b75bae5d9dc968f29 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Sat, 6 Apr 2024 22:15:18 +0300 Subject: [PATCH 16/33] Update src/pages/workspace/tags/WorkspaceTagsPage.tsx Co-authored-by: Vinh Hoang --- src/pages/workspace/tags/WorkspaceTagsPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index 789d1b02d53f..05a5daa4297d 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -82,7 +82,7 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { fetchTags(); }, [fetchTags]), ); - const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags).slice(0, 1), [policyTags]); + const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags)[0], [policyTags]); const tagList = useMemo( () => policyTagLists From 3bccbe80c890f7e2e8ca93823ee7b93f7f17bf58 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Sun, 7 Apr 2024 00:36:13 +0200 Subject: [PATCH 17/33] Refactoring Hello... --- .../workspace/tags/WorkspaceTagsPage.tsx | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index 05a5daa4297d..030eff519880 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -25,7 +25,6 @@ import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import * as DeviceCapabilities from '@libs/DeviceCapabilities'; -import localeCompare from '@libs/LocaleCompare'; import Navigation from '@libs/Navigation/Navigation'; import * as PolicyUtils from '@libs/PolicyUtils'; import type {WorkspacesCentralPaneNavigatorParamList} from '@navigation/types'; @@ -82,29 +81,25 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { fetchTags(); }, [fetchTags]), ); - const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags)[0], [policyTags]); + // We currently don't support multi level tags, so let's only get the first level tags. + const policyTagList = useMemo(() => PolicyUtils.getTagLists(policyTags)[0], [policyTags]); const tagList = useMemo( - () => - policyTagLists - .map((policyTagList) => - lodashSortBy(policyTagList?.tags ? Object.values(policyTagList.tags) : [], 'name', localeCompare).map((value) => { - const tag = value as OnyxCommon.OnyxValueWithOfflineFeedback; - const isDisabled = tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; - return { - value: tag.name, - text: PolicyUtils.getCleanedTagName(tag.name), - keyForList: tag.name, - isSelected: !!selectedTags[tag.name], - pendingAction: tag.pendingAction, - errors: tag.errors ?? undefined, - enabled: tag.enabled, - isDisabled, - rightElement: , - }; - }), - ) - .flat(), - [policyTagLists, selectedTags], + () => lodashSortBy(policyTagList.tags).map((value) => { + const tag = value as OnyxCommon.OnyxValueWithOfflineFeedback; + const isDisabled = tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; + return { + value: tag.name, + text: PolicyUtils.getCleanedTagName(tag.name), + keyForList: tag.name, + isSelected: !!selectedTags[tag.name], + pendingAction: tag.pendingAction, + errors: tag.errors ?? undefined, + enabled: tag.enabled, + isDisabled, + rightElement: , + }; + }), + [policyTagList.tags, selectedTags], ); const tagListKeyedByName = tagList.reduce>((acc, tag) => { From 8cd8d170358cf25f0e03580a5a0f6b892e634f84 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Sun, 7 Apr 2024 01:44:50 +0200 Subject: [PATCH 18/33] Prettier.. --- .../workspace/tags/WorkspaceTagsPage.tsx | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index 030eff519880..aa718f09b466 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -84,21 +84,22 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { // We currently don't support multi level tags, so let's only get the first level tags. const policyTagList = useMemo(() => PolicyUtils.getTagLists(policyTags)[0], [policyTags]); const tagList = useMemo( - () => lodashSortBy(policyTagList.tags).map((value) => { - const tag = value as OnyxCommon.OnyxValueWithOfflineFeedback; - const isDisabled = tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; - return { - value: tag.name, - text: PolicyUtils.getCleanedTagName(tag.name), - keyForList: tag.name, - isSelected: !!selectedTags[tag.name], - pendingAction: tag.pendingAction, - errors: tag.errors ?? undefined, - enabled: tag.enabled, - isDisabled, - rightElement: , - }; - }), + () => + lodashSortBy(policyTagList.tags).map((value) => { + const tag = value as OnyxCommon.OnyxValueWithOfflineFeedback; + const isDisabled = tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; + return { + value: tag.name, + text: PolicyUtils.getCleanedTagName(tag.name), + keyForList: tag.name, + isSelected: !!selectedTags[tag.name], + pendingAction: tag.pendingAction, + errors: tag.errors ?? undefined, + enabled: tag.enabled, + isDisabled, + rightElement: , + }; + }), [policyTagList.tags, selectedTags], ); From 07d2cbd4bd7b5bd582db030bb0bc4427f936e94b Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Tue, 9 Apr 2024 00:07:36 +0200 Subject: [PATCH 19/33] reverted sort logic.. --- src/pages/workspace/tags/WorkspaceTagsPage.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index aa718f09b466..1f240af5336e 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -39,6 +39,7 @@ import type SCREENS from '@src/SCREENS'; import type * as OnyxTypes from '@src/types/onyx'; import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; import type DeepValueOf from '@src/types/utils/DeepValueOf'; +import localeCompare from '@libs/LocaleCompare'; type PolicyForList = { value: string; @@ -85,7 +86,7 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { const policyTagList = useMemo(() => PolicyUtils.getTagLists(policyTags)[0], [policyTags]); const tagList = useMemo( () => - lodashSortBy(policyTagList.tags).map((value) => { + lodashSortBy(Object.values(policyTagList.tags || []), 'name', localeCompare).map((value) => { const tag = value as OnyxCommon.OnyxValueWithOfflineFeedback; const isDisabled = tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; return { From 80c9fa99af85d0d0f871e340001484085f52e819 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Tue, 9 Apr 2024 04:44:14 +0200 Subject: [PATCH 20/33] cleaning tag name ... --- src/pages/workspace/tags/WorkspaceEditTagsPage.tsx | 2 +- src/pages/workspace/tags/WorkspaceTagsPage.tsx | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx b/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx index 0072d37ef631..bb7f2e3eba91 100644 --- a/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx @@ -81,7 +81,7 @@ function WorkspaceEditTagsPage({route, policyTags}: WorkspaceEditTagsPageProps) inputID={INPUT_IDS.POLICY_TAGS_NAME} label={translate(`workspace.tags.customTagName`)} accessibilityLabel={translate(`workspace.tags.customTagName`)} - defaultValue={taglistName} + defaultValue={PolicyUtils.getCleanedTagName(taglistName)} role={CONST.ROLE.PRESENTATION} ref={inputCallbackRef} /> diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index 1f240af5336e..442c98ba2326 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -83,10 +83,10 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { }, [fetchTags]), ); // We currently don't support multi level tags, so let's only get the first level tags. - const policyTagList = useMemo(() => PolicyUtils.getTagLists(policyTags)[0], [policyTags]); + const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags)[0], [policyTags]); const tagList = useMemo( () => - lodashSortBy(Object.values(policyTagList.tags || []), 'name', localeCompare).map((value) => { + lodashSortBy(Object.values(policyTagLists.tags || []), 'name', localeCompare).map((value) => { const tag = value as OnyxCommon.OnyxValueWithOfflineFeedback; const isDisabled = tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; return { @@ -101,7 +101,7 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { rightElement: , }; }), - [policyTagList.tags, selectedTags], + [policyTagLists, selectedTags], ); const tagListKeyedByName = tagList.reduce>((acc, tag) => { From a75b0d50707b7c3c2a323214abb4b8c9c4b7e344 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Tue, 9 Apr 2024 05:14:20 +0200 Subject: [PATCH 21/33] Cleaning tag names --- src/pages/workspace/tags/TagSettingsPage.tsx | 4 ++-- src/pages/workspace/tags/WorkspaceEditTagsPage.tsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/workspace/tags/TagSettingsPage.tsx b/src/pages/workspace/tags/TagSettingsPage.tsx index 107689bc46b9..b68a67675201 100644 --- a/src/pages/workspace/tags/TagSettingsPage.tsx +++ b/src/pages/workspace/tags/TagSettingsPage.tsx @@ -79,7 +79,7 @@ function TagSettingsPage({route, policyTags}: TagSettingsPageProps) { testID={TagSettingsPage.displayName} > PolicyUtils.getTagLists(policyTags)[0].name, [policyTags]); + const taglistName = useMemo(() => PolicyUtils.getCleanedTagName(PolicyUtils.getTagLists(policyTags)[0].name), [policyTags]); const {inputCallbackRef} = useAutoFocusInput(); const updateTaglistName = useCallback( @@ -81,7 +81,7 @@ function WorkspaceEditTagsPage({route, policyTags}: WorkspaceEditTagsPageProps) inputID={INPUT_IDS.POLICY_TAGS_NAME} label={translate(`workspace.tags.customTagName`)} accessibilityLabel={translate(`workspace.tags.customTagName`)} - defaultValue={PolicyUtils.getCleanedTagName(taglistName)} + defaultValue={taglistName} role={CONST.ROLE.PRESENTATION} ref={inputCallbackRef} /> From 9bcd1c420c18e95da4608f80a003c19b5706ba88 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Tue, 9 Apr 2024 05:20:30 +0200 Subject: [PATCH 22/33] revert and prettier.. --- src/pages/workspace/tags/WorkspaceEditTagsPage.tsx | 2 +- src/pages/workspace/tags/WorkspaceTagsPage.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx b/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx index a20dc0dd2fd1..0072d37ef631 100644 --- a/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx @@ -43,7 +43,7 @@ const validateTagName = (values: FormOnyxValues PolicyUtils.getCleanedTagName(PolicyUtils.getTagLists(policyTags)[0].name), [policyTags]); + const taglistName = useMemo(() => PolicyUtils.getTagLists(policyTags)[0].name, [policyTags]); const {inputCallbackRef} = useAutoFocusInput(); const updateTaglistName = useCallback( diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index 442c98ba2326..1563c3e63eeb 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -25,6 +25,7 @@ import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import * as DeviceCapabilities from '@libs/DeviceCapabilities'; +import localeCompare from '@libs/LocaleCompare'; import Navigation from '@libs/Navigation/Navigation'; import * as PolicyUtils from '@libs/PolicyUtils'; import type {WorkspacesCentralPaneNavigatorParamList} from '@navigation/types'; @@ -39,7 +40,6 @@ import type SCREENS from '@src/SCREENS'; import type * as OnyxTypes from '@src/types/onyx'; import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; import type DeepValueOf from '@src/types/utils/DeepValueOf'; -import localeCompare from '@libs/LocaleCompare'; type PolicyForList = { value: string; From 019b2f796dba4c7eb3777140fcffb11f48ecaa98 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Wed, 10 Apr 2024 00:43:36 +0200 Subject: [PATCH 23/33] WorkspaceTagsPage... --- .../workspace/tags/WorkspaceTagsPage.tsx | 171 +++++++++--------- 1 file changed, 88 insertions(+), 83 deletions(-) diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index 1563c3e63eeb..b6601490cb8a 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -52,106 +52,111 @@ type PolicyForList = { type PolicyOption = ListItem & { /** Tag name is used as a key for the selectedTags state */ - keyForList: string; -}; + keyForList: string; + }; -type WorkspaceTagsOnyxProps = { - /** Collection of tags attached to a policy */ - policyTags: OnyxEntry; -}; + type WorkspaceTagsOnyxProps = { + /** Collection of tags attached to a policy */ + policyTags: OnyxEntry; + }; -type WorkspaceTagsPageProps = WorkspaceTagsOnyxProps & StackScreenProps; + type WorkspaceTagsPageProps = WorkspaceTagsOnyxProps & StackScreenProps; -function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { - const {isSmallScreenWidth} = useWindowDimensions(); - const styles = useThemeStyles(); - const theme = useTheme(); - const {translate} = useLocalize(); - const [selectedTags, setSelectedTags] = useState>({}); - const dropdownButtonRef = useRef(null); - const [deleteTagsConfirmModalVisible, setDeleteTagsConfirmModalVisible] = useState(false); + function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { + const {isSmallScreenWidth} = useWindowDimensions(); + const styles = useThemeStyles(); + const theme = useTheme(); + const {translate} = useLocalize(); + const [selectedTags, setSelectedTags] = useState>({}); + const dropdownButtonRef = useRef(null); + const [deleteTagsConfirmModalVisible, setDeleteTagsConfirmModalVisible] = useState(false); - const fetchTags = useCallback(() => { - Policy.openPolicyTagsPage(route.params.policyID); - }, [route.params.policyID]); + const fetchTags = useCallback(() => { + Policy.openPolicyTagsPage(route.params.policyID); + }, [route.params.policyID]); - const {isOffline} = useNetwork({onReconnect: fetchTags}); + const {isOffline} = useNetwork({onReconnect: fetchTags}); - useFocusEffect( - useCallback(() => { - fetchTags(); - }, [fetchTags]), - ); - // We currently don't support multi level tags, so let's only get the first level tags. - const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags)[0], [policyTags]); - const tagList = useMemo( - () => - lodashSortBy(Object.values(policyTagLists.tags || []), 'name', localeCompare).map((value) => { - const tag = value as OnyxCommon.OnyxValueWithOfflineFeedback; - const isDisabled = tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; - return { - value: tag.name, - text: PolicyUtils.getCleanedTagName(tag.name), - keyForList: tag.name, - isSelected: !!selectedTags[tag.name], - pendingAction: tag.pendingAction, - errors: tag.errors ?? undefined, - enabled: tag.enabled, - isDisabled, - rightElement: , - }; - }), - [policyTagLists, selectedTags], - ); + useFocusEffect( + useCallback(() => { + fetchTags(); + }, [fetchTags]), + ); + + // We currently don't support multi level tags, so let's only get the first level tags. + const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags), [policyTags]); + const tagList = useMemo( + () => + policyTagLists + .map((policyTagList) => + lodashSortBy(Object.values(policyTagList.tags || []), 'name', localeCompare).map((value) => { + const tag = value as OnyxCommon.OnyxValueWithOfflineFeedback; + const isDisabled = tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; + return { + value: tag.name, + text: tag.name, + keyForList: tag.name, + isSelected: !!selectedTags[tag.name], + pendingAction: tag.pendingAction, + errors: tag.errors ?? undefined, + enabled: tag.enabled, + isDisabled, + rightElement: , + }; + }), + ) + .flat(), + [policyTagLists, selectedTags], + ); - const tagListKeyedByName = tagList.reduce>((acc, tag) => { - acc[tag.value] = tag; - return acc; - }, {}); + const tagListKeyedByName = tagList.reduce>((acc, tag) => { + acc[tag.value] = tag; + return acc; + }, {}); - const toggleTag = (tag: PolicyForList) => { - setSelectedTags((prev) => ({ - ...prev, - [tag.value]: !prev[tag.value], - })); - }; + const toggleTag = (tag: PolicyForList) => { + setSelectedTags((prev) => ({ + ...prev, + [tag.value]: !prev[tag.value], + })); + }; - const toggleAllTags = () => { - const isAllSelected = tagList.every((tag) => !!selectedTags[tag.value]); - setSelectedTags(isAllSelected ? {} : Object.fromEntries(tagList.map((item) => [item.value, true]))); - }; + const toggleAllTags = () => { + const isAllSelected = tagList.every((tag) => !!selectedTags[tag.value]); + setSelectedTags(isAllSelected ? {} : Object.fromEntries(tagList.map((item) => [item.value, true]))); + }; - const getCustomListHeader = () => ( - - {translate('common.name')} - {translate('statusPage.status')} - - ); + const getCustomListHeader = () => ( + + {translate('common.name')} + {translate('statusPage.status')} + + ); - const navigateToTagsSettings = () => { - Navigation.navigate(ROUTES.WORKSPACE_TAGS_SETTINGS.getRoute(route.params.policyID)); - }; + const navigateToTagsSettings = () => { + Navigation.navigate(ROUTES.WORKSPACE_TAGS_SETTINGS.getRoute(route.params.policyID)); + }; - const navigateToCreateTagPage = () => { - Navigation.navigate(ROUTES.WORKSPACE_TAG_CREATE.getRoute(route.params.policyID)); - }; + const navigateToCreateTagPage = () => { + Navigation.navigate(ROUTES.WORKSPACE_TAG_CREATE.getRoute(route.params.policyID)); + }; - const navigateToTagSettings = (tag: PolicyOption) => { - setSelectedTags({}); - Navigation.navigate(ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(route.params.policyID, tag.keyForList)); - }; + const navigateToTagSettings = (tag: PolicyOption) => { + setSelectedTags({}); + Navigation.navigate(ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(route.params.policyID, tag.keyForList)); + }; - const selectedTagsArray = Object.keys(selectedTags).filter((key) => selectedTags[key]); + const selectedTagsArray = Object.keys(selectedTags).filter((key) => selectedTags[key]); - const handleDeleteTags = () => { - setSelectedTags({}); - Policy.deletePolicyTags(route.params.policyID, selectedTagsArray); - setDeleteTagsConfirmModalVisible(false); - }; + const handleDeleteTags = () => { + setSelectedTags({}); + Policy.deletePolicyTags(route.params.policyID, selectedTagsArray); + setDeleteTagsConfirmModalVisible(false); + }; - const isLoading = !isOffline && policyTags === undefined; + const isLoading = !isOffline && policyTags === undefined; - const getHeaderButtons = () => { + const getHeaderButtons = () => { const options: Array>> = []; if (selectedTagsArray.length > 0) { From 879064dbb2fb50c4b7e5637364b57c782c24df90 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Wed, 10 Apr 2024 00:51:10 +0200 Subject: [PATCH 24/33] prettier and reverted... --- src/pages/workspace/tags/TagSettingsPage.tsx | 2 +- .../workspace/tags/WorkspaceTagsPage.tsx | 176 +++++++++--------- 2 files changed, 89 insertions(+), 89 deletions(-) diff --git a/src/pages/workspace/tags/TagSettingsPage.tsx b/src/pages/workspace/tags/TagSettingsPage.tsx index b68a67675201..b09552f412e7 100644 --- a/src/pages/workspace/tags/TagSettingsPage.tsx +++ b/src/pages/workspace/tags/TagSettingsPage.tsx @@ -79,7 +79,7 @@ function TagSettingsPage({route, policyTags}: TagSettingsPageProps) { testID={TagSettingsPage.displayName} > ; - }; +type WorkspaceTagsOnyxProps = { + /** Collection of tags attached to a policy */ + policyTags: OnyxEntry; +}; - type WorkspaceTagsPageProps = WorkspaceTagsOnyxProps & StackScreenProps; +type WorkspaceTagsPageProps = WorkspaceTagsOnyxProps & StackScreenProps; - function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { - const {isSmallScreenWidth} = useWindowDimensions(); - const styles = useThemeStyles(); - const theme = useTheme(); - const {translate} = useLocalize(); - const [selectedTags, setSelectedTags] = useState>({}); - const dropdownButtonRef = useRef(null); - const [deleteTagsConfirmModalVisible, setDeleteTagsConfirmModalVisible] = useState(false); +function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { + const {isSmallScreenWidth} = useWindowDimensions(); + const styles = useThemeStyles(); + const theme = useTheme(); + const {translate} = useLocalize(); + const [selectedTags, setSelectedTags] = useState>({}); + const dropdownButtonRef = useRef(null); + const [deleteTagsConfirmModalVisible, setDeleteTagsConfirmModalVisible] = useState(false); - const fetchTags = useCallback(() => { - Policy.openPolicyTagsPage(route.params.policyID); - }, [route.params.policyID]); + const fetchTags = useCallback(() => { + Policy.openPolicyTagsPage(route.params.policyID); + }, [route.params.policyID]); - const {isOffline} = useNetwork({onReconnect: fetchTags}); + const {isOffline} = useNetwork({onReconnect: fetchTags}); - useFocusEffect( - useCallback(() => { - fetchTags(); - }, [fetchTags]), - ); - - // We currently don't support multi level tags, so let's only get the first level tags. - const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags), [policyTags]); - const tagList = useMemo( - () => - policyTagLists - .map((policyTagList) => - lodashSortBy(Object.values(policyTagList.tags || []), 'name', localeCompare).map((value) => { - const tag = value as OnyxCommon.OnyxValueWithOfflineFeedback; - const isDisabled = tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; - return { - value: tag.name, - text: tag.name, - keyForList: tag.name, - isSelected: !!selectedTags[tag.name], - pendingAction: tag.pendingAction, - errors: tag.errors ?? undefined, - enabled: tag.enabled, - isDisabled, - rightElement: , - }; - }), - ) - .flat(), - [policyTagLists, selectedTags], - ); + useFocusEffect( + useCallback(() => { + fetchTags(); + }, [fetchTags]), + ); + + // We currently don't support multi level tags, so let's only get the first level tags. + const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags), [policyTags]); + const tagList = useMemo( + () => + policyTagLists + .map((policyTagList) => + lodashSortBy(Object.values(policyTagList.tags || []), 'name', localeCompare).map((value) => { + const tag = value as OnyxCommon.OnyxValueWithOfflineFeedback; + const isDisabled = tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; + return { + value: tag.name, + text: tag.name, + keyForList: tag.name, + isSelected: !!selectedTags[tag.name], + pendingAction: tag.pendingAction, + errors: tag.errors ?? undefined, + enabled: tag.enabled, + isDisabled, + rightElement: , + }; + }), + ) + .flat(), + [policyTagLists, selectedTags], + ); - const tagListKeyedByName = tagList.reduce>((acc, tag) => { - acc[tag.value] = tag; - return acc; - }, {}); + const tagListKeyedByName = tagList.reduce>((acc, tag) => { + acc[tag.value] = tag; + return acc; + }, {}); - const toggleTag = (tag: PolicyForList) => { - setSelectedTags((prev) => ({ - ...prev, - [tag.value]: !prev[tag.value], - })); - }; + const toggleTag = (tag: PolicyForList) => { + setSelectedTags((prev) => ({ + ...prev, + [tag.value]: !prev[tag.value], + })); + }; - const toggleAllTags = () => { - const isAllSelected = tagList.every((tag) => !!selectedTags[tag.value]); - setSelectedTags(isAllSelected ? {} : Object.fromEntries(tagList.map((item) => [item.value, true]))); - }; + const toggleAllTags = () => { + const isAllSelected = tagList.every((tag) => !!selectedTags[tag.value]); + setSelectedTags(isAllSelected ? {} : Object.fromEntries(tagList.map((item) => [item.value, true]))); + }; - const getCustomListHeader = () => ( - - {translate('common.name')} - {translate('statusPage.status')} - - ); + const getCustomListHeader = () => ( + + {translate('common.name')} + {translate('statusPage.status')} + + ); - const navigateToTagsSettings = () => { - Navigation.navigate(ROUTES.WORKSPACE_TAGS_SETTINGS.getRoute(route.params.policyID)); - }; + const navigateToTagsSettings = () => { + Navigation.navigate(ROUTES.WORKSPACE_TAGS_SETTINGS.getRoute(route.params.policyID)); + }; - const navigateToCreateTagPage = () => { - Navigation.navigate(ROUTES.WORKSPACE_TAG_CREATE.getRoute(route.params.policyID)); - }; + const navigateToCreateTagPage = () => { + Navigation.navigate(ROUTES.WORKSPACE_TAG_CREATE.getRoute(route.params.policyID)); + }; - const navigateToTagSettings = (tag: PolicyOption) => { - setSelectedTags({}); - Navigation.navigate(ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(route.params.policyID, tag.keyForList)); - }; + const navigateToTagSettings = (tag: PolicyOption) => { + setSelectedTags({}); + Navigation.navigate(ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(route.params.policyID, tag.keyForList)); + }; - const selectedTagsArray = Object.keys(selectedTags).filter((key) => selectedTags[key]); + const selectedTagsArray = Object.keys(selectedTags).filter((key) => selectedTags[key]); - const handleDeleteTags = () => { - setSelectedTags({}); - Policy.deletePolicyTags(route.params.policyID, selectedTagsArray); - setDeleteTagsConfirmModalVisible(false); - }; + const handleDeleteTags = () => { + setSelectedTags({}); + Policy.deletePolicyTags(route.params.policyID, selectedTagsArray); + setDeleteTagsConfirmModalVisible(false); + }; - const isLoading = !isOffline && policyTags === undefined; + const isLoading = !isOffline && policyTags === undefined; - const getHeaderButtons = () => { + const getHeaderButtons = () => { const options: Array>> = []; if (selectedTagsArray.length > 0) { From 401f5bf73f1503a8f0b94a44dc9561cd92f05fcf Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Wed, 10 Apr 2024 01:46:30 +0200 Subject: [PATCH 25/33] Slicing the policyTagLists to get the first policy tag --- src/pages/workspace/tags/WorkspaceTagsPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index 5e0bec54f3cf..94aa28f644bb 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -84,7 +84,7 @@ function WorkspaceTagsPage({policyTags, route}: WorkspaceTagsPageProps) { ); // We currently don't support multi level tags, so let's only get the first level tags. - const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags), [policyTags]); + const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags).slice(0, 1), [policyTags]); const tagList = useMemo( () => policyTagLists From b638a4e00a5fab47dfde71bb4880370b368c8a23 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Wed, 10 Apr 2024 03:11:12 +0200 Subject: [PATCH 26/33] cleaning tags --- src/pages/workspace/tags/TagSettingsPage.tsx | 4 ++-- src/pages/workspace/tags/WorkspaceTagsPage.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/workspace/tags/TagSettingsPage.tsx b/src/pages/workspace/tags/TagSettingsPage.tsx index a643797eac1e..3e0b8eae30ee 100644 --- a/src/pages/workspace/tags/TagSettingsPage.tsx +++ b/src/pages/workspace/tags/TagSettingsPage.tsx @@ -79,7 +79,7 @@ function TagSettingsPage({route, policyTags}: TagSettingsPageProps) { testID={TagSettingsPage.displayName} > Date: Wed, 10 Apr 2024 04:37:02 +0200 Subject: [PATCH 27/33] Refactoring... --- src/pages/workspace/tags/WorkspaceEditTagsPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx b/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx index 0072d37ef631..bb7f2e3eba91 100644 --- a/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx @@ -81,7 +81,7 @@ function WorkspaceEditTagsPage({route, policyTags}: WorkspaceEditTagsPageProps) inputID={INPUT_IDS.POLICY_TAGS_NAME} label={translate(`workspace.tags.customTagName`)} accessibilityLabel={translate(`workspace.tags.customTagName`)} - defaultValue={taglistName} + defaultValue={PolicyUtils.getCleanedTagName(taglistName)} role={CONST.ROLE.PRESENTATION} ref={inputCallbackRef} /> From e00c83c344c0072cb3801c6557a395dca62942d6 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Thu, 11 Apr 2024 22:47:53 +0200 Subject: [PATCH 28/33] Cleaning TagName WorkspaceEditTagsPage --- src/pages/workspace/tags/EditTagPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/tags/EditTagPage.tsx b/src/pages/workspace/tags/EditTagPage.tsx index fbde96eb2b91..ed55155a3dcf 100644 --- a/src/pages/workspace/tags/EditTagPage.tsx +++ b/src/pages/workspace/tags/EditTagPage.tsx @@ -96,7 +96,7 @@ function EditTagPage({route, policyTags}: EditTagPageProps) { Date: Fri, 12 Apr 2024 23:36:35 +0200 Subject: [PATCH 29/33] fixing small bug for taglistName --- config/webpack/webpack.dev.ts | 4 ++-- src/pages/workspace/tags/WorkspaceEditTagsPage.tsx | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/config/webpack/webpack.dev.ts b/config/webpack/webpack.dev.ts index 8f32a2d95c99..e4b5aabf4ca6 100644 --- a/config/webpack/webpack.dev.ts +++ b/config/webpack/webpack.dev.ts @@ -49,9 +49,9 @@ const getConfiguration = (environment: Environment): Promise => ...proxySettings, historyApiFallback: true, port, - host: 'dev.new.expensify.com', + host: 'localhost', server: { - type: 'https', + type: 'http', options: { key: path.join(__dirname, 'key.pem'), cert: path.join(__dirname, 'certificate.pem'), diff --git a/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx b/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx index bb7f2e3eba91..b87f225d40f4 100644 --- a/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx @@ -48,7 +48,9 @@ function WorkspaceEditTagsPage({route, policyTags}: WorkspaceEditTagsPageProps) const updateTaglistName = useCallback( (values: FormOnyxValues) => { - Policy.renamePolicyTaglist(route.params.policyID, {oldName: taglistName, newName: values[INPUT_IDS.POLICY_TAGS_NAME]}, policyTags); + if (values[INPUT_IDS.POLICY_TAGS_NAME] !== taglistName) { + Policy.renamePolicyTaglist(route.params.policyID, {oldName: taglistName, newName: values[INPUT_IDS.POLICY_TAGS_NAME]}, policyTags); + } Navigation.goBack(); }, [policyTags, route.params.policyID, taglistName], From 8582e00e66d7a9b0ff6970288c2a6bbe64033203 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Sat, 13 Apr 2024 00:06:08 +0200 Subject: [PATCH 30/33] lint ... --- src/pages/workspace/tags/WorkspaceEditTagsPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx b/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx index b87f225d40f4..ffee71bd5011 100644 --- a/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx @@ -48,7 +48,7 @@ function WorkspaceEditTagsPage({route, policyTags}: WorkspaceEditTagsPageProps) const updateTaglistName = useCallback( (values: FormOnyxValues) => { - if (values[INPUT_IDS.POLICY_TAGS_NAME] !== taglistName) { + if (values[INPUT_IDS.POLICY_TAGS_NAME] !== taglistName) { Policy.renamePolicyTaglist(route.params.policyID, {oldName: taglistName, newName: values[INPUT_IDS.POLICY_TAGS_NAME]}, policyTags); } Navigation.goBack(); From 5fcac893f23fc02f5e1e717a4a3bb75cccde7467 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Sat, 13 Apr 2024 00:54:39 +0200 Subject: [PATCH 31/33] config/webpack/webpack.dev.ts --- config/webpack/webpack.dev.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/webpack/webpack.dev.ts b/config/webpack/webpack.dev.ts index e4b5aabf4ca6..8f32a2d95c99 100644 --- a/config/webpack/webpack.dev.ts +++ b/config/webpack/webpack.dev.ts @@ -49,9 +49,9 @@ const getConfiguration = (environment: Environment): Promise => ...proxySettings, historyApiFallback: true, port, - host: 'localhost', + host: 'dev.new.expensify.com', server: { - type: 'http', + type: 'https', options: { key: path.join(__dirname, 'key.pem'), cert: path.join(__dirname, 'certificate.pem'), From 8d082afac7702115368ed33604ce0a0619261f45 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Sat, 13 Apr 2024 01:02:55 +0200 Subject: [PATCH 32/33] Revert EditTagPage --- src/pages/workspace/tags/EditTagPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/tags/EditTagPage.tsx b/src/pages/workspace/tags/EditTagPage.tsx index ed55155a3dcf..fbde96eb2b91 100644 --- a/src/pages/workspace/tags/EditTagPage.tsx +++ b/src/pages/workspace/tags/EditTagPage.tsx @@ -96,7 +96,7 @@ function EditTagPage({route, policyTags}: EditTagPageProps) { Date: Tue, 16 Apr 2024 02:46:36 +0200 Subject: [PATCH 33/33] EditTagPage.tsx --- src/pages/workspace/tags/EditTagPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/tags/EditTagPage.tsx b/src/pages/workspace/tags/EditTagPage.tsx index fbde96eb2b91..d329d74dbca0 100644 --- a/src/pages/workspace/tags/EditTagPage.tsx +++ b/src/pages/workspace/tags/EditTagPage.tsx @@ -37,7 +37,7 @@ function EditTagPage({route, policyTags}: EditTagPageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); const {inputCallbackRef} = useAutoFocusInput(); - const currentTagName = route.params.tagName; + const currentTagName = PolicyUtils.getCleanedTagName(route.params.tagName); const validate = useCallback( (values: FormOnyxValues) => {