Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ReportActionItemCreated update #20960

Merged
merged 2 commits into from
Jun 20, 2023
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
7 changes: 6 additions & 1 deletion src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,12 @@ function ReportActionItem(props) {
};

if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) {
return <ReportActionItemCreated reportID={props.report.reportID} />;
return (
<ReportActionItemCreated
policyID={props.report.policyID}
reportID={props.report.reportID}
/>
);
}
if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.RENAMED) {
return <RenameAction action={props.action} />;
Expand Down
27 changes: 25 additions & 2 deletions src/pages/home/report/ReportActionItemCreated.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {memo} from 'react';
import {View, Image} from 'react-native';
import lodashGet from 'lodash/get';
import {withOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -29,11 +29,21 @@ const propTypes = {
/** Personal details of all the users */
personalDetails: PropTypes.objectOf(participantPropTypes),

/** The policy object for the current route */
policy: PropTypes.shape({
/** The name of the policy */
name: PropTypes.string,

/** The URL for the policy avatar */
avatar: PropTypes.string,
}),

...windowDimensionsPropTypes,
};
const defaultProps = {
report: {},
personalDetails: {},
policy: {},
};

function ReportActionItemCreated(props) {
Expand Down Expand Up @@ -91,5 +101,18 @@ export default compose(
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
policy: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
},
}),
)(ReportActionItemCreated);
)(
memo(
ReportActionItemCreated,
(prevProps, nextProps) =>
lodashGet(prevProps.props, 'policy.name') === lodashGet(nextProps, 'policy.name') &&
lodashGet(prevProps.props, 'policy.avatar') === lodashGet(nextProps, 'policy.avatar') &&
lodashGet(prevProps.props, 'report.lastReadTime') === lodashGet(nextProps, 'report.lastReadTime') &&
lodashGet(prevProps.props, 'report.statusNum') === lodashGet(nextProps, 'report.statusNum') &&
lodashGet(prevProps.props, 'report.stateNum') === lodashGet(nextProps, 'report.stateNum'),
),
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hungvu193 I don't think we can make this change. There might be other multiple thing that should trigger the rerender like change in name of report or user or user's profile. Those should also be incorporated here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sobitneupane you mean we also need to add the check for personalDetails and report?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. I'll update it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sobitneupane I've just updated!.
Since ReportActionItemCreated is inside ReportScreen, and every time report has update, the lastReadTimewill change, so the conditions for lastReadTime, statusNum and stateNum are enough for this case.