Skip to content

Commit 9628af9

Browse files
authored
Merge pull request #28866 from Expensify/tgolen-remove-multiple-withOnyx
Remove duplicate withOnyx calls
2 parents 2c90ed6 + 346e6b6 commit 9628af9

File tree

11 files changed

+92
-152
lines changed

11 files changed

+92
-152
lines changed

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ module.exports = {
3939
files: ['*.js', '*.jsx', '*.ts', '*.tsx'],
4040
plugins: ['react'],
4141
rules: {
42-
'rulesdir/no-multiple-onyx-in-file': 'off',
4342
'rulesdir/onyx-props-must-have-default': 'off',
4443
'react-native-a11y/has-accessibility-hint': ['off'],
4544
'react/jsx-no-constructed-context-values': 'error',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"lint-changed": "eslint --fix $(git diff --diff-filter=AM --name-only main -- \"*.js\" \"*.ts\" \"*.tsx\")",
4040
"lint-watch": "npx eslint-watch --watch --changed",
4141
"shellcheck": "./scripts/shellCheck.sh",
42-
"prettier": "prettier --write .",
42+
"prettier": "prettier --write . --loglevel warn",
4343
"prettier-watch": "onchange \"**/*.{js,ts,tsx}\" -- prettier --write --ignore-unknown {{changed}}",
4444
"print-version": "echo $npm_package_version",
4545
"storybook": "start-storybook -p 6006",

src/components/MoneyRequestHeader.js

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {View} from 'react-native';
55
import {withOnyx} from 'react-native-onyx';
66
import useLocalize from '@hooks/useLocalize';
77
import useWindowDimensions from '@hooks/useWindowDimensions';
8-
import compose from '@libs/compose';
98
import * as HeaderUtils from '@libs/HeaderUtils';
109
import Navigation from '@libs/Navigation/Navigation';
1110
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
@@ -162,26 +161,21 @@ MoneyRequestHeader.displayName = 'MoneyRequestHeader';
162161
MoneyRequestHeader.propTypes = propTypes;
163162
MoneyRequestHeader.defaultProps = defaultProps;
164163

165-
export default compose(
166-
withOnyx({
167-
session: {
168-
key: ONYXKEYS.SESSION,
169-
},
170-
parentReport: {
171-
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`,
172-
},
173-
parentReportActions: {
174-
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report ? report.parentReportID : '0'}`,
175-
canEvict: false,
176-
},
177-
}),
178-
// eslint-disable-next-line rulesdir/no-multiple-onyx-in-file
179-
withOnyx({
180-
transaction: {
181-
key: ({report, parentReportActions}) => {
182-
const parentReportAction = lodashGet(parentReportActions, [report.parentReportActionID]);
183-
return `${ONYXKEYS.COLLECTION.TRANSACTION}${lodashGet(parentReportAction, 'originalMessage.IOUTransactionID', 0)}`;
184-
},
164+
export default withOnyx({
165+
session: {
166+
key: ONYXKEYS.SESSION,
167+
},
168+
parentReport: {
169+
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report ? report.parentReportID : 0}`,
170+
},
171+
parentReportActions: {
172+
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report ? report.parentReportID : 0}`,
173+
canEvict: false,
174+
},
175+
transaction: {
176+
key: ({report, parentReportActions}) => {
177+
const parentReportAction = lodashGet(parentReportActions, [report.parentReportActionID]);
178+
return `${ONYXKEYS.COLLECTION.TRANSACTION}${lodashGet(parentReportAction, 'originalMessage.IOUTransactionID', 0)}`;
185179
},
186-
}),
187-
)(MoneyRequestHeader);
180+
},
181+
})(MoneyRequestHeader);

src/libs/actions/IOU.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2953,7 +2953,7 @@ function navigateToNextPage(iou, iouType, report, path = '') {
29532953
* @returns {String}
29542954
*/
29552955
function getIOUReportID(iou, route) {
2956-
return lodashGet(route, 'params.reportID') || lodashGet(iou, 'participants.0.reportID', '');
2956+
return lodashGet(route, 'params.reportID') || lodashGet(iou, 'participants.0.reportID', '0');
29572957
}
29582958

29592959
export {

src/pages/EditRequestPage.js

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import categoryPropTypes from '@components/categoryPropTypes';
88
import ScreenWrapper from '@components/ScreenWrapper';
99
import tagPropTypes from '@components/tagPropTypes';
1010
import transactionPropTypes from '@components/transactionPropTypes';
11-
import compose from '@libs/compose';
1211
import * as CurrencyUtils from '@libs/CurrencyUtils';
1312
import Navigation from '@libs/Navigation/Navigation';
1413
import * as OptionsListUtils from '@libs/OptionsListUtils';
@@ -276,39 +275,31 @@ function EditRequestPage({betas, report, route, parentReport, policyCategories,
276275
EditRequestPage.displayName = 'EditRequestPage';
277276
EditRequestPage.propTypes = propTypes;
278277
EditRequestPage.defaultProps = defaultProps;
279-
export default compose(
280-
withOnyx({
281-
betas: {
282-
key: ONYXKEYS.BETAS,
278+
export default withOnyx({
279+
betas: {
280+
key: ONYXKEYS.BETAS,
281+
},
282+
report: {
283+
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.threadReportID}`,
284+
},
285+
policyCategories: {
286+
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report ? report.policyID : '0'}`,
287+
},
288+
policyTags: {
289+
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`,
290+
},
291+
parentReport: {
292+
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report ? report.parentReportID : '0'}`,
293+
},
294+
parentReportActions: {
295+
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report ? report.parentReportID : '0'}`,
296+
canEvict: false,
297+
},
298+
transaction: {
299+
key: ({report, parentReportActions}) => {
300+
const parentReportActionID = lodashGet(report, 'parentReportActionID', '0');
301+
const parentReportAction = lodashGet(parentReportActions, parentReportActionID);
302+
return `${ONYXKEYS.COLLECTION.TRANSACTION}${lodashGet(parentReportAction, 'originalMessage.IOUTransactionID', 0)}`;
283303
},
284-
report: {
285-
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.threadReportID}`,
286-
},
287-
}),
288-
// eslint-disable-next-line rulesdir/no-multiple-onyx-in-file
289-
withOnyx({
290-
policyCategories: {
291-
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report ? report.policyID : '0'}`,
292-
},
293-
policyTags: {
294-
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`,
295-
},
296-
parentReport: {
297-
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report ? report.parentReportID : '0'}`,
298-
},
299-
parentReportActions: {
300-
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report ? report.parentReportID : '0'}`,
301-
canEvict: false,
302-
},
303-
}),
304-
// eslint-disable-next-line rulesdir/no-multiple-onyx-in-file
305-
withOnyx({
306-
transaction: {
307-
key: ({report, parentReportActions}) => {
308-
const parentReportActionID = lodashGet(report, 'parentReportActionID', '0');
309-
const parentReportAction = lodashGet(parentReportActions, parentReportActionID);
310-
return `${ONYXKEYS.COLLECTION.TRANSACTION}${lodashGet(parentReportAction, 'originalMessage.IOUTransactionID', 0)}`;
311-
},
312-
},
313-
}),
314-
)(EditRequestPage);
304+
},
305+
})(EditRequestPage);

src/pages/EditSplitBillPage.js

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import React from 'react';
44
import {withOnyx} from 'react-native-onyx';
55
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
66
import transactionPropTypes from '@components/transactionPropTypes';
7-
import compose from '@libs/compose';
87
import * as CurrencyUtils from '@libs/CurrencyUtils';
98
import Navigation from '@libs/Navigation/Navigation';
109
import * as ReportUtils from '@libs/ReportUtils';
@@ -136,26 +135,21 @@ function EditSplitBillPage({route, transaction, draftTransaction}) {
136135
EditSplitBillPage.displayName = 'EditSplitBillPage';
137136
EditSplitBillPage.propTypes = propTypes;
138137
EditSplitBillPage.defaultProps = defaultProps;
139-
export default compose(
140-
withOnyx({
141-
reportActions: {
142-
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${route.params.reportID}`,
143-
canEvict: false,
138+
export default withOnyx({
139+
reportActions: {
140+
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${route.params.reportID}`,
141+
canEvict: false,
142+
},
143+
transaction: {
144+
key: ({route, reportActions}) => {
145+
const reportAction = reportActions[`${route.params.reportActionID.toString()}`];
146+
return `${ONYXKEYS.COLLECTION.TRANSACTION}${lodashGet(reportAction, 'originalMessage.IOUTransactionID', 0)}`;
144147
},
145-
}),
146-
// eslint-disable-next-line rulesdir/no-multiple-onyx-in-file
147-
withOnyx({
148-
transaction: {
149-
key: ({route, reportActions}) => {
150-
const reportAction = reportActions[`${route.params.reportActionID.toString()}`];
151-
return `${ONYXKEYS.COLLECTION.TRANSACTION}${lodashGet(reportAction, 'originalMessage.IOUTransactionID', 0)}`;
152-
},
148+
},
149+
draftTransaction: {
150+
key: ({route, reportActions}) => {
151+
const reportAction = reportActions[`${route.params.reportActionID.toString()}`];
152+
return `${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${lodashGet(reportAction, 'originalMessage.IOUTransactionID', 0)}`;
153153
},
154-
draftTransaction: {
155-
key: ({route, reportActions}) => {
156-
const reportAction = reportActions[`${route.params.reportActionID.toString()}`];
157-
return `${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${lodashGet(reportAction, 'originalMessage.IOUTransactionID', 0)}`;
158-
},
159-
},
160-
}),
161-
)(EditSplitBillPage);
154+
},
155+
})(EditSplitBillPage);

src/pages/iou/MoneyRequestCategoryPage.js

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
77
import ScreenWrapper from '@components/ScreenWrapper';
88
import Text from '@components/Text';
99
import useLocalize from '@hooks/useLocalize';
10-
import compose from '@libs/compose';
1110
import Navigation from '@libs/Navigation/Navigation';
1211
import reportPropTypes from '@pages/reportPropTypes';
1312
import styles from '@styles/styles';
@@ -86,20 +85,11 @@ MoneyRequestCategoryPage.displayName = 'MoneyRequestCategoryPage';
8685
MoneyRequestCategoryPage.propTypes = propTypes;
8786
MoneyRequestCategoryPage.defaultProps = defaultProps;
8887

89-
export default compose(
90-
withOnyx({
91-
iou: {
92-
key: ONYXKEYS.IOU,
93-
},
94-
}),
95-
// eslint-disable-next-line rulesdir/no-multiple-onyx-in-file
96-
withOnyx({
97-
report: {
98-
key: ({route, iou}) => {
99-
const reportID = IOU.getIOUReportID(iou, route);
100-
101-
return `${ONYXKEYS.COLLECTION.REPORT}${reportID}`;
102-
},
103-
},
104-
}),
105-
)(MoneyRequestCategoryPage);
88+
export default withOnyx({
89+
iou: {
90+
key: ONYXKEYS.IOU,
91+
},
92+
report: {
93+
key: ({route, iou}) => `${ONYXKEYS.COLLECTION.REPORT}${IOU.getIOUReportID(iou, route)}`,
94+
},
95+
})(MoneyRequestCategoryPage);

src/pages/iou/MoneyRequestTagPage.js

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import TagPicker from '@components/TagPicker';
99
import tagPropTypes from '@components/tagPropTypes';
1010
import Text from '@components/Text';
1111
import useLocalize from '@hooks/useLocalize';
12-
import compose from '@libs/compose';
1312
import Navigation from '@libs/Navigation/Navigation';
1413
import * as PolicyUtils from '@libs/PolicyUtils';
1514
import reportPropTypes from '@pages/reportPropTypes';
@@ -96,26 +95,14 @@ MoneyRequestTagPage.displayName = 'MoneyRequestTagPage';
9695
MoneyRequestTagPage.propTypes = propTypes;
9796
MoneyRequestTagPage.defaultProps = defaultProps;
9897

99-
export default compose(
100-
withOnyx({
101-
iou: {
102-
key: ONYXKEYS.IOU,
103-
},
104-
}),
105-
// eslint-disable-next-line rulesdir/no-multiple-onyx-in-file
106-
withOnyx({
107-
report: {
108-
key: ({route, iou}) => {
109-
const reportID = IOU.getIOUReportID(iou, route);
110-
111-
return `${ONYXKEYS.COLLECTION.REPORT}${reportID}`;
112-
},
113-
},
114-
}),
115-
// eslint-disable-next-line rulesdir/no-multiple-onyx-in-file
116-
withOnyx({
117-
policyTags: {
118-
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`,
119-
},
120-
}),
121-
)(MoneyRequestTagPage);
98+
export default withOnyx({
99+
report: {
100+
key: ({route, iou}) => `${ONYXKEYS.COLLECTION.REPORT}${IOU.getIOUReportID(iou, route)}`,
101+
},
102+
iou: {
103+
key: ONYXKEYS.IOU,
104+
},
105+
policyTags: {
106+
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`,
107+
},
108+
})(MoneyRequestTagPage);

src/pages/iou/SplitBillDetailsPage.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,6 @@ export default compose(
171171
session: {
172172
key: ONYXKEYS.SESSION,
173173
},
174-
}),
175-
// eslint-disable-next-line rulesdir/no-multiple-onyx-in-file
176-
withOnyx({
177174
transaction: {
178175
key: ({route, reportActions}) => {
179176
const reportAction = reportActions[`${route.params.reportActionID.toString()}`];

src/pages/iou/steps/MoneyRequestConfirmPage.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,6 @@ export default compose(
413413
iou: {
414414
key: ONYXKEYS.IOU,
415415
},
416-
}),
417-
// eslint-disable-next-line rulesdir/no-multiple-onyx-in-file
418-
withOnyx({
419416
report: {
420417
key: ({route, iou}) => {
421418
const reportID = IOU.getIOUReportID(iou, route);
@@ -429,9 +426,6 @@ export default compose(
429426
selectedTab: {
430427
key: `${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.RECEIPT_TAB_ID}`,
431428
},
432-
}),
433-
// eslint-disable-next-line rulesdir/no-multiple-onyx-in-file
434-
withOnyx({
435429
policy: {
436430
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`,
437431
},

0 commit comments

Comments
 (0)