Skip to content

Commit 57cd25a

Browse files
authored
Merge pull request #32474 from s-alves10/fix/issue-31637
fix: hide pending deleted actions
2 parents 0e99676 + 22eca2a commit 57cd25a

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/libs/ReportActionsUtils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ function shouldReportActionBeVisible(reportAction: OnyxEntry<ReportAction>, key:
375375

376376
// All other actions are displayed except thread parents, deleted, or non-pending actions
377377
const isDeleted = isDeletedAction(reportAction);
378-
const isPending = !!reportAction.pendingAction;
378+
const isPending = !!reportAction.pendingAction && !(!isNetworkOffline && reportAction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);
379379
return !isDeleted || isPending || isDeletedParentAction(reportAction) || isReversedTransaction(reportAction);
380380
}
381381

src/pages/home/ReportScreen.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import TaskHeaderActionButton from '@components/TaskHeaderActionButton';
1616
import withCurrentReportID, {withCurrentReportIDDefaultProps, withCurrentReportIDPropTypes} from '@components/withCurrentReportID';
1717
import withViewportOffsetTop from '@components/withViewportOffsetTop';
1818
import useLocalize from '@hooks/useLocalize';
19+
import useNetwork from '@hooks/useNetwork';
1920
import usePrevious from '@hooks/usePrevious';
2021
import useWindowDimensions from '@hooks/useWindowDimensions';
2122
import compose from '@libs/compose';
@@ -152,6 +153,7 @@ function ReportScreen({
152153
const styles = useThemeStyles();
153154
const {translate} = useLocalize();
154155
const {isSmallScreenWidth} = useWindowDimensions();
156+
const {isOffline} = useNetwork();
155157

156158
const firstRenderRef = useRef(true);
157159
const flatListRef = useRef();
@@ -166,8 +168,11 @@ function ReportScreen({
166168
const {addWorkspaceRoomOrChatPendingAction, addWorkspaceRoomOrChatErrors} = ReportUtils.getReportOfflinePendingActionAndErrors(report);
167169
const screenWrapperStyle = [styles.appContent, styles.flex1, {marginTop: viewportOffsetTop}];
168170

171+
// eslint-disable-next-line react-hooks/exhaustive-deps -- need to re-filter the report actions when network status changes
172+
const filteredReportActions = useMemo(() => ReportActionsUtils.getSortedReportActionsForDisplay(reportActions, true), [isOffline, reportActions]);
173+
169174
// There are no reportActions at all to display and we are still in the process of loading the next set of actions.
170-
const isLoadingInitialReportActions = _.isEmpty(reportActions) && reportMetadata.isLoadingInitialReportActions;
175+
const isLoadingInitialReportActions = _.isEmpty(filteredReportActions) && reportMetadata.isLoadingInitialReportActions;
171176

172177
const isOptimisticDelete = lodashGet(report, 'statusNum') === CONST.REPORT.STATUS.CLOSED;
173178

@@ -422,7 +427,7 @@ function ReportScreen({
422427
>
423428
{isReportReadyForDisplay && !isLoadingInitialReportActions && !isLoading && (
424429
<ReportActionsView
425-
reportActions={reportActions}
430+
reportActions={filteredReportActions}
426431
report={report}
427432
isLoadingInitialReportActions={reportMetadata.isLoadingInitialReportActions}
428433
isLoadingNewerReportActions={reportMetadata.isLoadingNewerReportActions}
@@ -440,7 +445,7 @@ function ReportScreen({
440445
{isReportReadyForDisplay ? (
441446
<ReportFooter
442447
pendingAction={addWorkspaceRoomOrChatPendingAction}
443-
reportActions={reportActions}
448+
reportActions={filteredReportActions}
444449
report={report}
445450
isComposerFullSize={isComposerFullSize}
446451
onSubmitComment={onSubmitComment}
@@ -475,7 +480,6 @@ export default compose(
475480
reportActions: {
476481
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getReportID(route)}`,
477482
canEvict: false,
478-
selector: (reportActions) => ReportActionsUtils.getSortedReportActionsForDisplay(reportActions, true),
479483
},
480484
report: {
481485
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${getReportID(route)}`,

tests/unit/ReportActionsUtilsTest.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ describe('ReportActionsUtils', () => {
288288
expect(result).toStrictEqual(input);
289289
});
290290

291-
it('should filter out deleted, non-pending comments', () => {
291+
it('should filter out deleted and delete-pending comments', () => {
292292
const input = [
293293
{
294294
created: '2022-11-13 22:27:01.825',
@@ -312,6 +312,7 @@ describe('ReportActionsUtils', () => {
312312
];
313313
const result = ReportActionsUtils.getSortedReportActionsForDisplay(input);
314314
input.pop();
315+
input.pop();
315316
expect(result).toStrictEqual(input);
316317
});
317318
});

0 commit comments

Comments
 (0)