Skip to content

Commit

Permalink
make schema required
Browse files Browse the repository at this point in the history
  • Loading branch information
mshustov committed Mar 12, 2020
1 parent 075fe07 commit 3b8ad0c
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export {
ErrorToastOptions,
} from './notifications';

export { MountPoint, UnmountCallback } from './types';
export { MountPoint, UnmountCallback, PublicUiSettingsParams } from './types';

/**
* Core services exposed to the `Plugin` setup lifecycle
Expand Down
1 change: 1 addition & 0 deletions src/core/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

export {
UiSettingsParams,
PublicUiSettingsParams,
UserProvidedValues,
UiSettingsType,
ImageValidation,
Expand Down
6 changes: 3 additions & 3 deletions src/core/public/ui_settings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
*/

import { Observable } from 'rxjs';
import { UiSettingsParams, UserProvidedValues } from 'src/core/server/types';
import { PublicUiSettingsParams, UserProvidedValues } from 'src/core/server/types';

/** @public */
export interface UiSettingsState {
[key: string]: UiSettingsParams & UserProvidedValues;
[key: string]: PublicUiSettingsParams & UserProvidedValues;
}

/**
Expand Down Expand Up @@ -53,7 +53,7 @@ export interface IUiSettingsClient {
* Gets the metadata about all uiSettings, including the type, default value, and user value
* for each key.
*/
getAll: () => Readonly<Record<string, UiSettingsParams & UserProvidedValues>>;
getAll: () => Readonly<Record<string, PublicUiSettingsParams & UserProvidedValues>>;

/**
* Sets the value for a uiSetting. If the setting is not registered by any plugin
Expand Down
8 changes: 4 additions & 4 deletions src/core/public/ui_settings/ui_settings_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import { cloneDeep, defaultsDeep } from 'lodash';
import { Observable, Subject, concat, defer, of } from 'rxjs';
import { filter, map } from 'rxjs/operators';

import { UiSettingsParams, UserProvidedValues } from 'src/core/server/types';
import { UserProvidedValues, PublicUiSettingsParams } from 'src/core/server/types';
import { IUiSettingsClient, UiSettingsState } from './types';

import { UiSettingsApi } from './ui_settings_api';

interface UiSettingsClientParams {
api: UiSettingsApi;
defaults: Record<string, UiSettingsParams>;
defaults: Record<string, PublicUiSettingsParams>;
initialSettings?: UiSettingsState;
done$: Observable<unknown>;
}
Expand All @@ -39,8 +39,8 @@ export class UiSettingsClient implements IUiSettingsClient {
private readonly updateErrors$ = new Subject<Error>();

private readonly api: UiSettingsApi;
private readonly defaults: Record<string, UiSettingsParams>;
private cache: Record<string, UiSettingsParams & UserProvidedValues>;
private readonly defaults: Record<string, PublicUiSettingsParams>;
private cache: Record<string, PublicUiSettingsParams & UserProvidedValues>;

constructor(params: UiSettingsClientParams) {
this.api = params.api;
Expand Down
1 change: 1 addition & 0 deletions src/core/server/ui_settings/ui_settings_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const defaults = {
value: 'bar',
category: [],
description: '',
schema: schema.string(),
},
};

Expand Down
2 changes: 1 addition & 1 deletion src/core/types/ui_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export interface UiSettingsParams<T = unknown> {
* Value validation schema
* Used to validate value on write and read.
*/
schema?: Type<T>;
schema: Type<T>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import { Observable } from 'rxjs';
import { ReactWrapper } from 'enzyme';
import { mountWithI18nProvider } from 'test_utils/enzyme_helpers';
import dedent from 'dedent';
import { UiSettingsParams, UserProvidedValues, UiSettingsType } from '../../../../core/public';
import {
PublicUiSettingsParams,
UserProvidedValues,
UiSettingsType,
} from '../../../../core/public';
import { FieldSetting } from './types';
import { AdvancedSettingsComponent } from './advanced_settings';
import { notificationServiceMock, docLinksServiceMock } from '../../../../core/public/mocks';
Expand Down Expand Up @@ -68,7 +72,7 @@ function mockConfig() {
remove: (key: string) => Promise.resolve(true),
isCustom: (key: string) => false,
isOverridden: (key: string) => Boolean(config.getAll()[key].isOverridden),
getRegistered: () => ({} as Readonly<Record<string, UiSettingsParams>>),
getRegistered: () => ({} as Readonly<Record<string, PublicUiSettingsParams>>),
overrideLocalDefault: (key: string, value: any) => {},
getUpdate$: () =>
new Observable<{
Expand All @@ -89,7 +93,7 @@ function mockConfig() {
getUpdateErrors$: () => new Observable<Error>(),
get: (key: string, defaultOverride?: any): any => config.getAll()[key] || defaultOverride,
get$: (key: string) => new Observable<any>(config.get(key)),
getAll: (): Readonly<Record<string, UiSettingsParams & UserProvidedValues>> => {
getAll: (): Readonly<Record<string, PublicUiSettingsParams & UserProvidedValues>> => {
return {
'test:array:setting': {
...defaultConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { UiSettingsParams, StringValidationRegex } from 'src/core/public';
import { PublicUiSettingsParams, StringValidationRegex } from 'src/core/public';
import expect from '@kbn/expect';
import { toEditableConfig } from './to_editable_config';

Expand All @@ -30,7 +30,7 @@ function invoke({
name = 'woah',
value = 'forreal',
}: {
def?: UiSettingsParams & { isOverridden?: boolean };
def?: PublicUiSettingsParams & { isOverridden?: boolean };
name?: string;
value?: any;
}) {
Expand All @@ -55,7 +55,7 @@ describe('Settings', function() {
});

describe('when given a setting definition object', function() {
let def: UiSettingsParams & { isOverridden?: boolean };
let def: PublicUiSettingsParams & { isOverridden?: boolean };
beforeEach(function() {
def = {
value: 'the original',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import {
UiSettingsParams,
PublicUiSettingsParams,
UserProvidedValues,
StringValidationRegexString,
SavedObjectAttribute,
Expand All @@ -40,7 +40,7 @@ export function toEditableConfig({
isCustom,
isOverridden,
}: {
def: UiSettingsParams & UserProvidedValues<any>;
def: PublicUiSettingsParams & UserProvidedValues<any>;
name: string;
value: SavedObjectAttribute;
isCustom: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

import { schema } from '@kbn/config-schema';
import { Plugin, CoreSetup } from 'kibana/server';

export class UiSettingsPlugin implements Plugin {
Expand All @@ -27,6 +27,7 @@ export class UiSettingsPlugin implements Plugin {
description: 'just for testing',
value: '2',
category: ['any'],
schema: schema.string(),
},
});

Expand Down

0 comments on commit 3b8ad0c

Please sign in to comment.