Allow nested declaration for exposeToBrowser#128864
Conversation
|
Pinging @elastic/kibana-core (Team:Core) |
afharo
left a comment
There was a problem hiding this comment.
LGTM! I just added a few nits for your consideration
| ) | ||
| ) | ||
| ), | ||
| this.configService |
There was a problem hiding this comment.
Mind the filter in line 225 (I couldn't comment there): since the root values do not necessarily are boolean now, are we OK with validating that a key simply exists?
There was a problem hiding this comment.
We're validating that at least one value exists (not a key), but that doesn't change much: Yea, I think we're fine.
Only edge case I see would be a scenario where the descriptor only defines nested keys with false values:
{
nested: {
key: false,
}
}this would 'bypass' the filtering. But the output of createBrowserConfig would then be an empty object regardless, so I think it's fine.
TBH we could probably get rid of this whole filter block and let createBrowserConfig generates empty configs for all plugins, but I wanted to avoid touching more code than necessary here.
Do you think it would make sense to get rid of this filter block in the current PR?
| * @public | ||
| */ | ||
| export type ExposedToBrowserDescriptor<T> = { | ||
| [Key in keyof T]?: T[Key] extends Maybe<any[]> |
There was a problem hiding this comment.
nit: If we do Array<infer U> instead of any[] we remove the additional any and allow us to support cherry-picking properties in an array of objects if necessary 😇
const config = {
myArray: [
{
propA: 'value',
propB: 'value',
}
]
};
const exposeToBrowser = {
myArray: {
propA: true
}
}There was a problem hiding this comment.
I 'stupidly' reproduced the type logic of MakeUsageFromSchema from the same file.
If we have a way to get rid of this any, I would be more than happy to. However regarding allowing to pick from the array, I'd rather hold that until we got a specific requirement for it, given the way we would be handling arrays in the exposeToBrowser definition would be slightly different and maybe a bit misleading (objectKey->properties, arrayKey->propertiesOfElements)
💚 Build SucceededMetrics [docs]History
To update your PR or re-run it, just comment with: |
|
Added 7.17 and 8.1 labels as Stack Monitoring will need this to fix an issue in previous versions as well :) |
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
* Allow nested declaration for `exposeToBrowser` * update generated doc * add utest (cherry picked from commit dd0a190) # Conflicts: # src/core/server/server.api.md
* Allow nested declaration for `exposeToBrowser` * update generated doc * add utest (cherry picked from commit dd0a190) # Conflicts: # src/core/server/plugins/plugins_service.ts # src/core/server/server.api.md
Summary
Fix #128794
Allow to use a nested structure when defining
PluginConfigDescriptor.exposeToBrowserto only expose a subset of a given configuration section/object.Checklist