-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[ML] Fixes getTab() to always return an array. #45616
Conversation
Pinging @elastic/ml-ui |
data_frames: [], | ||
data_frame_analytics: [], | ||
export function getTabs(tabId: TabId, disableLinks: boolean): Tab[] { | ||
const TAB_MAP: Partial<Record<TabId, Tab[]>> = { |
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 quite liked having the other main tabs listed here, even though they are empty, because it explicitly states that those tabs have no sub tabs.
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.
Added back in a90916d.
datavisualizer: [], | ||
data_frames: [], | ||
data_frame_analytics: [], | ||
export function getTabs(tabId: TabId, disableLinks: boolean): Tab[] { |
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.
maybe this whole function should be a switch
rather than a map which we then have to work around?
That way, all main tabs which have no sub tabs could be caught and fall through to returning []
and all unexpected tab ids would be caught by the default
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'll leave that to a possible follow up. Since getTabs()
itself returns []
in cases where tabId
is something that's not part of TAB_MAP
there's no work-around needed when .map()
is used later on.
💚 Build Succeeded |
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.
LGTM
💚 Build Succeeded |
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.
Thanks for the fix, @walterra 🙌
- Fixes getTabs() to always return an array. I was wondering why TypeScript didn't flag the tabs.map(...) part because tabs could possibly be undefined. It's because Record assumes that every key exists. More on that can be found in this blog post. - This PR fixes a) the type of TAB_MAP by wrapping it in Partial<...> so it correctly flags the tabs.map() part with tabs possibly being undefined and b) fixes getTabs()'s return value by always returning an array.
- Fixes getTabs() to always return an array. I was wondering why TypeScript didn't flag the tabs.map(...) part because tabs could possibly be undefined. It's because Record assumes that every key exists. More on that can be found in this blog post. - This PR fixes a) the type of TAB_MAP by wrapping it in Partial<...> so it correctly flags the tabs.map() part with tabs possibly being undefined and b) fixes getTabs()'s return value by always returning an array.
Summary
Fixes #45612.
Fixes
getTabs()
to always return an array. I was wondering why TypeScript didn't flag thetabs.map(...)
part becausetabs
could possibly beundefined
. It's becauseRecord
assumes that every key exists. More on that can be found in this blog post.This PR fixes a) the type of
TAB_MAP
by wrapping it inPartial<...>
so it correctly flags thetabs.map()
part withtabs
possibly being undefined and b) fixesgetTabs()
's return value by always returning an array.Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.This was checked for cross-browser compatibility, including a check against IE11no DOM changesAny text added follows EUI's writing guidelines, uses sentence case text and includes i18n supportDocumentation was added for features that require explanation or tutorialsThis was checked for keyboard-only and screenreader accessibilityFor maintainers