Skip to content
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
18 changes: 18 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2472,6 +2472,24 @@ const CONST = {
MAX_GROUPING_TIME: 300000,
MAX_SYSTEM_MESSAGE_COLLAPSE_TIME: 24 * 60 * 60 * 1000,
},
// Matches the backend's WORKFLOW_ACTIONS list
get WORKFLOW_ACTIONS() {
return [
this.ACTIONS.TYPE.SUBMITTED,
this.ACTIONS.TYPE.SUBMITTED_AND_CLOSED,
this.ACTIONS.TYPE.APPROVED,
this.ACTIONS.TYPE.UNAPPROVED,
this.ACTIONS.TYPE.REJECTED,
this.ACTIONS.TYPE.REJECTED_TO_SUBMITTER,
this.ACTIONS.TYPE.RETRACTED,
this.ACTIONS.TYPE.CLOSED,
this.ACTIONS.TYPE.REOPENED,
this.ACTIONS.TYPE.FORWARDED,
this.ACTIONS.TYPE.TAKE_CONTROL,
this.ACTIONS.TYPE.REROUTE,
this.ACTIONS.TYPE.REASSIGN_APPROVER,
] as const;
},
CANCEL_PAYMENT_REASONS: {
ADMIN: 'CANCEL_REASON_ADMIN',
USER: 'CANCEL_REASON_USER',
Expand Down
7 changes: 4 additions & 3 deletions src/hooks/useSearchAutoRefetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {SearchQueryJSON} from '@components/Search/types';
import {search} from '@libs/actions/Search';
import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute';
import TransitionTracker from '@libs/Navigation/TransitionTracker';
import {isApprovedAction, isForwardedAction, isSubmittedAction, isSubmittedAndClosedAction} from '@libs/ReportActionsUtils';
import type {SearchKey} from '@libs/SearchKeyUtils';
import {shouldRefetchSearchOnReportActionChange} from '@libs/SearchQueryUtils';
import {getValidGroupBy, isReportActionEntry} from '@libs/SearchUIUtils';
Expand Down Expand Up @@ -358,8 +357,10 @@ function hasChangedTransactionInSearchResults(
return changedTransactionIDs.some((transactionID) => searchResultIDs.has(transactionID));
}

const WORKFLOW_ACTION_TYPES = new Set<string>(CONST.REPORT.WORKFLOW_ACTIONS);

/**
* Whether a submitted, approved or forwarded report action was added, which changes the report's approver and its submitted or approved violations.
* Whether a workflow report action was added, which can change the report's approver, workflow dates and its submitted or approved violations.
*
* Onyx only replaces the report action maps it writes, so maps with an unchanged reference are skipped, and the walk stops at the first match.
*/
Expand All @@ -373,7 +374,7 @@ function hasAddedWorkflowReportAction(reportActions: OnyxCollection<ReportAction
if (previousActions?.[reportActionID]) {
continue;
}
if (isSubmittedAction(reportAction) || isSubmittedAndClosedAction(reportAction) || isApprovedAction(reportAction) || isForwardedAction(reportAction)) {
if (reportAction && WORKFLOW_ACTION_TYPES.has(reportAction.actionName)) {
return true;
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/libs/SearchQueryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ const WORKFLOW_FILTER_KEYS = new Set<SearchFilterKey>([
CONST.SEARCH.SYNTAX_FILTER_KEYS.SUBMITTED,
CONST.SEARCH.SYNTAX_FILTER_KEYS.APPROVED,
]);
const VIOLATION_HAS_VALUES = [CONST.SEARCH.HAS_VALUES.SUBMITTED_VIOLATION, CONST.SEARCH.HAS_VALUES.APPROVED_VIOLATION] as const;

function isFooterCount(value: string): value is SearchFooterCount {
return VALID_FOOTER_COUNTS.has(value);
Expand Down Expand Up @@ -875,7 +876,7 @@ function getQueryWithFooterSelection(
* search snapshots can still include FORWARDED actions with violation data.
*/
function queryHasViolationFilter(queryJSON: SearchQueryJSON | undefined): boolean {
return queryHasHasFilter(queryJSON, [CONST.SEARCH.HAS_VALUES.SUBMITTED_VIOLATION, CONST.SEARCH.HAS_VALUES.APPROVED_VIOLATION]);
return queryHasHasFilter(queryJSON, VIOLATION_HAS_VALUES);
}

/**
Expand Down Expand Up @@ -908,15 +909,15 @@ function shouldRefetchSearchOnReportActionChange(queryJSON: SearchQueryJSON): bo
return (
queryJSON.groupBy === CONST.SEARCH.GROUP_BY.APPROVER ||
queryJSON.flatFilters.some((filter) => WORKFLOW_FILTER_KEYS.has(filter.key)) ||
queryHasHasFilter(queryJSON, [CONST.SEARCH.HAS_VALUES.SUBMITTED_VIOLATION, CONST.SEARCH.HAS_VALUES.APPROVED_VIOLATION], true)
queryHasHasFilter(queryJSON, VIOLATION_HAS_VALUES, true)
);
}

/**
* Same meaning as queryHasViolationFilter, for the advanced-filters form `has` array rather than parsed query JSON.
*/
function hasValuesIncludeViolationFilter(hasValues: readonly string[] | undefined): boolean {
return !!hasValues?.includes(CONST.SEARCH.HAS_VALUES.SUBMITTED_VIOLATION) || !!hasValues?.includes(CONST.SEARCH.HAS_VALUES.APPROVED_VIOLATION);
return VIOLATION_HAS_VALUES.some((violationHasValue) => !!hasValues?.includes(violationHasValue));
}

/**
Expand Down
17 changes: 1 addition & 16 deletions src/libs/actions/IOU/Hold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,22 +699,7 @@ function getDuplicateActionsForPartialReport(

const sourceReportActions = getAllReportActions(sourceReportID);

// Match the backend's WORKFLOW_ACTIONS list
const workflowActionTypes = [
CONST.REPORT.ACTIONS.TYPE.SUBMITTED,
CONST.REPORT.ACTIONS.TYPE.SUBMITTED_AND_CLOSED,
CONST.REPORT.ACTIONS.TYPE.APPROVED,
CONST.REPORT.ACTIONS.TYPE.UNAPPROVED,
CONST.REPORT.ACTIONS.TYPE.REJECTED,
CONST.REPORT.ACTIONS.TYPE.REJECTED_TO_SUBMITTER,
CONST.REPORT.ACTIONS.TYPE.RETRACTED,
CONST.REPORT.ACTIONS.TYPE.CLOSED,
CONST.REPORT.ACTIONS.TYPE.REOPENED,
CONST.REPORT.ACTIONS.TYPE.FORWARDED,
CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL,
CONST.REPORT.ACTIONS.TYPE.REROUTE,
CONST.REPORT.ACTIONS.TYPE.REASSIGN_APPROVER,
] as const;
const workflowActionTypes = CONST.REPORT.WORKFLOW_ACTIONS;

const copiedActions: Record<string, OnyxTypes.ReportAction> = {};
const copiedActionsSuccess: OnyxCollection<NullishDeep<OnyxTypes.ReportAction>> = {};
Expand Down
17 changes: 6 additions & 11 deletions tests/unit/useSearchAutoRefetchTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,21 +715,16 @@ describe('useSearchAutoRefetch', () => {
},
});

it.each<ReportActionName>([
CONST.REPORT.ACTIONS.TYPE.SUBMITTED,
CONST.REPORT.ACTIONS.TYPE.SUBMITTED_AND_CLOSED,
CONST.REPORT.ACTIONS.TYPE.APPROVED,
CONST.REPORT.ACTIONS.TYPE.FORWARDED,
])('should trigger search when a %s report action is added while grouped by approver', (actionName) => {
it.each<ReportActionName>(CONST.REPORT.WORKFLOW_ACTIONS)('should trigger search when a %s report action is added while grouped by approver', (actionName) => {
// Given a search grouped by approver whose results already show a row
const {rerender} = renderHook((props: UseSearchAutoRefetch) => useSearchAutoRefetch(props), {
initialProps: approverProps,
});

// When a report is submitted, approved or forwarded, which adds a report action but changes no transaction
// When a workflow action such as an approval or an approver change is added, which changes no transaction
rerender(withAddedAction(approverProps, actionName));

// Then the search runs again, because the report's expenses move in or out of an approver group
// Then the search runs again, because the report's expenses can move in or out of an approver group
expect(search).toHaveBeenCalledTimes(1);
});

Expand Down Expand Up @@ -792,8 +787,8 @@ describe('useSearchAutoRefetch', () => {
expect(search).not.toHaveBeenCalled();
});

it('should not trigger search when an approval report action is added and the search is not grouped by approver', () => {
// Given a search that isn't grouped by approver
it("should not trigger search when an approval report action is added and the query doesn't depend on workflow state", () => {
// Given a search with no approver grouping and no approver, workflow date or violation filter
const ungroupedProps = createMock<UseSearchAutoRefetch>({...approverProps, queryJSON: baseProps.queryJSON});
const {rerender} = renderHook((props: UseSearchAutoRefetch) => useSearchAutoRefetch(props), {
initialProps: ungroupedProps,
Expand All @@ -802,7 +797,7 @@ describe('useSearchAutoRefetch', () => {
// When a report is approved
rerender(withAddedAction(ungroupedProps, 'APPROVED'));

// Then no search is triggered, because only the approver grouping depends on approval actions
// Then no search is triggered, because the query's results don't depend on the report's workflow state
expect(search).not.toHaveBeenCalled();
});
});
Expand Down
Loading