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

[OldDot Rules Migration] Tag rules #48325

Merged
merged 36 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
53828c7
Add WorkspaceMembersSelectionList
WojtekBoman Aug 28, 2024
374f298
add interface for tag edit
BrtqKr Aug 28, 2024
299856e
wire up the tags
BrtqKr Aug 29, 2024
4a3bfcc
wire up action
BrtqKr Aug 30, 2024
d64e7b6
Merge remote-tracking branch 'origin/main' into brtqkr/47016-tag-rules
BrtqKr Sep 9, 2024
10dbc8e
cleanup, modify action
BrtqKr Sep 9, 2024
e9dbc5c
change translations
BrtqKr Sep 9, 2024
99d973f
Merge remote-tracking branch 'origin/main' into brtqkr/47016-tag-rules
BrtqKr Sep 10, 2024
78df971
add remove approver option
BrtqKr Sep 10, 2024
7f792c8
disable when workflows are disabled
BrtqKr Sep 10, 2024
6163fe5
add approver conditon
BrtqKr Sep 10, 2024
bd3fdba
add approver conditon to category settings
BrtqKr Sep 10, 2024
21d8f3d
replace values with const
BrtqKr Sep 11, 2024
d7cb964
change conditon for find category approver
BrtqKr Sep 11, 2024
5c0b778
ts fix
BrtqKr Sep 11, 2024
804c601
use getCategoryApproverRule in the actions
BrtqKr Sep 12, 2024
c43913b
change offline pattern for tags
BrtqKr Sep 12, 2024
4770792
ts fix
BrtqKr Sep 12, 2024
e0e1d5b
make pending keys unique
BrtqKr Sep 12, 2024
57a13f2
review fixes
BrtqKr Sep 13, 2024
9fe0ff3
Merge remote-tracking branch 'origin/main' into brtqkr/47016-tag-rules
BrtqKr Sep 13, 2024
d7e902a
Merge remote-tracking branch 'origin/main' into brtqkr/47016-tag-rules
BrtqKr Sep 17, 2024
fe5f31c
update category rule when renaming category
BrtqKr Sep 17, 2024
bc4eed8
update tag rule when renaming tag
BrtqKr Sep 17, 2024
6fc0879
remove pending action pattern for rules
BrtqKr Sep 17, 2024
69d919a
Merge remote-tracking branch 'origin/main' into brtqkr/47016-tag-rules
BrtqKr Sep 17, 2024
08cf2a2
fix onyx check
BrtqKr Sep 18, 2024
b32ed64
remove pending pattern from type
BrtqKr Sep 18, 2024
71c8ef8
run prettier
BrtqKr Sep 18, 2024
669e692
cleanup
BrtqKr Sep 18, 2024
4fccbb1
cleanup
BrtqKr Sep 18, 2024
2fdea82
remove withOnyx
BrtqKr Sep 18, 2024
d91e3f3
Merge remote-tracking branch 'origin/main' into brtqkr/47016-tag-rules
BrtqKr Sep 18, 2024
4810e33
run prettier
BrtqKr Sep 18, 2024
2ba3191
cleanup
BrtqKr Sep 18, 2024
e06551c
rename connection
BrtqKr Sep 19, 2024
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
16 changes: 0 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2164,7 +2164,15 @@ const CONST = {
// Often referred to as "collect" workspaces
TEAM: 'team',
},
FIELD_LIST_TITLE_FIELD_ID: 'text_title',
RULE_CONDITIONS: {
MATCHES: 'matches',
},
FIELDS: {
TAG: 'tag',
CATEGORY: 'category',
FIELD_LIST_TITLE: 'text_title',
TAX: 'tax',
},
DEFAULT_REPORT_NAME_PATTERN: '{report:type} {report:startdate}',
ROLE: {
ADMIN: 'admin',
Expand Down
4 changes: 4 additions & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,10 @@ const ROUTES = {
route: 'settings/workspaces/:policyID/tag/:orderWeight/:tagName',
getRoute: (policyID: string, orderWeight: number, tagName: string) => `settings/workspaces/${policyID}/tag/${orderWeight}/${encodeURIComponent(tagName)}` as const,
},
WORKSPACE_TAG_APPROVER: {
route: 'settings/workspaces/:policyID/tag/:orderWeight/:tagName/approver',
getRoute: (policyID: string, orderWeight: number, tagName: string) => `settings/workspaces/${policyID}/tag/${orderWeight}/${tagName}/approver` as const,
},
WORKSPACE_TAG_LIST_VIEW: {
route: 'settings/workspaces/:policyID/tag-list/:orderWeight',
getRoute: (policyID: string, orderWeight: number) => `settings/workspaces/${policyID}/tag-list/${orderWeight}` as const,
Expand Down
1 change: 1 addition & 0 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ const SCREENS = {
TAX_CREATE: 'Workspace_Tax_Create',
TAG_CREATE: 'Tag_Create',
TAG_SETTINGS: 'Tag_Settings',
TAG_APPROVER: 'Tag_Approver',
TAG_LIST_VIEW: 'Tag_List_View',
TAG_GL_CODE: 'Tag_GL_Code',
CURRENCY: 'Workspace_Profile_Currency',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3182,6 +3182,8 @@ export default {
importedFromAccountingSoftware: 'The tags below are imported from your',
glCode: 'GL code',
updateGLCodeFailureMessage: 'An error occurred while updating the GL code, please try again.',
tagRules: 'Tag rules',
approverDescription: 'Approver',
importTags: 'Import tags',
importedTagsMessage: (columnCounts: number) =>
`We found *${columnCounts} columns* in your spreadsheet. Select *Name* next to the column that contains tags names. You can also select *Enabled* next to the column that sets tags status.`,
Expand Down
2 changes: 2 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3231,6 +3231,8 @@ export default {
importedFromAccountingSoftware: 'Etiquetas importadas desde',
glCode: 'Código de Libro Mayor',
updateGLCodeFailureMessage: 'Se produjo un error al actualizar el código de Libro Mayor. Por favor, inténtelo nuevamente.',
tagRules: 'Reglas de etiquetas',
approverDescription: 'Aprobador',
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB we could probably move this to the general since it is used twice.

importTags: 'Importar categorías',
importedTagsMessage: (columnCounts: number) =>
`Hemos encontrado *${columnCounts} columnas* en su hoja de cálculo. Seleccione *Nombre* junto a la columna que contiene los nombres de las etiquetas. También puede seleccionar *Habilitado* junto a la columna que establece el estado de la etiqueta.`,
Expand Down
7 changes: 7 additions & 0 deletions src/libs/API/parameters/SetPolicyTagApproverParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type SetPolicyTagApproverParams = {
policyID: string;
tagName: string;
approver: string | null;
};

export default SetPolicyTagApproverParams;
1 change: 1 addition & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export type {default as EnablePolicyCompanyCardsParams} from './EnablePolicyComp
export type {default as ToggleCardContinuousReconciliationParams} from './ToggleCardContinuousReconciliationParams';
export type {default as CardDeactivateParams} from './CardDeactivateParams';
export type {default as UpdateExpensifyCardLimitTypeParams} from './UpdateExpensifyCardLimitTypeParams';
export type {default as SetPolicyTagApproverParams} from './SetPolicyTagApproverParams';
export type {default as SaveSearchParams} from './SaveSearch';
export type {default as DeleteSavedSearchParams} from './DeleteSavedSearch';
export type {default as SetPolicyCategoryReceiptsRequiredParams} from './SetPolicyCategoryReceiptsRequiredParams';
Expand Down
2 changes: 2 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ const WRITE_COMMANDS = {
CREATE_ADMIN_ISSUED_VIRTUAL_CARD: 'CreateAdminIssuedVirtualCard',
ADD_DELEGATE: 'AddDelegate',
TOGGLE_CARD_CONTINUOUS_RECONCILIATION: 'ToggleCardContinuousReconciliation',
SET_POLICY_TAG_APPROVER: 'SetPolicyTagApprover',
SAVE_SEARCH: 'SaveSearch',
DELETE_SAVED_SEARCH: 'DeleteSavedSearch',
UPDATE_CARD_SETTLEMENT_FREQUENCY: 'UpdateCardSettlementFrequency',
Expand Down Expand Up @@ -634,6 +635,7 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.DECLINE_JOIN_REQUEST]: Parameters.DeclineJoinRequestParams;
[WRITE_COMMANDS.SET_POLICY_TAXES_CURRENCY_DEFAULT]: Parameters.SetPolicyCurrencyDefaultParams;
[WRITE_COMMANDS.SET_POLICY_CUSTOM_TAX_NAME]: Parameters.SetPolicyCustomTaxNameParams;
[WRITE_COMMANDS.SET_POLICY_TAG_APPROVER]: Parameters.SetPolicyTagApproverParams;
[WRITE_COMMANDS.SET_POLICY_TAXES_FOREIGN_CURRENCY_DEFAULT]: Parameters.SetPolicyForeignCurrencyDefaultParams;
[WRITE_COMMANDS.CREATE_POLICY_TAX]: Parameters.CreatePolicyTaxParams;
[WRITE_COMMANDS.SET_POLICY_TAXES_ENABLED]: Parameters.SetPolicyTaxesEnabledParams;
Expand Down
9 changes: 6 additions & 3 deletions src/libs/CategoryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ function formatRequireReceiptsOverText(translate: LocaleContextProps['translate'
);
}

function getCategoryApprover(approvalRules: ApprovalRule[], categoryName: string) {
return approvalRules?.find((rule) => rule.applyWhen.some((when) => when.value === categoryName))?.approver;
function getCategoryApproverRule(approvalRules: ApprovalRule[], categoryName: string) {
const approverRule = approvalRules?.find((rule) =>
rule.applyWhen.find(({condition, field, value}) => condition === CONST.POLICY.RULE_CONDITIONS.MATCHES && field === CONST.POLICY.FIELDS.CATEGORY && value === categoryName),
);
return approverRule;
}

function getCategoryDefaultTaxRate(expenseRules: ExpenseRule[], categoryName: string, defaultTaxRate?: string) {
Expand All @@ -59,4 +62,4 @@ function getCategoryDefaultTaxRate(expenseRules: ExpenseRule[], categoryName: st
return categoryDefaultTaxRate;
}

export {formatDefaultTaxRateText, formatRequireReceiptsOverText, getCategoryApprover, getCategoryDefaultTaxRate};
export {formatDefaultTaxRateText, formatRequireReceiptsOverText, getCategoryApproverRule, getCategoryDefaultTaxRate};
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ const SettingsModalStackNavigator = createModalStackNavigator<SettingsNavigatorP
[SCREENS.WORKSPACE.TAGS_EDIT]: () => require<ReactComponentModule>('../../../../pages/workspace/tags/WorkspaceEditTagsPage').default,
[SCREENS.WORKSPACE.TAG_CREATE]: () => require<ReactComponentModule>('../../../../pages/workspace/tags/WorkspaceCreateTagPage').default,
[SCREENS.WORKSPACE.TAG_EDIT]: () => require<ReactComponentModule>('../../../../pages/workspace/tags/EditTagPage').default,
[SCREENS.WORKSPACE.TAG_APPROVER]: () => require<ReactComponentModule>('../../../../pages/workspace/tags/TagApproverPage').default,
[SCREENS.WORKSPACE.TAG_GL_CODE]: () => require<ReactComponentModule>('../../../../pages/workspace/tags/TagGLCodePage').default,
[SCREENS.WORKSPACE.TAXES_SETTINGS]: () => require<ReactComponentModule>('../../../../pages/workspace/taxes/WorkspaceTaxesSettingsPage').default,
[SCREENS.WORKSPACE.TAXES_SETTINGS_CUSTOM_TAX_NAME]: () => require<ReactComponentModule>('../../../../pages/workspace/taxes/WorkspaceTaxesSettingsCustomTaxName').default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ const FULL_SCREEN_TO_RHP_MAPPING: Partial<Record<FullScreenName, string[]>> = {
SCREENS.WORKSPACE.TAG_EDIT,
SCREENS.WORKSPACE.TAG_LIST_VIEW,
SCREENS.WORKSPACE.TAG_GL_CODE,
SCREENS.WORKSPACE.TAG_APPROVER,
SCREENS.WORKSPACE.TAGS_IMPORT,
SCREENS.WORKSPACE.TAGS_IMPORTED,
],
Expand Down
7 changes: 7 additions & 0 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,13 @@ const config: LinkingOptions<RootStackParamList>['config'] = {
tagName: (tagName: string) => decodeURIComponent(tagName),
},
},
[SCREENS.WORKSPACE.TAG_APPROVER]: {
path: ROUTES.WORKSPACE_TAG_APPROVER.route,
parse: {
orderWeight: Number,
tagName: (tagName: string) => decodeURIComponent(tagName),
},
},
[SCREENS.WORKSPACE.TAG_GL_CODE]: {
path: ROUTES.WORKSPACE_TAG_GL_CODE.route,
parse: {
Expand Down
5 changes: 5 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ type SettingsNavigatorParamList = {
orderWeight: number;
tagName: string;
};
[SCREENS.WORKSPACE.TAG_APPROVER]: {
policyID: string;
orderWeight: number;
tagName: string;
};
[SCREENS.WORKSPACE.TAG_GL_CODE]: {
policyID: string;
orderWeight: number;
Expand Down
12 changes: 12 additions & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,17 @@ function getWorkspaceAccountID(policyID: string) {
return policy.workspaceAccountID ?? 0;
}

function getTagApproverRule(policyID: string, tagName: string) {
const policy = getPolicy(policyID);

const approvalRules = policy?.rules?.approvalRules ?? [];
const approverRule = approvalRules.find((rule) =>
rule.applyWhen.find(({condition, field, value}) => condition === CONST.POLICY.RULE_CONDITIONS.MATCHES && field === CONST.POLICY.FIELDS.TAG && value === tagName),
);

return approverRule;
}

function getDomainNameForPolicy(policyID?: string): string {
if (!policyID) {
return '';
Expand Down Expand Up @@ -1107,6 +1118,7 @@ export {
getWorkspaceAccountID,
getAllTaxRatesNamesAndKeys as getAllTaxRates,
getTagNamesFromTagsLists,
getTagApproverRule,
getDomainNameForPolicy,
hasUnsupportedIntegration,
getWorkflowApprovalsUnavailable,
Expand Down
25 changes: 25 additions & 0 deletions src/libs/ReportActionsConnection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type {OnyxCollection} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';
import type {ReportActions} from '@src/types/onyx/ReportAction';

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
if (!actions) {
return;
}

allReportActions = actions;
},
});

// This function is used to get all reports
function getAllReportActions() {
return allReportActions;
}

// eslint-disable-next-line import/prefer-default-export
export {getAllReportActions};
Loading
Loading