-
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
Provide uiSettings service in NP #48413
Conversation
Pinging @elastic/kibana-platform (Team:Platform) |
}, | ||
elasticsearch: { | ||
adminClient: adminClient.asScoped(req), | ||
dataClient: dataClient.asScoped(req), | ||
}, | ||
uiSettings: { | ||
client: coreSetup.uiSettings.asScopedToClient(savedObjectsClient), |
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.
Note: There are several reasons to pass savedObjectsClient
here:
- Consistency. All context services use the same version of the client.
- There is no way for uiSettings to declare a dependency on the saved object service at the moment. The current dependency graph is
uiSettings
-- used by -->legacy
-- used by -->savedObjects
.
We can work around it exposingregister
via start contract as well, but it's not something we want to support in the long term.
💔 Build Failed |
@@ -52,8 +51,17 @@ export async function createOrUpgradeSavedConfig<T extends SavedObjectAttribute | |||
// create the new SavedConfig | |||
await savedObjectsClient.create('config', attributes, { id: version }); | |||
} catch (error) { | |||
if (onWriteError) { | |||
return onWriteError(error, attributes); | |||
if (handleWriteErrors) { |
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 inlined this logic to improve testability.
💔 Build Failed |
const { uiSettings } = setup(); | ||
expect(uiSettings.assertUpdateAllowed('foo')).to.be(undefined); | ||
}); | ||
it('throws 400 Boom error when keys is overridden', () => { |
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.
covered by CannotOverrideError tests
}); | ||
}); | ||
|
||
describe('#getRaw()', () => { |
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.
covered by getAll
tests
const userProvided: UserProvided = {}; | ||
|
||
// write the userValue for each key stored in the saved object that is not overridden | ||
for (const [key, userValue] of Object.entries(await this.read(options))) { |
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 haven't found someone utilizing them in LP.
💔 Build Failed |
💚 Build Succeeded |
@@ -763,7 +765,7 @@ export type IScopedClusterClient = Pick<ScopedClusterClient, 'callAsCurrentUser' | |||
export interface IUiSettingsClient { | |||
get: <T extends SavedObjectAttribute = any>(key: string) => Promise<T>; | |||
getAll: <T extends SavedObjectAttribute = any>() => Promise<Record<string, T>>; | |||
getDefaults: () => Record<string, UiSettingsParams>; | |||
getRegistered: () => Readonly<Record<string, UiSettingsParams>>; |
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.
We can still keep getDefaults
for BWC with 3rd party plugins. I decided we don't want to have an additional API to maintain. Any objections?
💚 Build Succeeded |
ack: will review tomorrow, sorry would have done sooner but I didn't see it in the kibana-platform project 😅 |
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.
Renovate changes LGTM
@joshdover my bad 😅 |
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.
Can you update the uiExport table in the migration guide with a link to the docs for registering a uiSetting?
requiresPageReload?: boolean; | ||
/** a flag indicating that value cannot be changed */ | ||
readonly?: boolean; | ||
/** defines a type of UI element {@link UiSettingsType} */ |
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.
Is there a 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.
No. I think we assume string
as a default. Probably we should express this in code https://github.com/restrry/kibana/blob/841abd1162f1eb6aaebf27d004c92e8344636d91/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.js#L494
Co-Authored-By: Josh Dover <[email protected]>
💚 Build Succeeded |
💔 Build Failed |
retest |
💚 Build Succeeded |
* provide ui settins client via context * update mocks * update types and expose setDefaults to plugins * move ui settings routes to NP * add typings fro test kbn server * move integration test & improve typings * hide client private methods, update tests * add unit tests for get_upgradable_config * inline writeErrors into createOrUpgradeConfig to simplify testing * regen docs * add functional tests for ui_settings service * unify test suites * add types for sipertest in core_plugin tests * tsify core_plugins tests * add test for empty saved config * update renovate * rename get/setDefaults to reguster * regen docs * regen docs * Update src/core/MIGRATION.md Co-Authored-By: Josh Dover <[email protected]>
* provide ui settins client via context * update mocks * update types and expose setDefaults to plugins * move ui settings routes to NP * add typings fro test kbn server * move integration test & improve typings * hide client private methods, update tests * add unit tests for get_upgradable_config * inline writeErrors into createOrUpgradeConfig to simplify testing * regen docs * add functional tests for ui_settings service * unify test suites * add types for sipertest in core_plugin tests * tsify core_plugins tests * add test for empty saved config * update renovate * rename get/setDefaults to reguster * regen docs * regen docs * Update src/core/MIGRATION.md Co-Authored-By: Josh Dover <[email protected]>
Summary
This PR:
register
in the setup phase.getDefaults
togetRegistered
. Only found usage in the core plugins and updated accordingly. I decided to update them because plugins are about to start using this API and I don't want to change public API later. uiSettings internals still usesdefaults
term.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 IE11[ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support[ ] Documentation was added for features that require explanation or tutorials[ ] This was checked for keyboard-only and screenreader accessibilityFor maintainers
Dev Docs
New platform plugins can register custom uiSettings via
uiSettings.register
methodUiSettings client can be accessed: