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

[CP Staging] Default to -1 in report header details #44562

Merged
merged 4 commits into from
Jun 27, 2024
Merged
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
const {translate} = useLocalize();
const {isOffline} = useNetwork();
const styles = useThemeStyles();
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID ?? '-1'}`);
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID || '-1'}`);

Check failure on line 82 in src/pages/ReportDetailsPage.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should disable the lint rule here @mountiny

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, thank you!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this instead of disabling the rule?

Suggested change
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID || '-1'}`);
const parentReportID = report.parentReportID ?? '-1';
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${parentReportID === '-1' ? parentReportID : report.parentReportID}`);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do, but I think it has to be parentReportID === '' ? parentReportID : report.parentReportID

This comment was marked as outdated.

Copy link
Contributor

@allgandalf allgandalf Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait no vit,

const parentReportID = report.parentReportID ?? '-1';

This would mean that the fallback would be -1 a string and not empty string.

Implying parentReportID === '' ? parentReportID would never be true

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay maybe this is indeed becoming more confusing to read than just dismissing that stupid rule. 🙄

My bad! 😅 - let's just go back to dismissing the rule I apologize.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

want the next commit on my name then 🌚

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would work I think, but getting headache from it so happy to use the rule exception

const [sortedAllReportActions = []] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID ?? '-1'}`, {
canEvict: false,
selector: (allReportActions: OnyxEntry<OnyxTypes.ReportActions>) => ReportActionsUtils.getSortedReportActionsForDisplay(allReportActions, true),
Expand Down
Loading