diff --git a/src/CONST/index.ts b/src/CONST/index.ts index 38f6af7e6a91..76c84eefb7eb 100644 --- a/src/CONST/index.ts +++ b/src/CONST/index.ts @@ -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', diff --git a/src/hooks/useSearchAutoRefetch.ts b/src/hooks/useSearchAutoRefetch.ts index 2a11aca534f5..f3554ce133f3 100644 --- a/src/hooks/useSearchAutoRefetch.ts +++ b/src/hooks/useSearchAutoRefetch.ts @@ -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'; @@ -358,8 +357,10 @@ function hasChangedTransactionInSearchResults( return changedTransactionIDs.some((transactionID) => searchResultIDs.has(transactionID)); } +const WORKFLOW_ACTION_TYPES = new Set(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. */ @@ -373,7 +374,7 @@ function hasAddedWorkflowReportAction(reportActions: OnyxCollection([ 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); @@ -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); } /** @@ -908,7 +909,7 @@ 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) ); } @@ -916,7 +917,7 @@ function shouldRefetchSearchOnReportActionChange(queryJSON: SearchQueryJSON): bo * 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)); } /** diff --git a/src/libs/actions/IOU/Hold.ts b/src/libs/actions/IOU/Hold.ts index d641a10b6565..338b50c0f30f 100644 --- a/src/libs/actions/IOU/Hold.ts +++ b/src/libs/actions/IOU/Hold.ts @@ -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 = {}; const copiedActionsSuccess: OnyxCollection> = {}; diff --git a/tests/unit/useSearchAutoRefetchTest.ts b/tests/unit/useSearchAutoRefetchTest.ts index a34eace18e44..6a482ed11057 100644 --- a/tests/unit/useSearchAutoRefetchTest.ts +++ b/tests/unit/useSearchAutoRefetchTest.ts @@ -715,21 +715,16 @@ describe('useSearchAutoRefetch', () => { }, }); - it.each([ - 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(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); }); @@ -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({...approverProps, queryJSON: baseProps.queryJSON}); const {rerender} = renderHook((props: UseSearchAutoRefetch) => useSearchAutoRefetch(props), { initialProps: ungroupedProps, @@ -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(); }); });