Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cc24a97
Add the data to be loaded from onyx
tgolen Jan 8, 2024
d318c95
Remove the use of lodash.
tgolen Jan 8, 2024
b2b8868
Remove deprecated method
tgolen Jan 8, 2024
33e348e
Merge branch 'main' into tgolen-refactor-hocsideloading
tgolen Jan 12, 2024
4237770
Update onyx
tgolen Jan 12, 2024
83b1547
Fix types
tgolen Jan 12, 2024
2440051
Remove extra onyx subscription
tgolen Jan 12, 2024
05b979d
Add all withOnyx properties and import type
tgolen Jan 12, 2024
6f7b07f
Remove unused imports
tgolen Jan 12, 2024
fe4cb1a
Style
tgolen Jan 12, 2024
9cf1ed8
Merge branch 'main' into tgolen-refactor-hocsideloading
tgolen Jan 16, 2024
b2173c0
Merge branch 'main' into tgolen-refactor-hocsideloading
tgolen Jan 30, 2024
e77f37d
Update Onyx
tgolen Jan 31, 2024
093b922
Import type
tgolen Jan 31, 2024
253ee78
Merge branch 'main' into tgolen-refactor-hocsideloading
tgolen Jan 31, 2024
824f2fd
Update lock file
tgolen Jan 31, 2024
20c290f
Separate into multiple withOnyx
tgolen Feb 1, 2024
5484326
Merge branch 'main' into tgolen-refactor-hocsideloading
tgolen Feb 2, 2024
3d0c4e7
Merge branch 'main' into tgolen-refactor-hocsideloading
tgolen Feb 5, 2024
1c275d1
Try to improve the withOnyx types
tgolen Feb 5, 2024
64a65fa
Use hook for dimensions
tgolen Feb 5, 2024
f18570a
Try to fix types
tgolen Feb 5, 2024
6febb6e
Remove debug
tgolen Feb 5, 2024
240065b
Reset the component to an earlier point in time
tgolen Feb 5, 2024
0a10216
Add a better check for when to show the not-found page
tgolen Feb 5, 2024
e112608
Fix selector types
tgolen Feb 5, 2024
cf4be5f
Update src/pages/home/report/withReportAndReportActionOrNotFound.tsx
tgolen Feb 6, 2024
31009d2
Merge branch 'main' into tgolen-refactor-hocsideloading
tgolen Feb 7, 2024
2deac05
Merge branch 'main' into tgolen-refactor-hocsideloading
tgolen Feb 8, 2024
d698da3
Fix changes from TS migration
tgolen Feb 8, 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
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
"react-native-linear-gradient": "^2.8.1",
"react-native-localize": "^2.2.6",
"react-native-modal": "^13.0.0",
"react-native-onyx": "2.0.1",
"react-native-onyx": "2.0.2",
"react-native-pager-view": "6.2.2",
"react-native-pdf": "6.7.3",
"react-native-performance": "^5.1.0",
Expand Down
24 changes: 7 additions & 17 deletions src/pages/FlagCommentPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useCallback} from 'react';
import {ScrollView, View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import type {SvgProps} from 'react-native-svg';
import type {ValueOf} from 'type-fest';
Expand All @@ -19,16 +18,15 @@ import * as ReportUtils from '@libs/ReportUtils';
import * as Report from '@userActions/Report';
import * as Session from '@userActions/Session';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type * as OnyxTypes from '@src/types/onyx';
import withReportAndReportActionOrNotFound from './home/report/withReportAndReportActionOrNotFound';
import type {WithReportAndReportActionOrNotFoundProps} from './home/report/withReportAndReportActionOrNotFound';

type FlagCommentPageWithOnyxProps = {
/** All the report actions from the parent report */
parentReportActions: OnyxEntry<OnyxTypes.ReportActions>;
/** The report action from the parent report */
parentReportAction: OnyxEntry<OnyxTypes.ReportAction>;
};

type FlagCommentPageNavigationProps = StackScreenProps<FlagCommentNavigatorParamList, typeof SCREENS.FLAG_COMMENT_ROOT>;
Expand All @@ -55,7 +53,7 @@ function getReportID(route: FlagCommentPageNavigationProps['route']) {
return route.params.reportID.toString();
}

function FlagCommentPage({parentReportActions, route, report, reportActions}: FlagCommentPageProps) {
function FlagCommentPage({parentReportAction, route, report, reportActions}: FlagCommentPageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();

Expand Down Expand Up @@ -114,21 +112,20 @@ function FlagCommentPage({parentReportActions, route, report, reportActions}: Fl
let reportAction = reportActions?.[`${route.params.reportActionID.toString()}`];

// Handle threads if needed
if (reportAction?.reportActionID === undefined) {
reportAction = parentReportActions?.[report?.parentReportActionID ?? ''];
if (reportAction?.reportActionID === undefined && parentReportAction) {
reportAction = parentReportAction;
}

if (!reportAction) {
return null;
}

return reportAction;
}, [report, reportActions, route.params.reportActionID, parentReportActions]);
}, [reportActions, route.params.reportActionID, parentReportAction]);

const flagComment = (severity: Severity) => {
let reportID: string | undefined = getReportID(route);
const reportAction = getActionToFlag();
const parentReportAction = parentReportActions?.[report?.parentReportActionID ?? ''];

// Handle threads if needed
if (ReportUtils.isChatThread(report) && reportAction?.reportActionID === parentReportAction?.reportActionID) {
Expand Down Expand Up @@ -190,11 +187,4 @@ function FlagCommentPage({parentReportActions, route, report, reportActions}: Fl

FlagCommentPage.displayName = 'FlagCommentPage';

export default withReportAndReportActionOrNotFound(
withOnyx<FlagCommentPageProps, FlagCommentPageWithOnyxProps>({
parentReportActions: {
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID ?? report?.reportID}`,
canEvict: false,
},
})(FlagCommentPage),
);
export default withReportAndReportActionOrNotFound(FlagCommentPage);
25 changes: 20 additions & 5 deletions src/pages/home/report/withReportAndReportActionOrNotFound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
import type {StackScreenProps} from '@react-navigation/stack';
import type {ComponentType, ForwardedRef, RefAttributes} from 'react';
import React, {useCallback, useEffect} from 'react';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry, WithOnyxInstanceState} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import withWindowDimensions from '@components/withWindowDimensions';
import type {WindowDimensionsProps} from '@components/withWindowDimensions/types';
import compose from '@libs/compose';
import getComponentDisplayName from '@libs/getComponentDisplayName';
import type {FlagCommentNavigatorParamList} from '@libs/Navigation/types';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import NotFoundPage from '@pages/ErrorPage/NotFoundPage';
import * as Report from '@userActions/Report';
Expand All @@ -29,6 +28,9 @@ type OnyxProps = {
/** Array of report actions for this report */
reportActions: OnyxEntry<OnyxTypes.ReportActions>;

/** The report's parentReportAction */
parentReportAction: OnyxEntry<OnyxTypes.ReportAction>;

/** The policies which the user has access to */
policies: OnyxCollection<OnyxTypes.Policy>;

Expand All @@ -50,11 +52,11 @@ export default function <TProps extends WithReportAndReportActionOrNotFoundProps

// Handle threads if needed
if (!reportAction?.reportActionID) {
reportAction = ReportActionsUtils.getParentReportAction(props.report);
reportAction = props?.parentReportAction ?? {};
}

return reportAction;
}, [props.report, props.reportActions, props.route.params.reportActionID]);
}, [props.reportActions, props.route.params.reportActionID, props.parentReportAction]);

const reportAction = getReportAction();

Expand All @@ -79,7 +81,9 @@ export default function <TProps extends WithReportAndReportActionOrNotFoundProps
}

// Perform the access/not found checks
if (shouldHideReport || isEmptyObject(reportAction)) {
// Be sure to avoid showing the not-found page while the parent report actions are still being read from Onyx. The parentReportAction will be undefined while it's being read from Onyx
// and then reportAction will either be a valid parentReportAction or an empty object. In the case of an empty object, then it's OK to show the not-found page.
if (shouldHideReport || (props?.parentReportAction !== undefined && isEmptyObject(reportAction))) {
return <NotFoundPage />;
}

Expand Down Expand Up @@ -115,6 +119,17 @@ export default function <TProps extends WithReportAndReportActionOrNotFoundProps
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${route.params.reportID}`,
canEvict: false,
},
parentReportAction: {
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report ? report.parentReportID : 0}`,
selector: (parentReportActions: OnyxEntry<OnyxTypes.ReportActions>, props: WithOnyxInstanceState<OnyxProps>): OnyxEntry<OnyxTypes.ReportAction> => {
const parentReportActionID = props?.report?.parentReportActionID;
if (!parentReportActionID) {
return null;
}
return parentReportActions?.[parentReportActionID] ?? null;
},
canEvict: false,
},
}),
withWindowDimensions,
)(React.forwardRef(WithReportOrNotFound));
Expand Down