-
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
Stats API: do not convert arrays to objects #21053
Conversation
💔 Build Failed |
days_of_the_week: ['monday', 'tuesday', 'wednesday'], | ||
}); | ||
}); | ||
}); |
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.
@tsullivan Could you write a test that uses an array of objects whose keys might need changing? So, for example:
const apiData = {
daysOfTheWeek: [
{
dayName: 'monday',
dayIndex: 1
},
{
dayName: 'tuesday',
dayIndex: 2
},
{
dayName: 'wednesday',
dayIndex: 3
}
]
}
The expected result would be:
{
days_of_the_week: [
{
day_name: 'monday',
day_index: 1
},
{
day_name: 'tuesday',
day_index: 2
},
{
day_name: 'wednesday',
day_index: 3
}
]
}
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.
Sure. That would not work with the code as it is. I stopped implementation on this before I started worrying about objects nested in arrays. But it is a fair ask.
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.
}; | ||
}, {}); | ||
} else { | ||
return apiData; |
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.
Per the comments from @ycombinator about the test, it seems weird that we aren't doing any manipulation if it's an array since it seems reasonable it could be an array of objects that need to be manipulated?
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.
}, {}); | ||
if (Array.isArray(apiData)) { | ||
return apiData.map(getValueOrRecurse); | ||
} else { |
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.
Since you are return
ing from the if
above, you don't necessarily need the else
here. Somewhat related: https://github.com/elastic/kibana/blob/master/style_guides/js_style_guide.md#returnthrow-early-from-functions.
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.
One minor comment, otherwise LGTM.
💚 Build Succeeded |
* Stats API: do not convert arrays to objects * handle nested arrays in toApiFieldNames * add early return
This PR solves a problem where the
toApiFieldNames
method was converting arrays in the data to objects.For example:
would become
The changes in this PR handle arrays nested with object data as well.