-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Convert uiSettings service to TypeScript #47018
Conversation
Pinging @elastic/kibana-platform |
getAll: <T extends SavedObjectAttribute = any>() => Promise<Record<string, T>>; | ||
getUserProvided: () => Promise<UserProvided>; | ||
setMany: <T extends SavedObjectAttribute = any>(changes: Record<string, T>) => Promise<void>; | ||
set: <T extends SavedObjectAttribute = any>(key: string, value: T) => Promise<void>; |
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.
value must satisfy SavedObjectAttribute` constraints. @rudolf is it okay that we cannot set an array of primitives? according to SavedObjects interface
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.
@@ -233,7 +231,7 @@ describe('ui settings', () => { | |||
}); | |||
|
|||
try { | |||
await uiSettings.setMany(['bar', 'foo']); | |||
await uiSettings.setMany({ baz: 'baz', foo: 'foo' }); |
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 believe it was used in unexpected way
// mock includeFrozen to return false | ||
mockRequest.getUiSettingsService = () => ({ get: async () => false }); | ||
uiSettingsService.get.mockResolvedValue(false); | ||
mockRequest.getUiSettingsService = () => uiSettingsService; |
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.
had to update tests to fix a type error
@@ -489,7 +487,7 @@ describe('ui settings', () => { | |||
it('pulls user configuration from ES', async () => { | |||
const esDocSource = {}; | |||
const { uiSettings, assertGetQuery } = setup({ esDocSource }); | |||
await uiSettings.get(); | |||
await uiSettings.get('any'); |
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.
key is required argument
} | ||
|
||
async getRaw() { | ||
// NOTE: should be a private method | ||
async getRaw(): Promise<UiSettingsRaw> { |
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.
right now we used them in tests. I'd re-write test and hide them later
get: <T extends SavedObjectAttribute = any>(key: string) => Promise<T>; | ||
getAll: <T extends SavedObjectAttribute = any>() => Promise<Record<string, T>>; | ||
getUserProvided: () => Promise<UserProvided>; | ||
setMany: <T extends SavedObjectAttribute = any>(changes: Record<string, T>) => Promise<void>; |
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 use T extends SavedObjectAttributes = any
but not sure we should. I thought it made it harder to read the code.
await this._write({ changes }); | ||
} | ||
|
||
async set(key, value) { | ||
async set<T extends SavedObjectAttribute = any>(key: string, value: T) { |
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.
probably we should improve client side typings as well, right now they get/set any
https://github.com/restrry/kibana/blob/33486f99d4c77cc9213f83cb4b7109ffa84207fe/src/core/public/ui_settings/ui_settings_client.ts#L125
|
||
export interface IUiSettingsService { | ||
getDefaults: () => Promise<Record<string, UiSettingsParams>>; | ||
get: <T extends SavedObjectAttribute = any>(key: string) => Promise<T>; |
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.
used as
const value = uiSettings.get<string>('key');
// error
const value = uiSettings.get<string []>('key');
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.
APM changes lgtm
* @property {Function} [options.log] | ||
*/ | ||
constructor(options) { | ||
export class UiSettingsService implements IUiSettingsService { |
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.
Shall we rename it to UiSettingsClient
? It's not a service but a designated object for the plugins to interact with.
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.
Yeah I think that makes sense, or even just UISettings
?
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.
Actually, we probably need to decide on our convention for capitalization of acronyms. For example we use HttpServiceSetup
instead of HTTPServiceSetup
in core right now. Should this be UiSettingsClient
? I prefer this pattern because then the I-prefix looks a little less strange: IUiSettingsClient
💚 Build Succeeded |
💔 Build Failed |
retest |
💚 Build Succeeded |
export async function createOrUpgradeSavedConfig<T extends SavedObjectAttribute = any>( | ||
options: Options | ||
): Promise<Record<string, T> | undefined> { | ||
const { savedObjectsClient, version, buildNum, logWithMetadata, onWriteError } = 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.
Move object destructure to function arguments?
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'd prefer not to do. there are already too many params to use positional arguments.
retest |
💚 Build Succeeded |
* tsify is_config_version_upgradeable * tsify get_upgradeable_config * tsify create_or_upgrade_saved_config * tsify ui_settings_service * tsify ui_settings_service_factory * tsify ui_settings_service_for_request * declare types on server object * tsify set route * tsify set_many route * tsify get route * tsify delete route * tsify logWithMetadata * improve ui_settings_service typings * introduce uiService mocks * remove private methods from public contract * add types for server.uiSettingsServiceFactory * rename IUiSettingsService --> IUiSettingsClient
* tsify is_config_version_upgradeable * tsify get_upgradeable_config * tsify create_or_upgrade_saved_config * tsify ui_settings_service * tsify ui_settings_service_factory * tsify ui_settings_service_for_request * declare types on server object * tsify set route * tsify set_many route * tsify get route * tsify delete route * tsify logWithMetadata * improve ui_settings_service typings * introduce uiService mocks * remove private methods from public contract * add types for server.uiSettingsServiceFactory * rename IUiSettingsService --> IUiSettingsClient
Summary
Convert service to TS and declare
IUiSettingsService
public interface.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