Skip to content

Commit

Permalink
use defaut value from const
Browse files Browse the repository at this point in the history
  • Loading branch information
christianwen committed Dec 17, 2024
1 parent 8b8510b commit 7c602dc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
32 changes: 16 additions & 16 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const defaultReportMetadata = {
function getReportID(route: ReportScreenNavigationProps['route']): string {
// The report ID is used in an onyx key. If it's an empty string, onyx will return
// a collection instead of an individual report.
return String(route.params?.reportID || 0);
return String(route.params?.reportID || CONST.DEFAULT_NUMBER_ID);
}

/**
Expand All @@ -94,14 +94,14 @@ function getParentReportAction(parentReportActions: OnyxEntry<OnyxTypes.ReportAc
if (!parentReportActions || !parentReportActionID) {
return;
}
return parentReportActions[parentReportActionID ?? '0'];
return parentReportActions[parentReportActionID ?? CONST.DEFAULT_NUMBER_ID];
}

function ReportScreen({route, currentReportID = '', navigation}: ReportScreenProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const reportIDFromRoute = getReportID(route);
const reportActionIDFromRoute = route?.params?.reportActionID ?? '';
const reportActionIDFromRoute = route?.params?.reportActionID ?? CONST.DEFAULT_NUMBER_ID;
const isFocused = useIsFocused();
const prevIsFocused = usePrevious(isFocused);
const firstRenderRef = useRef(true);
Expand All @@ -118,17 +118,17 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
const [accountManagerReportID] = useOnyx(ONYXKEYS.ACCOUNT_MANAGER_REPORT_ID, {initialValue: ''});
// If accountManagerReportID is an empty string, using ?? can crash the app.
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [accountManagerReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${accountManagerReportID || '-1'}`);
const [accountManagerReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${accountManagerReportID || CONST.DEFAULT_NUMBER_ID}`);
const [userLeavingStatus] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_USER_IS_LEAVING_ROOM}${reportIDFromRoute}`, {initialValue: false});
const [reportOnyx, reportResult] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`, {allowStaleData: true});
const [reportMetadata = defaultReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportIDFromRoute}`, {initialValue: defaultReportMetadata});
const [isSidebarLoaded] = useOnyx(ONYXKEYS.IS_SIDEBAR_LOADED, {initialValue: false});
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, initialValue: {}});
const [betas] = useOnyx(ONYXKEYS.BETAS);
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [parentReportAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportOnyx?.parentReportID || -1}`, {
const [parentReportAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportOnyx?.parentReportID || CONST.DEFAULT_NUMBER_ID}`, {
canEvict: false,
selector: (parentReportActions) => getParentReportAction(parentReportActions, reportOnyx?.parentReportActionID ?? ''),
selector: (parentReportActions) => getParentReportAction(parentReportActions, reportOnyx?.parentReportActionID ?? CONST.DEFAULT_NUMBER_ID),

Check failure on line 131 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type 'string | 0' is not assignable to parameter of type 'string | undefined'.
});
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP);
const wasLoadingApp = usePrevious(isLoadingApp);
Expand Down Expand Up @@ -189,7 +189,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
() =>
reportOnyx && {
lastReadTime: reportOnyx.lastReadTime,
reportID: reportOnyx.reportID ?? '',
reportID: reportOnyx.reportID ?? CONST.DEFAULT_NUMBER_ID,
policyID: reportOnyx.policyID,
lastVisibleActionCreated: reportOnyx.lastVisibleActionCreated,
statusNum: reportOnyx.statusNum,
Expand Down Expand Up @@ -272,12 +272,12 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
const hasHelpfulErrors = Object.keys(report?.errorFields ?? {}).some((key) => key !== 'notFound');
const shouldHideReport = !hasHelpfulErrors && !ReportUtils.canAccessReport(report, policies, betas);

const transactionThreadReportID = ReportActionsUtils.getOneTransactionThreadReportID(reportID ?? '', reportActions ?? [], isOffline);
const transactionThreadReportID = ReportActionsUtils.getOneTransactionThreadReportID(reportID ?? CONST.DEFAULT_NUMBER_ID, reportActions ?? [], isOffline);

Check failure on line 275 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type 'string | 0' is not assignable to parameter of type 'string'.
const [transactionThreadReportActions = {}] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`);
const combinedReportActions = ReportActionsUtils.getCombinedReportActions(reportActions, transactionThreadReportID ?? null, Object.values(transactionThreadReportActions));
const lastReportAction = [...combinedReportActions, parentReportAction].find((action) => ReportUtils.canEditReportAction(action) && !ReportActionsUtils.isMoneyRequestAction(action));
const isSingleTransactionView = ReportUtils.isMoneyRequest(report) || ReportUtils.isTrackExpenseReport(report);
const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID ?? '-1'}`];
const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID ?? CONST.DEFAULT_NUMBER_ID}`];
const isTopMostReportId = currentReportID === reportIDFromRoute;
const didSubscribeToReportLeavingEvents = useRef(false);
const [showSoftInputOnFocus, setShowSoftInputOnFocus] = useState(false);
Expand Down Expand Up @@ -320,7 +320,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
}

useEffect(() => {
if (!transactionThreadReportID || !route?.params?.reportActionID || !ReportUtils.isOneTransactionThread(linkedAction?.childReportID ?? '-1', reportID ?? '', linkedAction)) {
if (!transactionThreadReportID || !route?.params?.reportActionID || !ReportUtils.isOneTransactionThread(linkedAction?.childReportID ?? CONST.DEFAULT_NUMBER_ID, reportID ?? CONST.DEFAULT_NUMBER_ID, linkedAction)) {

Check failure on line 323 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Replace `!transactionThreadReportID·||·!route?.params?.reportActionID·||·!ReportUtils.isOneTransactionThread(linkedAction?.childReportID·??·CONST.DEFAULT_NUMBER_ID,·reportID·??·CONST.DEFAULT_NUMBER_ID,·linkedAction)` with `⏎············!transactionThreadReportID·||⏎············!route?.params?.reportActionID·||⏎············!ReportUtils.isOneTransactionThread(linkedAction?.childReportID·??·CONST.DEFAULT_NUMBER_ID,·reportID·??·CONST.DEFAULT_NUMBER_ID,·linkedAction)⏎········`

Check failure on line 323 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Replace `!transactionThreadReportID·||·!route?.params?.reportActionID·||·!ReportUtils.isOneTransactionThread(linkedAction?.childReportID·??·CONST.DEFAULT_NUMBER_ID,·reportID·??·CONST.DEFAULT_NUMBER_ID,·linkedAction)` with `⏎············!transactionThreadReportID·||⏎············!route?.params?.reportActionID·||⏎············!ReportUtils.isOneTransactionThread(linkedAction?.childReportID·??·CONST.DEFAULT_NUMBER_ID,·reportID·??·CONST.DEFAULT_NUMBER_ID,·linkedAction)⏎········`

Check failure on line 323 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type 'string | 0' is not assignable to parameter of type 'string'.
return;
}
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(route?.params?.reportID));
Expand Down Expand Up @@ -501,7 +501,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
}, []);

const chatWithAccountManager = useCallback(() => {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(accountManagerReportID ?? ''));
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(accountManagerReportID ?? CONST.DEFAULT_NUMBER_ID));

Check failure on line 504 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type 'string | 0' is not assignable to parameter of type 'string'.
}, [accountManagerReportID]);

// Clear notifications for the current report when it's opened and re-focused
Expand All @@ -511,7 +511,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
return;
}

clearReportNotifications(reportID ?? '');
clearReportNotifications(reportID ?? CONST.DEFAULT_NUMBER_ID);

Check failure on line 514 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type 'string | 0' is not assignable to parameter of type 'string'.
}, [reportID, isTopMostReportId]);

useEffect(clearNotifications, [clearNotifications]);
Expand All @@ -527,7 +527,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
return;
}

Report.unsubscribeFromLeavingRoomReportChannel(reportID ?? '');
Report.unsubscribeFromLeavingRoomReportChannel(reportID ?? CONST.DEFAULT_NUMBER_ID);

Check failure on line 530 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type 'string | 0' is not assignable to parameter of type 'string'.
};

// I'm disabling the warning, as it expects to use exhaustive deps, even though we want this useEffect to run only on the first render.
Expand Down Expand Up @@ -567,7 +567,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
) {
return;
}
Report.openReport(reportID ?? '');
Report.openReport(reportID ?? CONST.DEFAULT_NUMBER_ID);

Check failure on line 570 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type 'string | 0' is not assignable to parameter of type 'string'.

// We don't want to run this useEffect every time `report` is changed
// Excluding shouldUseNarrowLayout from the dependency list to prevent re-triggering on screen resize events.
Expand Down Expand Up @@ -731,7 +731,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
return;
}
// After creating the task report then navigating to task detail we don't have any report actions and the last read time is empty so We need to update the initial last read time when opening the task report detail.
Report.readNewestAction(report?.reportID ?? '');
Report.readNewestAction(report?.reportID ?? CONST.DEFAULT_NUMBER_ID);

Check failure on line 734 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type 'string | 0' is not assignable to parameter of type 'string'.
}, [report]);
const mostRecentReportAction = reportActions.at(0);
const isMostRecentReportIOU = mostRecentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU;
Expand Down Expand Up @@ -766,7 +766,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
navigation={navigation}
style={screenWrapperStyle}
shouldEnableKeyboardAvoidingView={(isTopMostReportId || isInNarrowPaneModal) && (!isComposerFocus || showSoftInputOnFocus)}
testID={`report-screen-${reportID ?? ''}`}
testID={`report-screen-${reportID ?? CONST.DEFAULT_NUMBER_ID}`}
>
<FullPageNotFoundView
shouldShow={shouldShowNotFoundPage}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ function ReportActionCompose({
// We are returning a callback here as we want to incoke the method on unmount only
useEffect(
() => () => {
if (!EmojiPickerActions.isActive(report?.reportID ?? '-1')) {
if (!EmojiPickerActions.isActive(report?.reportID ?? CONST.DEFAULT_NUMBER_ID)) {

Check failure on line 338 in src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type 'string | 0' is not assignable to parameter of type 'string'.
return;
}
EmojiPickerActions.hideEmojiPicker();
Expand Down Expand Up @@ -498,7 +498,7 @@ function ReportActionCompose({
isScrollLikelyLayoutTriggered={isScrollLikelyLayoutTriggered}
raiseIsScrollLikelyLayoutTriggered={raiseIsScrollLikelyLayoutTriggered}
reportID={reportID}
policyID={report?.policyID ?? '-1'}
policyID={report?.policyID ?? CONST.DEFAULT_NUMBER_ID}

Check failure on line 501 in src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Type 'string | 0' is not assignable to type 'string'.
includeChronos={ReportUtils.chatIncludesChronos(report)}
isGroupPolicyReport={isGroupPolicyReport}
lastReportAction={lastReportAction}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function ReportFooter({
}
},
});
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? -1}`);
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? CONST.DEFAULT_NUMBER_ID}`);

const chatFooterStyles = {...styles.chatFooter, minHeight: !isOffline ? CONST.CHAT_FOOTER_MIN_HEIGHT : 0};
const isArchivedRoom = ReportUtils.isArchivedRoom(report, reportNameValuePairs);
Expand Down

0 comments on commit 7c602dc

Please sign in to comment.