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

Include filtered actions when computing oldest and newest reportAction on a report #37839

Merged
merged 8 commits into from
Mar 6, 2024
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
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
Loading