Skip to content

Commit

Permalink
Use getNonEmptyStringOnyxID instead of getNonEmptyStringReportID
Browse files Browse the repository at this point in the history
  • Loading branch information
VickyStash committed Jan 14, 2025
1 parent 590070f commit ee611e6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/hooks/usePaginatedReportActions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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"
Expand All @@ -9,7 +10,7 @@ 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) {
const nonEmptyStringReportID = ReportUtils.getNonEmptyStringReportID(reportID);
const nonEmptyStringReportID = getNonEmptyStringOnyxID(reportID);
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${nonEmptyStringReportID}`);
const canUserPerformWriteAction = ReportUtils.canUserPerformWriteAction(report);

Expand Down
8 changes: 0 additions & 8 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8804,13 +8804,6 @@ function getReportMetadata(reportID: string | undefined) {
return reportID ? allReportMetadataKeyValue[reportID] : undefined;
}

/** Make sure the report id is not an empty string as it can break an onyx key */
function getNonEmptyStringReportID(reportID: string | undefined): string | undefined {
// 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 reportID !== '' ? reportID : undefined;
}

export {
addDomainToShortMention,
completeShortMention,
Expand Down Expand Up @@ -9139,7 +9132,6 @@ export {
shouldUnmaskChat,
getReportMetadata,
buildOptimisticSelfDMReport,
getNonEmptyStringReportID,
isHiddenForCurrentUser,
};

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

Check failure on line 3 in src/libs/getNonEmptyStringOnyxID.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Insert `··`
// a collection instead of an individual item, which is not an expected behaviour.

Check failure on line 4 in src/libs/getNonEmptyStringOnyxID.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Replace `··` with `····`
return onyxID !== '' ? onyxID : undefined;

Check failure on line 5 in src/libs/getNonEmptyStringOnyxID.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Insert `··`
}
5 changes: 2 additions & 3 deletions src/pages/home/HeaderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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 * as OptionsListUtils from '@libs/OptionsListUtils';

Check failure on line 30 in src/pages/home/HeaderView.tsx

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 Parser from '@libs/Parser';
Expand Down Expand Up @@ -71,9 +72,7 @@ function HeaderView({report, parentReportAction, reportID, onNavigationMenuButto
const route = useRoute();
const [isDeleteTaskConfirmModalVisible, setIsDeleteTaskConfirmModalVisible] = React.useState(false);
const [invoiceReceiverPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.invoiceReceiver && 'policyID' in report.invoiceReceiver ? report.invoiceReceiver.policyID : undefined}`);
const [parentReport] = useOnyx(
`${ONYXKEYS.COLLECTION.REPORT}${ReportUtils.getNonEmptyStringReportID(report?.parentReportID) ?? ReportUtils.getNonEmptyStringReportID(report?.reportID)}`,
);
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
7 changes: 4 additions & 3 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import usePrevious from '@hooks/usePrevious';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import useViewportOffsetTop from '@hooks/useViewportOffsetTop';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
Expand Down Expand Up @@ -92,7 +93,7 @@ function getParentReportAction(parentReportActions: OnyxEntry<OnyxTypes.ReportAc
function ReportScreen({route, navigation}: ReportScreenProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const reportIDFromRoute = ReportUtils.getNonEmptyStringReportID(route.params?.reportID);
const reportIDFromRoute = getNonEmptyStringOnyxID(route.params?.reportID);
const reportActionIDFromRoute = route?.params?.reportActionID;
const isFocused = useIsFocused();
const prevIsFocused = usePrevious(isFocused);
Expand All @@ -109,14 +110,14 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
const [modal] = useOnyx(ONYXKEYS.MODAL);
const [isComposerFullSize] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportIDFromRoute}`, {initialValue: false});
const [accountManagerReportID] = useOnyx(ONYXKEYS.ACCOUNT_MANAGER_REPORT_ID);
const [accountManagerReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${ReportUtils.getNonEmptyStringReportID(accountManagerReportID)}`);
const [accountManagerReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(accountManagerReportID)}`);
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);
const [parentReportAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${ReportUtils.getNonEmptyStringReportID(reportOnyx?.parentReportID)}`, {
const [parentReportAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getNonEmptyStringOnyxID(reportOnyx?.parentReportID)}`, {
canEvict: false,
selector: (parentReportActions) => getParentReportAction(parentReportActions, reportOnyx?.parentReportActionID),
});
Expand Down

0 comments on commit ee611e6

Please sign in to comment.