Skip to content

Commit 1825e52

Browse files
authored
Merge pull request #84673 from hungvu193/followup-66423
[NO QA] Remove ONYXKEYS.COLLECTION.REPORT_VIOLATIONS
2 parents 29dbed2 + 0f9e49a commit 1825e52

15 files changed

Lines changed: 25 additions & 294 deletions

File tree

src/CONST/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6348,10 +6348,6 @@ const CONST = {
63486348
RBR_MESSAGE_MAX_CHARACTERS_FOR_PREVIEW: 40,
63496349
},
63506350

6351-
REPORT_VIOLATIONS_EXCLUDED_FIELDS: {
6352-
TEXT_TITLE: 'text_title',
6353-
},
6354-
63556351
/** Context menu types */
63566352
CONTEXT_MENU_TYPES: {
63576353
LINK: 'LINK',

src/ONYXKEYS.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,6 @@ const ONYXKEYS = {
713713
REPORT_USER_IS_TYPING: 'reportUserIsTyping_',
714714
PENDING_CONCIERGE_RESPONSE: 'pendingConciergeResponse_',
715715
REPORT_USER_IS_LEAVING_ROOM: 'reportUserIsLeavingRoom_',
716-
REPORT_VIOLATIONS: 'reportViolations_',
717716
SECURITY_GROUP: 'securityGroup_',
718717
TRANSACTION: 'transactions_',
719718
TRANSACTION_VIOLATIONS: 'transactionViolations_',
@@ -1198,7 +1197,6 @@ type OnyxCollectionValuesMapping = {
11981197
[ONYXKEYS.COLLECTION.REPORT_USER_IS_TYPING]: OnyxTypes.ReportUserIsTyping;
11991198
[ONYXKEYS.COLLECTION.PENDING_CONCIERGE_RESPONSE]: OnyxTypes.PendingConciergeResponse;
12001199
[ONYXKEYS.COLLECTION.REPORT_USER_IS_LEAVING_ROOM]: boolean;
1201-
[ONYXKEYS.COLLECTION.REPORT_VIOLATIONS]: OnyxTypes.ReportViolations;
12021200
[ONYXKEYS.COLLECTION.SECURITY_GROUP]: OnyxTypes.SecurityGroup;
12031201
[ONYXKEYS.COLLECTION.TRANSACTION]: OnyxTypes.Transaction;
12041202
[ONYXKEYS.COLLECTION.TRANSACTION_DRAFT]: OnyxTypes.Transaction;

src/components/MoneyRequestReportView/MoneyRequestViewReportFields.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {View} from 'react-native';
44
import type {OnyxEntry} from 'react-native-onyx';
55
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
66
import OfflineWithFeedback from '@components/OfflineWithFeedback';
7-
import useOnyx from '@hooks/useOnyx';
87
import useThemeStyles from '@hooks/useThemeStyles';
98
import {clearReportFieldKeyErrors} from '@libs/actions/Report';
109
import {resolveReportFieldValue} from '@libs/Formula';
@@ -23,7 +22,6 @@ import {
2322
} from '@libs/ReportUtils';
2423
import type {ThemeStyles} from '@styles/index';
2524
import CONST from '@src/CONST';
26-
import ONYXKEYS from '@src/ONYXKEYS';
2725
import ROUTES from '@src/ROUTES';
2826
import type {Policy, PolicyReportField, Report, ReportViolationName} from '@src/types/onyx';
2927
import type {PendingAction} from '@src/types/onyx/OnyxCommon';
@@ -82,8 +80,6 @@ function ReportFieldView(reportField: EnrichedPolicyReportField, report: OnyxEnt
8280
function MoneyRequestViewReportFields({report, policy, isCombinedReport = false, pendingAction}: MoneyRequestViewReportFieldsProps) {
8381
const styles = useThemeStyles();
8482

85-
const [violations] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_VIOLATIONS}${report?.reportID}`);
86-
8783
const sortedPolicyReportFields = useMemo<EnrichedPolicyReportField[]>((): EnrichedPolicyReportField[] => {
8884
const {fieldValues, fieldsByName} = getReportFieldMaps(report, policy?.fieldList ?? {});
8985
const fields = Object.values(fieldsByName);
@@ -98,7 +94,7 @@ function MoneyRequestViewReportFields({report, policy, isCombinedReport = false,
9894
const isDeletedFormulaField = field.type === CONST.REPORT_FIELD_TYPES.FORMULA && field.deletable;
9995
const fieldKey = getReportFieldKey(field.fieldID);
10096

101-
const violation = isFieldDisabled ? undefined : getFieldViolation(violations, field);
97+
const violation = isFieldDisabled ? undefined : getFieldViolation(field);
10298
const violationTranslation = getFieldViolationTranslation(field, violation);
10399

104100
return {
@@ -110,7 +106,7 @@ function MoneyRequestViewReportFields({report, policy, isCombinedReport = false,
110106
violationTranslation,
111107
};
112108
});
113-
}, [policy, report, violations]);
109+
}, [policy, report]);
114110

115111
const enabledReportFields = sortedPolicyReportFields.filter(
116112
(reportField) => !isReportFieldDisabled(report, reportField, policy) || reportField.type === CONST.REPORT_FIELD_TYPES.FORMULA,

src/components/ReportActionItem/MoneyReportView.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import UnreadActionIndicator from '@components/UnreadActionIndicator';
1313
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
1414
import useLocalize from '@hooks/useLocalize';
1515
import useNetwork from '@hooks/useNetwork';
16-
import useOnyx from '@hooks/useOnyx';
1716
import useReportTransactions from '@hooks/useReportTransactions';
1817
import useStyleUtils from '@hooks/useStyleUtils';
1918
import useTheme from '@hooks/useTheme';
@@ -46,7 +45,6 @@ import variables from '@styles/variables';
4645
import CONST from '@src/CONST';
4746
import type {TranslationPaths} from '@src/languages/types';
4847
import {clearReportFieldKeyErrors} from '@src/libs/actions/Report';
49-
import ONYXKEYS from '@src/ONYXKEYS';
5048
import ROUTES from '@src/ROUTES';
5149
import type {Policy, Report} from '@src/types/onyx';
5250
import type {PendingAction} from '@src/types/onyx/OnyxCommon';
@@ -115,8 +113,6 @@ function MoneyReportView({
115113
StyleUtils.getColorStyle(theme.textSupporting),
116114
];
117115

118-
const [violations] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_VIOLATIONS}${report?.reportID}`);
119-
120116
const {sortedPolicyReportFields, fieldValues, fieldsByName} = useMemo(() => {
121117
const {fieldValues: values, fieldsByName: byName} = getReportFieldMaps(report, policy?.fieldList ?? {});
122118
const sorted = Object.values(byName)
@@ -176,7 +172,7 @@ function MoneyReportView({
176172
const isFieldDisabled = isReportFieldDisabledForUser(report, reportField, policy);
177173
const fieldKey = getReportFieldKey(reportField.fieldID);
178174

179-
const violation = isFieldDisabled ? undefined : getFieldViolation(violations, reportField);
175+
const violation = isFieldDisabled ? undefined : getFieldViolation(reportField);
180176
const violationTranslation = getFieldViolationTranslation(reportField, violation);
181177

182178
return (

src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ function TransactionPreviewContent({
7373
const styles = useThemeStyles();
7474
const {translate} = useLocalize();
7575
const {environmentURL} = useEnvironment();
76-
const [reportViolations] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_VIOLATIONS}${getNonEmptyStringOnyxID(report?.reportID)}`);
7776
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`);
7877
const isParentPolicyExpenseChat = isPolicyExpenseChat(chatReport);
7978
const transactionDetails = useMemo<Partial<TransactionDetails>>(
@@ -115,9 +114,8 @@ function TransactionPreviewContent({
115114
currentUserEmail,
116115
currentUserAccountID,
117116
reportActions,
118-
reportViolations,
119117
}),
120-
[areThereDuplicates, transactionPreviewCommonArguments, isReportAPolicyExpenseChat, currentUserEmail, currentUserAccountID, reportActions, reportViolations],
118+
[areThereDuplicates, transactionPreviewCommonArguments, isReportAPolicyExpenseChat, currentUserEmail, currentUserAccountID, reportActions],
121119
);
122120

123121
const {shouldShowRBR, shouldShowMerchant, shouldShowSplitShare, shouldShowTag, shouldShowCategory, shouldShowSkeleton, shouldShowDescription} = conditionals;

src/libs/ReportUtils.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import type {
5656
ReportMetadata,
5757
ReportNameValuePairs,
5858
ReportViolationName,
59-
ReportViolations,
6059
Task,
6160
Transaction,
6261
TransactionViolation,
@@ -9318,13 +9317,6 @@ function hasAnyViolations(
93189317
);
93199318
}
93209319

9321-
function hasReportViolations(reportViolations: OnyxEntry<ReportViolations>) {
9322-
if (!reportViolations) {
9323-
return false;
9324-
}
9325-
return Object.values(reportViolations ?? {}).some((violations) => !isEmptyObject(violations));
9326-
}
9327-
93289320
/**
93299321
* Checks if submission should be blocked due to strict policy rules being enabled and violations present.
93309322
* When a user's domain has "strictly enforce workspace rules" enabled, they cannot submit reports with violations.
@@ -12417,23 +12409,12 @@ function getChatUsedForOnboarding(onboardingValue: OnyxEntry<Onboarding>, concie
1241712409
/**
1241812410
* Checks if given field has any violations and returns name of the first encountered one
1241912411
*/
12420-
function getFieldViolation(violations: OnyxEntry<ReportViolations>, reportField: PolicyReportField): ReportViolationName | undefined {
12412+
function getFieldViolation(reportField: PolicyReportField): ReportViolationName | undefined {
1242112413
if (!reportField) {
1242212414
return undefined;
1242312415
}
1242412416

12425-
if (!violations) {
12426-
return (reportField.value ?? reportField.defaultValue) ? undefined : CONST.REPORT_VIOLATIONS.FIELD_REQUIRED;
12427-
}
12428-
12429-
const fieldViolation = Object.values(CONST.REPORT_VIOLATIONS).find((violation) => !!violations[violation] && violations[violation][reportField.fieldID]);
12430-
12431-
// If the field has no value or no violation, we return 'fieldRequired' violation
12432-
if (!fieldViolation) {
12433-
return reportField.value ? undefined : CONST.REPORT_VIOLATIONS.FIELD_REQUIRED;
12434-
}
12435-
12436-
return fieldViolation;
12417+
return (reportField.value ?? reportField.defaultValue) ? undefined : CONST.REPORT_VIOLATIONS.FIELD_REQUIRED;
1243712418
}
1243812419

1243912420
/**
@@ -13521,7 +13502,6 @@ export {
1352113502
getMostRecentlyVisitedReport,
1352213503
getSourceIDFromReportAction,
1352313504
getIntegrationNameFromExportMessage,
13524-
hasReportViolations,
1352513505
isPayAtEndExpenseReport,
1352613506
getApprovalChain,
1352713507
isIndividualInvoiceRoom,

src/libs/TransactionPreviewUtils.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,7 @@ import {convertToDisplayString} from './CurrencyUtils';
1111
import DateUtils from './DateUtils';
1212
import {hasDynamicExternalWorkflow} from './PolicyUtils';
1313
import {getMostRecentActiveDEWSubmitFailedAction, getOriginalMessage, isDynamicExternalWorkflowSubmitFailedAction, isMessageDeleted, isMoneyRequestAction} from './ReportActionsUtils';
14-
import {
15-
hasActionWithErrorsForTransaction,
16-
hasReceiptError,
17-
hasReportViolations,
18-
isPaidGroupPolicyExpenseReport,
19-
isPaidGroupPolicy as isPaidGroupPolicyUtil,
20-
isReportApproved,
21-
isReportOwner,
22-
isSettled,
23-
} from './ReportUtils';
14+
import {hasActionWithErrorsForTransaction, hasReceiptError, isPaidGroupPolicyExpenseReport, isPaidGroupPolicy as isPaidGroupPolicyUtil, isReportApproved, isSettled} from './ReportUtils';
2415
import type {TransactionDetails} from './ReportUtils';
2516
import StringUtils from './StringUtils';
2617
import {
@@ -368,7 +359,6 @@ function getTransactionPreviewTextAndTranslationPaths({
368359
}
369360

370361
function createTransactionPreviewConditionals({
371-
reportViolations,
372362
iouReport,
373363
policy,
374364
transaction,
@@ -382,7 +372,6 @@ function createTransactionPreviewConditionals({
382372
currentUserAccountID,
383373
reportActions,
384374
}: {
385-
reportViolations: OnyxEntry<OnyxTypes.ReportViolations>;
386375
iouReport: OnyxEntry<OnyxTypes.Report>;
387376
policy: OnyxEntry<OnyxTypes.Policy>;
388377
transaction: OnyxEntry<OnyxTypes.Transaction> | undefined;
@@ -433,8 +422,7 @@ function createTransactionPreviewConditionals({
433422
(violation) => violation.name === CONST.VIOLATIONS.MODIFIED_AMOUNT && (violation.type === CONST.VIOLATION_TYPES.VIOLATION || violation.type === CONST.VIOLATION_TYPES.NOTICE),
434423
));
435424
const hasErrorOrOnHold = hasFieldErrors || (!isFullySettled && !isFullyApproved && isTransactionOnHold);
436-
const hasReportViolationsOrActionErrors =
437-
(isReportOwner(iouReport) && hasReportViolations(reportViolations)) || hasActionWithErrorsForTransaction(iouReport?.reportID, transaction, reportActions);
425+
const hasReportViolationsOrActionErrors = hasActionWithErrorsForTransaction(iouReport?.reportID, transaction, reportActions);
438426
const isDEWSubmitFailed = hasDynamicExternalWorkflow(policy) && !!getMostRecentActiveDEWSubmitFailedAction(reportActions);
439427
const shouldShowRBR = hasAnyViolations || hasErrorOrOnHold || hasReportViolationsOrActionErrors || hasReceiptError(transaction) || isDEWSubmitFailed;
440428

src/libs/actions/IOU/index.ts

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ import {
7979
getSubmitToAccountID,
8080
hasDependentTags,
8181
hasDynamicExternalWorkflow,
82-
isControlPolicy,
8382
isDelayedSubmissionEnabled,
8483
isPaidGroupPolicy,
8584
isPolicyAdmin,
@@ -1776,39 +1775,6 @@ function getReceiptError(
17761775
);
17771776
}
17781777

1779-
/** Helper function to get optimistic fields violations onyx data */
1780-
function getFieldViolationsOnyxData(iouReport: OnyxTypes.Report): OnyxData<typeof ONYXKEYS.COLLECTION.REPORT_VIOLATIONS> {
1781-
const missingFields: OnyxTypes.ReportFieldsViolations = {};
1782-
const excludedFields = Object.values(CONST.REPORT_VIOLATIONS_EXCLUDED_FIELDS) as string[];
1783-
1784-
for (const field of Object.values(iouReport.fieldList ?? {})) {
1785-
if (excludedFields.includes(field.fieldID) || !!field.value || !!field.defaultValue) {
1786-
continue;
1787-
}
1788-
// in case of missing field violation the empty object is indicator.
1789-
missingFields[field.fieldID] = {};
1790-
}
1791-
1792-
return {
1793-
optimisticData: [
1794-
{
1795-
onyxMethod: Onyx.METHOD.SET,
1796-
key: `${ONYXKEYS.COLLECTION.REPORT_VIOLATIONS}${iouReport.reportID}`,
1797-
value: {
1798-
fieldRequired: missingFields,
1799-
},
1800-
},
1801-
],
1802-
failureData: [
1803-
{
1804-
onyxMethod: Onyx.METHOD.SET,
1805-
key: `${ONYXKEYS.COLLECTION.REPORT_VIOLATIONS}${iouReport.reportID}`,
1806-
value: null,
1807-
},
1808-
],
1809-
};
1810-
}
1811-
18121778
type BuildOnyxDataForTestDriveIOUParams = {
18131779
transaction: OnyxTypes.Transaction;
18141780
iouOptimisticParams: MoneyRequestOptimisticParams['iou'];
@@ -2579,7 +2545,6 @@ type BuildOnyxDataForTrackExpenseParams = {
25792545
chat: {report: OnyxInputValue<OnyxTypes.Report>; previewAction: OnyxInputValue<ReportAction>};
25802546
iou: {report: OnyxInputValue<OnyxTypes.Report>; createdAction: OptimisticCreatedReportAction; action: OptimisticIOUReportAction};
25812547
transactionParams: {transaction: OnyxTypes.Transaction; threadReport: OptimisticChatReport | null; threadCreatedReportAction: OptimisticCreatedReportAction | null};
2582-
policyParams: {policy?: OnyxInputValue<OnyxTypes.Policy>; tagList?: OnyxInputValue<OnyxTypes.PolicyTagLists>; categories?: OnyxInputValue<OnyxTypes.PolicyCategories>};
25832548
shouldCreateNewMoneyRequestReport: boolean;
25842549
existingTransactionThreadReportID?: string;
25852550
actionableTrackExpenseWhisper?: OnyxInputValue<OnyxTypes.ReportAction>;
@@ -2596,15 +2561,13 @@ type BuildOnyxDataForTrackExpenseKeys =
25962561
| typeof ONYXKEYS.COLLECTION.TRANSACTION
25972562
| typeof ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE
25982563
| typeof ONYXKEYS.COLLECTION.SNAPSHOT
2599-
| typeof ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS
2600-
| typeof ONYXKEYS.COLLECTION.REPORT_VIOLATIONS;
2564+
| typeof ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS;
26012565

26022566
/** Builds the Onyx data for track expense */
26032567
function buildOnyxDataForTrackExpense({
26042568
chat,
26052569
iou,
26062570
transactionParams,
2607-
policyParams = {},
26082571
shouldCreateNewMoneyRequestReport,
26092572
existingTransactionThreadReportID,
26102573
actionableTrackExpenseWhisper,
@@ -2616,8 +2579,6 @@ function buildOnyxDataForTrackExpense({
26162579
const {report: chatReport, previewAction: reportPreviewAction} = chat;
26172580
const {report: iouReport, createdAction: iouCreatedAction, action: iouAction} = iou;
26182581
const {transaction, threadReport: transactionThreadReport, threadCreatedReportAction: transactionThreadCreatedReportAction} = transactionParams;
2619-
const {policy, tagList: policyTagList, categories: policyCategories} = policyParams;
2620-
26212582
const isScanRequest = isScanRequestTransactionUtils(transaction);
26222583
const isDistanceRequest = isDistanceRequestTransactionUtils(transaction);
26232584
const clearedPendingFields = Object.fromEntries(Object.keys(transaction.pendingFields ?? {}).map((key) => [key, null]));
@@ -2993,38 +2954,6 @@ function buildOnyxDataForTrackExpense({
29932954
onyxData.successData?.push(...searchUpdate.successData);
29942955
}
29952956
}
2996-
2997-
// We don't need to compute violations unless we're on a paid policy
2998-
if (!policy || !isPaidGroupPolicy(policy) || transaction.reportID === CONST.REPORT.UNREPORTED_REPORT_ID) {
2999-
return onyxData;
3000-
}
3001-
3002-
const violationsOnyxData = ViolationsUtils.getViolationsOnyxData(
3003-
transaction,
3004-
[],
3005-
policy,
3006-
policyTagList ?? {},
3007-
policyCategories ?? {},
3008-
hasDependentTags(policy, policyTagList ?? {}),
3009-
false,
3010-
);
3011-
3012-
if (violationsOnyxData) {
3013-
onyxData.optimisticData?.push(violationsOnyxData);
3014-
onyxData.failureData?.push({
3015-
onyxMethod: Onyx.METHOD.SET,
3016-
key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`,
3017-
value: [],
3018-
});
3019-
}
3020-
3021-
// Show field violations only for control policies
3022-
if (isControlPolicy(policy) && iouReport) {
3023-
const {optimisticData: fieldViolationsOptimisticData, failureData: fieldViolationsFailureData} = getFieldViolationsOnyxData(iouReport);
3024-
onyxData.optimisticData?.push(...(fieldViolationsOptimisticData ?? []));
3025-
onyxData.failureData?.push(...(fieldViolationsFailureData ?? []));
3026-
}
3027-
30282957
return onyxData;
30292958
}
30302959

@@ -3717,7 +3646,7 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T
37173646
isSelfTourViewed,
37183647
} = params;
37193648
const {payeeAccountID = userAccountID, payeeEmail = currentUserEmail, participant} = participantParams;
3720-
const {policy, policyCategories, policyTagList} = policyParams;
3649+
const {policy} = policyParams;
37213650
const {
37223651
comment,
37233652
amount,
@@ -4012,7 +3941,6 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T
40123941
threadCreatedReportAction: optimisticCreatedActionForTransactionThread,
40133942
threadReport: optimisticTransactionThread ?? {},
40143943
},
4015-
policyParams: {policy, tagList: policyTagList, categories: policyCategories},
40163944
shouldCreateNewMoneyRequestReport,
40173945
actionableTrackExpenseWhisper,
40183946
retryParams,

0 commit comments

Comments
 (0)