Skip to content
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
14 changes: 6 additions & 8 deletions src/components/ParentNavigationSubtitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import React from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import {getReportAction, shouldReportActionBeVisible} from '@libs/ReportActionsUtils';
import {canUserPerformWriteAction as canUserPerformWriteActionReportUtils} from '@libs/ReportUtils';
import CONST from '@src/CONST';
import type {ParentNavigationSummaryParams} from '@src/languages/params';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -30,10 +29,9 @@ type ParentNavigationSubtitleProps = {
function ParentNavigationSubtitle({parentNavigationSubtitleData, parentReportActionID, parentReportID = '', pressableStyles}: ParentNavigationSubtitleProps) {
const styles = useThemeStyles();
const {workspaceName, reportName} = parentNavigationSubtitleData;
const {isOffline} = useNetwork();
const {translate} = useLocalize();
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`);
const canUserPerformWriteAction = ReportUtils.canUserPerformWriteAction(report);
const canUserPerformWriteAction = canUserPerformWriteActionReportUtils(report);

// We should not display the parent navigation subtitle if the user does not have access to the parent chat (the reportName is empty in this case)
if (!reportName) {
Expand All @@ -43,11 +41,11 @@ function ParentNavigationSubtitle({parentNavigationSubtitleData, parentReportAct
return (
<PressableWithoutFeedback
onPress={() => {
const parentAction = ReportActionsUtils.getReportAction(parentReportID, parentReportActionID ?? '-1');
const isVisibleAction = ReportActionsUtils.shouldReportActionBeVisible(parentAction, parentAction?.reportActionID ?? '-1', canUserPerformWriteAction);
const parentAction = getReportAction(parentReportID, parentReportActionID);
const isVisibleAction = shouldReportActionBeVisible(parentAction, parentAction?.reportActionID ?? CONST.DEFAULT_NUMBER_ID, canUserPerformWriteAction);
// Pop the thread report screen before navigating to the chat report.
Navigation.goBack(ROUTES.REPORT_WITH_ID.getRoute(parentReportID));
if (isVisibleAction && !isOffline) {
if (isVisibleAction) {
// Pop the chat report screen before navigating to the linked report action.
Navigation.goBack(ROUTES.REPORT_WITH_ID.getRoute(parentReportID, parentReportActionID), true);
}
Expand Down
3 changes: 2 additions & 1 deletion src/libs/PaginationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ function getContinuousChain<TResource>(
id?: string,
): {data: TResource[]; hasNextPage: boolean; hasPreviousPage: boolean} {
if (pages.length === 0) {
return {data: id ? [] : sortedItems, hasNextPage: false, hasPreviousPage: false};
const dataItem = sortedItems.find((item) => getID(item) === id);
return {data: id && !dataItem ? [] : sortedItems, hasNextPage: false, hasPreviousPage: false};
}

const pagesWithIndexes = getPagesWithIndexes(sortedItems, pages, getID);
Expand Down
18 changes: 6 additions & 12 deletions src/pages/home/report/ThreadDivider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import * as Expensicons from '@components/Icon/Expensicons';
import {PressableWithoutFeedback} from '@components/Pressable';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import {shouldReportActionBeVisible} from '@libs/ReportActionsUtils';
import {canUserPerformWriteAction} from '@libs/ReportUtils';
import type {Ancestor} from '@libs/ReportUtils';
import * as ReportUtils from '@libs/ReportUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
Expand All @@ -28,7 +27,6 @@ function ThreadDivider({ancestor, isLinkDisabled = false}: ThreadDividerProps) {
const styles = useThemeStyles();
const theme = useTheme();
const {translate} = useLocalize();
const {isOffline} = useNetwork();

return (
<View
Expand All @@ -48,16 +46,12 @@ function ThreadDivider({ancestor, isLinkDisabled = false}: ThreadDividerProps) {
) : (
<PressableWithoutFeedback
onPress={() => {
const isVisibleAction = ReportActionsUtils.shouldReportActionBeVisible(
ancestor.reportAction,
ancestor.reportAction.reportActionID ?? '-1',
ReportUtils.canUserPerformWriteAction(ancestor.report),
);
const isVisibleAction = shouldReportActionBeVisible(ancestor.reportAction, ancestor.reportAction.reportActionID, canUserPerformWriteAction(ancestor.report));
// Pop the thread report screen before navigating to the chat report.
Navigation.goBack(ROUTES.REPORT_WITH_ID.getRoute(ancestor.report.reportID ?? '-1'));
if (isVisibleAction && !isOffline) {
Navigation.goBack(ROUTES.REPORT_WITH_ID.getRoute(ancestor.report.reportID));
if (isVisibleAction) {
// Pop the chat report screen before navigating to the linked report action.
Navigation.goBack(ROUTES.REPORT_WITH_ID.getRoute(ancestor.report.reportID ?? '-1', ancestor.reportAction.reportActionID));
Navigation.goBack(ROUTES.REPORT_WITH_ID.getRoute(ancestor.report.reportID, ancestor.reportAction.reportActionID));
}
}}
accessibilityLabel={translate('threads.thread')}
Expand Down
27 changes: 25 additions & 2 deletions tests/unit/PaginationUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ describe('PaginationUtils', () => {
expect(result.hasNextPage).toBe(false);
});

it('given an input ID and the report only contains pending actions, it will return an empty array', () => {
it('given an input ID and the report only contains pending actions, it will return all actions', () => {
const input = createItems([
// Given these sortedItems
'7',
Expand All @@ -178,8 +178,31 @@ describe('PaginationUtils', () => {
const pages: Pages = [];

// Expect these sortedItems
const expectedResult: Item[] = [];
const expectedResult = [...input];
const result = PaginationUtils.getContinuousChain(input, pages, getID, '4');
// Expect the result to be the same
expect(result.data).toStrictEqual(expectedResult);
expect(result.hasPreviousPage).toBe(false);
expect(result.hasNextPage).toBe(false);
});

it('given an input ID of 8 which does not exist in Onyx and the report only contains pending actions, it will return an empty array', () => {
const input = createItems([
// Given these sortedItems
'7',
'6',
'5',
'4',
'3',
'2',
'1',
]);

const pages: Pages = [];

// Expect these sortedItems
const expectedResult: Item[] = [];
const result = PaginationUtils.getContinuousChain(input, pages, getID, '8');
expect(result.data).toStrictEqual(expectedResult);
expect(result.hasPreviousPage).toBe(false);
expect(result.hasNextPage).toBe(false);
Expand Down