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

Create REPORT_METADATA onyx key to separate report loading logic from the report data #26173

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3be5e69
Separate ReportScreenContext to prevent cyclic re-renders
ospfranco Aug 25, 2023
6125c38
Get rid of full list re-render when marking messages as unread
ospfranco Aug 28, 2023
be7ea56
Linting
ospfranco Aug 28, 2023
caed994
Merge branch 'main' into osp/ReportScreen-optimizations
ospfranco Aug 29, 2023
37926ee
Merge branch 'main' into osp/ReportScreen-optimizations
ospfranco Aug 29, 2023
90c9119
create new onyx metadata collection and connect components
ospfranco Aug 29, 2023
9829fd8
Clean code on ReportScreen main body
ospfranco Aug 30, 2023
bbeb353
Merge branch 'main' into osp/report-metadata
ospfranco Aug 30, 2023
426c3cb
Do not use context on SidebarLinks
ospfranco Aug 30, 2023
9fd2f94
Eagerly initialize date-fns locale
ospfranco Aug 30, 2023
b3b33eb
Update src/pages/home/ReportScreen.js
ospfranco Aug 30, 2023
40d48bb
Update src/pages/home/report/ReportActionsList.js
ospfranco Aug 30, 2023
14808d9
Remove requestIdleCallback as it might not be available everywhere
ospfranco Aug 30, 2023
4f75359
Merge branch 'main' into osp/report-metadata
ospfranco Sep 4, 2023
6effb37
Fix wrong variable name
ospfranco Sep 8, 2023
5d3f53b
Merge branch 'main' into osp/report-metadata
ospfranco Sep 12, 2023
cfa7db6
Merge branch 'main' into osp/report-metadata
ospfranco Sep 13, 2023
12c8fa9
Get rid of unused currentReportId prop
ospfranco Sep 14, 2023
d761db0
Merge branch 'main' into osp/report-metadata
ospfranco Sep 14, 2023
ffaf7a8
Remove containerHeight from ReportActionsSkeletonView because onLayou…
ospfranco Sep 14, 2023
3df387b
Lint
ospfranco Sep 14, 2023
8d5031b
Merge branch 'main' into osp/report-metadata
ospfranco Sep 15, 2023
063d658
Removed skeleton height calculation
ospfranco Sep 15, 2023
f74d674
Merge branch 'main' into osp/report-metadata
ospfranco Sep 18, 2023
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
2 changes: 2 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ const ONYXKEYS = {
POLICY_CATEGORIES: 'policyCategories_',
WORKSPACE_INVITE_MEMBERS_DRAFT: 'workspaceInviteMembersDraft_',
REPORT: 'report_',
REPORT_METADATA: 'reportMetadata_',
REPORT_ACTIONS: 'reportActions_',
REPORT_ACTIONS_DRAFTS: 'reportActionsDrafts_',
REPORT_ACTIONS_REACTIONS: 'reportActionsReactions_',
Expand Down Expand Up @@ -379,6 +380,7 @@ type OnyxValues = {
[ONYXKEYS.COLLECTION.DEPRECATED_POLICY_MEMBER_LIST]: OnyxTypes.PolicyMember;
[ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT]: Record<string, number>;
[ONYXKEYS.COLLECTION.REPORT]: OnyxTypes.Report;
[ONYXKEYS.COLLECTION.REPORT_METADATA]: OnyxTypes.ReportMetadata;
[ONYXKEYS.COLLECTION.REPORT_ACTIONS]: OnyxTypes.ReportAction;
[ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS]: string;
[ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS]: OnyxTypes.ReportActionReactions;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Reactions/ReportActionItemEmojiReactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import EmojiReactionsPropTypes from './EmojiReactionsPropTypes';
import Tooltip from '../Tooltip';
import ReactionTooltipContent from './ReactionTooltipContent';
import * as EmojiUtils from '../../libs/EmojiUtils';
import ReportScreenContext from '../../pages/home/ReportScreenContext';
import {ReactionListContext} from '../../pages/home/ReportScreenContext';

const propTypes = {
emojiReactions: EmojiReactionsPropTypes,
Expand Down Expand Up @@ -41,7 +41,7 @@ const defaultProps = {
};

function ReportActionItemEmojiReactions(props) {
const {reactionListRef} = useContext(ReportScreenContext);
const reactionListRef = useContext(ReactionListContext);
const popoverReactionListAnchor = useRef(null);
let totalReactionCount = 0;

Expand Down
11 changes: 11 additions & 0 deletions src/components/withLocalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const withLocalizePropTypes = {
/** Formats a datetime to local date and time string */
datetimeToCalendarTime: PropTypes.func.isRequired,

/** Updates date-fns internal locale */
updateLocale: PropTypes.func.isRequired,

/** Returns a locally converted phone number for numbers from the same region
* and an internationally converted phone number with the country code for numbers from other regions */
formatPhoneNumber: PropTypes.func.isRequired,
Expand Down Expand Up @@ -72,6 +75,7 @@ class LocaleContextProvider extends React.Component {
numberFormat: this.numberFormat.bind(this),
datetimeToRelative: this.datetimeToRelative.bind(this),
datetimeToCalendarTime: this.datetimeToCalendarTime.bind(this),
updateLocale: this.updateLocale.bind(this),
formatPhoneNumber: this.formatPhoneNumber.bind(this),
fromLocaleDigit: this.fromLocaleDigit.bind(this),
toLocaleDigit: this.toLocaleDigit.bind(this),
Expand Down Expand Up @@ -115,6 +119,13 @@ class LocaleContextProvider extends React.Component {
return DateUtils.datetimeToCalendarTime(this.props.preferredLocale, datetime, includeTimezone, lodashGet(this.props, 'currentUserPersonalDetails.timezone.selected'), isLowercase);
}

/**
* Updates date-fns internal locale to the user preferredLocale
*/
updateLocale() {
DateUtils.setLocale(this.props.preferredLocale);
}

/**
* @param {String} phoneNumber
* @returns {String}
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useReportScrollManager/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {useContext, useCallback} from 'react';
import ReportScreenContext from '../../pages/home/ReportScreenContext';
import {ActionListContext} from '../../pages/home/ReportScreenContext';

function useReportScrollManager() {
const {flatListRef} = useContext(ReportScreenContext);
const flatListRef = useContext(ActionListContext);

/**
* Scroll to the provided index. On non-native implementations we do not want to scroll when we are scrolling because
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useReportScrollManager/index.native.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {useContext, useCallback} from 'react';
import ReportScreenContext from '../../pages/home/ReportScreenContext';
import {ActionListContext} from '../../pages/home/ReportScreenContext';

function useReportScrollManager() {
const {flatListRef} = useContext(ReportScreenContext);
const flatListRef = useContext(ActionListContext);

/**
* Scroll to the provided index.
Expand Down
1 change: 1 addition & 0 deletions src/libs/DateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ const DateUtils = {
subtractMillisecondsFromDateTime,
getDateStringFromISOTimestamp,
getStatusUntilDate,
setLocale,
};

export default DateUtils;
2 changes: 1 addition & 1 deletion src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ function createPolicyExpenseChats(policyID, invitedEmailsToAccountIDs) {

workspaceMembersChats.onyxFailureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticReport.reportID}`,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${optimisticReport.reportID}`,
value: {
isLoadingReportActions: false,
},
Expand Down
104 changes: 66 additions & 38 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,43 +401,65 @@ function reportActionsExist(reportID) {
* @param {Array} participantAccountIDList The list of accountIDs that are included in a new chat, not including the user creating it
*/
function openReport(reportID, participantLoginList = [], newReportObject = {}, parentReportActionID = '0', isFromDeepLink = false, participantAccountIDList = []) {
const optimisticReportData = {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: reportActionsExist(reportID)
? {}
: {
isLoadingReportActions: true,
isLoadingMoreReportActions: false,
reportName: lodashGet(allReports, [reportID, 'reportName'], CONST.REPORT.DEFAULT_REPORT_NAME),
},
};
const reportSuccessData = {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
isLoadingReportActions: false,
pendingFields: {
createChat: null,
const optimisticReportData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: reportActionsExist(reportID)
? {}
: {
reportName: lodashGet(allReports, [reportID, 'reportName'], CONST.REPORT.DEFAULT_REPORT_NAME),
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`,
value: reportActionsExist(reportID)
? {}
: {
isLoadingReportActions: true,
isLoadingMoreReportActions: false,
},
},
];

const reportSuccessData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
pendingFields: {
createChat: null,
},
errorFields: {
createChat: null,
},
isOptimisticReport: false,
},
errorFields: {
createChat: null,
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`,
value: {
isLoadingReportActions: false,
ospfranco marked this conversation as resolved.
Show resolved Hide resolved
},
isOptimisticReport: false,
},
};
const reportFailureData = {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
isLoadingReportActions: false,
];

const reportFailureData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`,
value: {
isLoadingReportActions: false,
},
},
};
];

const onyxData = {
optimisticData: [optimisticReportData],
successData: [reportSuccessData],
failureData: [reportFailureData],
optimisticData: optimisticReportData,
successData: reportSuccessData,
failureData: reportFailureData,
};

const params = {
Expand All @@ -454,17 +476,17 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p
// If we open an exist report, but it is not present in Onyx yet, we should change the method to set for this report
// and we need data to be available when we navigate to the chat page
if (_.isEmpty(ReportUtils.getReport(reportID))) {
optimisticReportData.onyxMethod = Onyx.METHOD.SET;
onyxData.optimisticReportData.onyxMethod = Onyx.METHOD.SET;
}

// If we are creating a new report, we need to add the optimistic report data and a report action
if (!_.isEmpty(newReportObject)) {
// Change the method to set for new reports because it doesn't exist yet, is faster,
// and we need the data to be available when we navigate to the chat page
optimisticReportData.onyxMethod = Onyx.METHOD.SET;
optimisticReportData.value = {
onyxData.optimisticReportData[0].onyxMethod = Onyx.METHOD.SET;
onyxData.optimisticReportData[0].value = {
reportName: CONST.REPORT.DEFAULT_REPORT_NAME,
...optimisticReportData.value,
...onyxData.optimisticReportData.value,
...newReportObject,
pendingFields: {
createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
Expand Down Expand Up @@ -646,17 +668,23 @@ function reconnect(reportID) {
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
reportName: lodashGet(allReports, [reportID, 'reportName'], CONST.REPORT.DEFAULT_REPORT_NAME),
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`,
value: {
isLoadingReportActions: true,
isLoadingMoreReportActions: false,
reportName: lodashGet(allReports, [reportID, 'reportName'], CONST.REPORT.DEFAULT_REPORT_NAME),
},
},
],
successData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`,
value: {
isLoadingReportActions: false,
},
Expand All @@ -665,7 +693,7 @@ function reconnect(reportID) {
failureData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`,
value: {
isLoadingReportActions: false,
},
Expand Down
Loading
Loading