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

Align default IDs in ReportScreen file #55074

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
1 change: 0 additions & 1 deletion .eslintrc.changed.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ module.exports = {
files: [
'src/libs/actions/IOU.ts',
'src/libs/actions/Report.ts',
'src/pages/home/ReportScreen.tsx',
'src/pages/workspace/WorkspaceInitialPage.tsx',
'src/pages/home/report/PureReportActionItem.tsx',
'src/libs/SidebarUtils.ts',
Expand Down
26 changes: 22 additions & 4 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ const ROUTES = {
REPORT: 'r',
REPORT_WITH_ID: {
route: 'r/:reportID?/:reportActionID?',
getRoute: (reportID: string, reportActionID?: string, referrer?: string) => {
getRoute: (reportID: string | undefined, reportActionID?: string, referrer?: string) => {
if (!reportID) {
Log.warn('Invalid reportID is used to build the REPORT_WITH_ID route');
}
const baseRoute = reportActionID ? (`r/${reportID}/${reportActionID}` as const) : (`r/${reportID}` as const);
const referrerParam = referrer ? `?referrer=${encodeURIComponent(referrer)}` : '';
return `${baseRoute}${referrerParam}` as const;
Expand Down Expand Up @@ -363,7 +366,12 @@ const ROUTES = {
},
REPORT_WITH_ID_DETAILS: {
route: 'r/:reportID/details',
getRoute: (reportID: string | undefined, backTo?: string) => getUrlWithBackToParam(`r/${reportID}/details`, backTo),
getRoute: (reportID: string | undefined, backTo?: string) => {
if (!reportID) {
Log.warn('Invalid reportID is used to build the REPORT_WITH_ID_DETAILS route');
}
return getUrlWithBackToParam(`r/${reportID}/details`, backTo);
},
},
REPORT_WITH_ID_DETAILS_EXPORT: {
route: 'r/:reportID/details/export/:connectionName',
Expand Down Expand Up @@ -399,7 +407,12 @@ const ROUTES = {
},
REPORT_DESCRIPTION: {
route: 'r/:reportID/description',
getRoute: (reportID: string | undefined, backTo?: string) => getUrlWithBackToParam(`r/${reportID}/description` as const, backTo),
getRoute: (reportID: string | undefined, backTo?: string) => {
if (!reportID) {
Log.warn('Invalid reportID is used to build the REPORT_DESCRIPTION route');
}
return getUrlWithBackToParam(`r/${reportID}/description` as const, backTo);
},
},
TASK_ASSIGNEE: {
route: 'r/:reportID/assignee',
Expand Down Expand Up @@ -896,7 +909,12 @@ const ROUTES = {
},
WORKSPACE_PROFILE_DESCRIPTION: {
route: 'settings/workspaces/:policyID/profile/description',
getRoute: (policyID: string | undefined) => `settings/workspaces/${policyID}/profile/description` as const,
getRoute: (policyID: string | undefined) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the WORKSPACE_PROFILE_DESCRIPTION route');
}
return `settings/workspaces/${policyID}/profile/description` as const;
},
},
WORKSPACE_PROFILE_SHARE: {
route: 'settings/workspaces/:policyID/profile/share',
Expand Down
15 changes: 7 additions & 8 deletions src/hooks/usePaginatedReportActions.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import {useMemo} from 'react';
import {useOnyx} from 'react-native-onyx';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import PaginationUtils from '@libs/PaginationUtils';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';

Check failure on line 5 in src/hooks/usePaginatedReportActions.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import * as ReportUtils from '@libs/ReportUtils';

Check failure on line 6 in src/hooks/usePaginatedReportActions.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import ONYXKEYS from '@src/ONYXKEYS';

/**
* Get the longest continuous chunk of reportActions including the linked reportAction. If not linking to a specific action, returns the continuous chunk of newest reportActions.
*/
function usePaginatedReportActions(reportID?: string, reportActionID?: string) {
// Use `||` instead of `??` to handle empty string.
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const reportIDWithDefault = reportID || '-1';
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDWithDefault}`);
function usePaginatedReportActions(reportID: string | undefined, reportActionID?: string) {
const nonEmptyStringReportID = getNonEmptyStringOnyxID(reportID);
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${nonEmptyStringReportID}`);
const canUserPerformWriteAction = ReportUtils.canUserPerformWriteAction(report);

const [sortedAllReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportIDWithDefault}`, {
const [sortedAllReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${nonEmptyStringReportID}`, {
canEvict: false,
selector: (allReportActions) => ReportActionsUtils.getSortedReportActionsForDisplay(allReportActions, canUserPerformWriteAction, true),
});
const [reportActionPages] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_PAGES}${reportIDWithDefault}`);
const [reportActionPages] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_PAGES}${nonEmptyStringReportID}`);

const {
data: reportActions,
Expand All @@ -33,7 +32,7 @@
}, [reportActionID, reportActionPages, sortedAllReportActions]);

const linkedAction = useMemo(
() => sortedAllReportActions?.find((reportAction) => String(reportAction.reportActionID) === String(reportActionID)),
() => (reportActionID ? sortedAllReportActions?.find((reportAction) => String(reportAction.reportActionID) === String(reportActionID)) : undefined),
[reportActionID, sortedAllReportActions],
);

Expand Down
5 changes: 4 additions & 1 deletion src/libs/Notification/LocalNotification/index.desktop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ function showModifiedExpenseNotification(report: Report, reportAction: ReportAct
BrowserNotifications.pushModifiedExpenseNotification(report, reportAction, onClick);
}

function clearReportNotifications(reportID: string) {
function clearReportNotifications(reportID: string | undefined) {
if (!reportID) {
return;
}
BrowserNotifications.clearNotifications((notificationData) => notificationData.reportID === reportID);
VickyStash marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
5 changes: 4 additions & 1 deletion src/libs/Notification/LocalNotification/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ function showModifiedExpenseNotification(report: Report, reportAction: ReportAct
BrowserNotifications.pushModifiedExpenseNotification(report, reportAction, onClick, true);
}

function clearReportNotifications(reportID: string) {
function clearReportNotifications(reportID: string | undefined) {
VickyStash marked this conversation as resolved.
Show resolved Hide resolved
if (!reportID) {
return;
}
BrowserNotifications.clearNotifications((notificationData) => notificationData.reportID === reportID);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ const parseNotificationAndReportIDs = (pushPayload: PushPayload) => {
};
};

const clearReportNotifications: ClearReportNotifications = (reportID: string) => {
const clearReportNotifications: ClearReportNotifications = (reportID: string | undefined) => {
Log.info('[PushNotification] clearing report notifications', false, {reportID});

if (!reportID) {
return;
}

Airship.push
.getActiveNotifications()
.then((pushPayloads) => {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Notification/clearReportNotifications/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
type ClearReportNotifications = (reportID: string) => void;
type ClearReportNotifications = (reportID: string | undefined) => void;

export default ClearReportNotifications;
4 changes: 2 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7487,8 +7487,8 @@ function isReportDataReady(): boolean {
/**
* Return true if reportID from path is valid
*/
function isValidReportIDFromPath(reportIDFromPath: string): boolean {
return !['', 'null', '0', '-1'].includes(reportIDFromPath);
function isValidReportIDFromPath(reportIDFromPath: string | undefined): boolean {
return !!reportIDFromPath && !['', 'null', 'undefined', '0', '-1'].includes(reportIDFromPath);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ function subscribeToReportTypingEvents(reportID: string) {
}

/** Initialize our pusher subscriptions to listen for someone leaving a room. */
function subscribeToReportLeavingEvents(reportID: string) {
function subscribeToReportLeavingEvents(reportID: string | undefined) {
if (!reportID) {
return;
}
Expand Down
6 changes: 6 additions & 0 deletions src/libs/getNonEmptyStringOnyxID.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** Make sure the id is not an empty string as it can break an onyx key */
export default function getNonEmptyStringOnyxID(onyxID: string | undefined): string | undefined {
// The onyx ID is used inside the onyx key. If it's an empty string, onyx will return
// a collection instead of an individual item, which is not an expected behaviour.
return onyxID !== '' ? onyxID : undefined;
}
11 changes: 5 additions & 6 deletions src/pages/home/HeaderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import usePolicy from '@hooks/usePolicy';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import Navigation from '@libs/Navigation/Navigation';
import {getPersonalDetailsForAccountIDs} from '@libs/OptionsListUtils';
import Parser from '@libs/Parser';
Expand Down Expand Up @@ -76,7 +77,7 @@ type HeaderViewProps = {
parentReportAction: OnyxEntry<ReportAction> | null;

/** The reportID of the current report */
reportID: string;
reportID: string | undefined;

/** Whether we should display the header as in narrow layout */
shouldUseNarrowLayout?: boolean;
Expand All @@ -94,11 +95,9 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked,
const {isSmallScreenWidth} = useResponsiveLayout();
const route = useRoute();
const [isDeleteTaskConfirmModalVisible, setIsDeleteTaskConfirmModalVisible] = React.useState(false);
const [invoiceReceiverPolicy] = useOnyx(
`${ONYXKEYS.COLLECTION.POLICY}${report?.invoiceReceiver && 'policyID' in report.invoiceReceiver ? report.invoiceReceiver.policyID : CONST.DEFAULT_NUMBER_ID}`,
);
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID || report?.reportID || CONST.DEFAULT_NUMBER_ID}`);
const invoiceReceiverPolicyID = report?.invoiceReceiver && 'policyID' in report.invoiceReceiver ? report.invoiceReceiver.policyID : undefined;
const [invoiceReceiverPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${invoiceReceiverPolicyID}`);
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.parentReportID) ?? getNonEmptyStringOnyxID(report?.reportID)}`);
const policy = usePolicy(report?.policyID);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);

Expand Down
Loading
Loading