Skip to content

Commit

Permalink
Merge pull request #37839 from Expensify/Rory-AltFixGetOlderActions
Browse files Browse the repository at this point in the history
Include filtered actions when computing oldest and newest reportAction on a report

(cherry picked from commit 8d4c340)
  • Loading branch information
youssef-lr authored and OSBotify committed Mar 6, 2024
1 parent 6725eb3 commit 4f224f4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
30 changes: 23 additions & 7 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,31 @@ Onyx.connect({
},
});

// map of reportID to all reportActions for that report
const allReportActions: OnyxCollection<ReportActions> = {};

// map of reportID to the ID of the oldest reportAction for that report
const oldestReportActions: Record<string, string> = {};

// map of report to the ID of the newest action for that report
const newestReportActions: Record<string, string> = {};

Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
callback: (action, key) => {
if (!key || !action) {
callback: (actions, key) => {
if (!key || !actions) {
return;
}
const reportID = CollectionUtils.extractCollectionItemID(key);
allReportActions[reportID] = action;
allReportActions[reportID] = actions;
const sortedActions = ReportActionsUtils.getSortedReportActions(Object.values(actions));

if (sortedActions.length === 0) {
return;
}

oldestReportActions[reportID] = sortedActions[0].reportActionID;
newestReportActions[reportID] = sortedActions[sortedActions.length - 1].reportActionID;
},
});

Expand Down Expand Up @@ -879,7 +895,7 @@ function reconnect(reportID: string) {
* Gets the older actions that have not been read yet.
* Normally happens when you scroll up on a chat, and the actions have not been read yet.
*/
function getOlderActions(reportID: string, reportActionID: string) {
function getOlderActions(reportID: string) {
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand Down Expand Up @@ -912,7 +928,7 @@ function getOlderActions(reportID: string, reportActionID: string) {

const parameters: GetOlderActionsParams = {
reportID,
reportActionID,
reportActionID: oldestReportActions[reportID],
};

API.read(READ_COMMANDS.GET_OLDER_ACTIONS, parameters, {optimisticData, successData, failureData});
Expand All @@ -922,7 +938,7 @@ function getOlderActions(reportID: string, reportActionID: string) {
* Gets the newer actions that have not been read yet.
* Normally happens when you are not located at the bottom of the list and scroll down on a chat.
*/
function getNewerActions(reportID: string, reportActionID: string) {
function getNewerActions(reportID: string) {
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand Down Expand Up @@ -955,7 +971,7 @@ function getNewerActions(reportID: string, reportActionID: string) {

const parameters: GetNewerActionsParams = {
reportID,
reportActionID,
reportActionID: newestReportActions[reportID],
};

API.read(READ_COMMANDS.GET_NEWER_ACTIONS, parameters, {optimisticData, successData, failureData});
Expand Down
7 changes: 3 additions & 4 deletions src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function ReportActionsView(props) {
return;
}
// Retrieve the next REPORT.ACTIONS.LIMIT sized page of comments
Report.getOlderActions(reportID, oldestReportAction.reportActionID);
Report.getOlderActions(reportID);
}, [props.isLoadingOlderReportActions, props.network.isOffline, oldestReportAction, reportID]);

/**
Expand Down Expand Up @@ -223,10 +223,9 @@ function ReportActionsView(props) {
return;
}

const newestReportAction = _.first(props.reportActions);
Report.getNewerActions(reportID, newestReportAction.reportActionID);
Report.getNewerActions(reportID);
}, 500),
[props.isLoadingNewerReportActions, props.isLoadingInitialReportActions, props.reportActions, reportID, hasNewestReportAction],
[props.isLoadingNewerReportActions, props.isLoadingInitialReportActions, reportID, hasNewestReportAction],
);

/**
Expand Down

0 comments on commit 4f224f4

Please sign in to comment.