Skip to content

♻️ (frontend) Make the code more readable by simplifying conditional logic #844

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ export const DocsGrid = ({
void fetchNextPage();
};

const title =
target === DocDefaultFilter.MY_DOCS
? t('My docs')
: target === DocDefaultFilter.SHARED_WITH_ME
? t('Shared with me')
: t('All docs');
const title = {
[DocDefaultFilter.MY_DOCS]: t('My docs'),
[DocDefaultFilter.SHARED_WITH_ME]: t('Shared with me'),
[DocDefaultFilter.ALL_DOCS]: t('All docs'),
}[target]

Comment on lines +53 to 54
Copy link
Preview

Copilot AI Apr 6, 2025

Choose a reason for hiding this comment

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

Directly indexing the mapping with [target] assumes that target always matches one of the map keys. Consider adding a default fallback (e.g., using the nullish coalescing operator) to prevent 'title' from being undefined for unexpected target values.

Suggested change
}[target]
}[target] ?? t('Unknown');

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Copy link
Member

Choose a reason for hiding this comment

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

It was just to test how copilot does a review 🙂

Maybe based on the suggestion uses t('All docs') than t('Unknown'). WDYT @AntoLC ?

Copy link
Author

Choose a reason for hiding this comment

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

i would keep it the way it is.

if someone where to add another key to the enum DocDefaultFilter, typescript will raise an error which will force the addition of a new key to the translation map

Copy link
Author

Choose a reason for hiding this comment

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

or

Suggested change
}[target]
const title = {
[DocDefaultFilter.MY_DOCS]: t('My docs'),
[DocDefaultFilter.SHARED_WITH_ME]: t('Shared with me'),
}[target] ?? t('All docs');

return (
<Box
Expand Down