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

[ML] Fixes getTab() to always return an array. #45616

Merged
merged 2 commits into from
Sep 13, 2019

Conversation

walterra
Copy link
Contributor

Summary

Fixes #45612.

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.

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@walterra walterra added bug Fixes for quality problems that affect the customer experience regression :ml v8.0.0 Feature:Transforms ML transforms v7.5.0 backport:skip This commit does not require backporting labels Sep 13, 2019
@walterra walterra requested a review from a team as a code owner September 13, 2019 08:55
@walterra walterra self-assigned this Sep 13, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui

data_frames: [],
data_frame_analytics: [],
export function getTabs(tabId: TabId, disableLinks: boolean): Tab[] {
const TAB_MAP: Partial<Record<TabId, Tab[]>> = {
Copy link
Member

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.

Copy link
Contributor Author

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[] {
Copy link
Member

@jgowdyelastic jgowdyelastic Sep 13, 2019

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

Copy link
Contributor Author

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.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@peteharverson peteharverson added the release_note:skip Skip the PR/issue when compiling release notes label Sep 13, 2019
Copy link
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

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

LGTM

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@alvarezmelissa87 alvarezmelissa87 left a 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 🙌

@walterra walterra removed the backport:skip This commit does not require backporting label Sep 13, 2019
@walterra walterra merged commit ec5d1a9 into elastic:master Sep 13, 2019
@walterra walterra deleted the ml-fix-tabs branch September 13, 2019 12:39
walterra added a commit to walterra/kibana that referenced this pull request Sep 13, 2019
- 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.
walterra added a commit that referenced this pull request Sep 13, 2019
- 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:Transforms ML transforms :ml regression release_note:skip Skip the PR/issue when compiling release notes v7.5.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ML] Transforms - access denied message not displayed
5 participants