-
Notifications
You must be signed in to change notification settings - Fork 272
♻️ (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
base: main
Are you sure you want to change the base?
Conversation
Use a map to make the code more readable
Minor nitpick. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
}[target] | ||
|
There was a problem hiding this comment.
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.
}[target] | |
}[target] ?? t('Unknown'); |
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or
}[target] | |
const title = { | |
[DocDefaultFilter.MY_DOCS]: t('My docs'), | |
[DocDefaultFilter.SHARED_WITH_ME]: t('Shared with me'), | |
}[target] ?? t('All docs'); |
Use a map to make the code more readable
Purpose
Make the code more readable by simplifying conditional logic.
Proposal
Replaced nested ternary expressions with a mapping object to improve readability and maintainability.