uiSettings - use validation field for image field maxSize (#54522)

* uiSettings - use validation field for image field maxSize
This commit is contained in:
Matthew Kime 2020-01-13 13:58:59 -06:00 committed by GitHub
parent 62e7edbe26
commit 2178ee38c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 48 additions and 14 deletions

View file

@ -9,5 +9,5 @@ returns `basePath` value, specific for an incoming request.
<b>Signature:</b>
```typescript
get: (request: KibanaRequest<unknown, unknown, unknown, any> | LegacyRequest) => string;
get: (request: LegacyRequest | KibanaRequest<unknown, unknown, unknown, any>) => string;
```

View file

@ -20,9 +20,9 @@ The constructor for this class is marked as internal. Third-party code should no
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [get](./kibana-plugin-server.basepath.get.md) | | <code>(request: KibanaRequest&lt;unknown, unknown, unknown, any&gt; &#124; LegacyRequest) =&gt; string</code> | returns <code>basePath</code> value, specific for an incoming request. |
| [get](./kibana-plugin-server.basepath.get.md) | | <code>(request: LegacyRequest &#124; KibanaRequest&lt;unknown, unknown, unknown, any&gt;) =&gt; string</code> | returns <code>basePath</code> value, specific for an incoming request. |
| [prepend](./kibana-plugin-server.basepath.prepend.md) | | <code>(path: string) =&gt; string</code> | Prepends <code>path</code> with the basePath. |
| [remove](./kibana-plugin-server.basepath.remove.md) | | <code>(path: string) =&gt; string</code> | Removes the prepended basePath from the <code>path</code>. |
| [serverBasePath](./kibana-plugin-server.basepath.serverbasepath.md) | | <code>string</code> | returns the server's basePath<!-- -->See [BasePath.get](./kibana-plugin-server.basepath.get.md) for getting the basePath value for a specific request |
| [set](./kibana-plugin-server.basepath.set.md) | | <code>(request: KibanaRequest&lt;unknown, unknown, unknown, any&gt; &#124; LegacyRequest, requestSpecificBasePath: string) =&gt; void</code> | sets <code>basePath</code> value, specific for an incoming request. |
| [set](./kibana-plugin-server.basepath.set.md) | | <code>(request: LegacyRequest &#124; KibanaRequest&lt;unknown, unknown, unknown, any&gt;, requestSpecificBasePath: string) =&gt; void</code> | sets <code>basePath</code> value, specific for an incoming request. |

View file

@ -9,5 +9,5 @@ sets `basePath` value, specific for an incoming request.
<b>Signature:</b>
```typescript
set: (request: KibanaRequest<unknown, unknown, unknown, any> | LegacyRequest, requestSpecificBasePath: string) => void;
set: (request: LegacyRequest | KibanaRequest<unknown, unknown, unknown, any>, requestSpecificBasePath: string) => void;
```

View file

@ -24,5 +24,6 @@ export interface UiSettingsParams
| [readonly](./kibana-plugin-server.uisettingsparams.readonly.md) | <code>boolean</code> | a flag indicating that value cannot be changed |
| [requiresPageReload](./kibana-plugin-server.uisettingsparams.requirespagereload.md) | <code>boolean</code> | a flag indicating whether new value applying requires page reloading |
| [type](./kibana-plugin-server.uisettingsparams.type.md) | <code>UiSettingsType</code> | defines a type of UI element [UiSettingsType](./kibana-plugin-server.uisettingstype.md) |
| [validation](./kibana-plugin-server.uisettingsparams.validation.md) | <code>ImageValidation &#124; StringValidation</code> | |
| [value](./kibana-plugin-server.uisettingsparams.value.md) | <code>SavedObjectAttribute</code> | default value to fall back to if a user doesn't provide any |

View file

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) &gt; [validation](./kibana-plugin-server.uisettingsparams.validation.md)
## UiSettingsParams.validation property
<b>Signature:</b>
```typescript
validation?: ImageValidation | StringValidation;
```

View file

@ -1935,6 +1935,11 @@ export interface UiSettingsParams {
readonly?: boolean;
requiresPageReload?: boolean;
type?: UiSettingsType;
// Warning: (ae-forgotten-export) The symbol "ImageValidation" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "StringValidation" needs to be exported by the entry point index.d.ts
//
// (undocumented)
validation?: ImageValidation | StringValidation;
value?: SavedObjectAttribute;
}

View file

@ -102,6 +102,23 @@ export interface UiSettingsParams {
readonly?: boolean;
/** defines a type of UI element {@link UiSettingsType} */
type?: UiSettingsType;
/*
* Allows defining a custom validation applicable to value change on the client.
* @deprecated
*/
validation?: ImageValidation | StringValidation;
}
export interface StringValidation {
regexString: string;
message: string;
}
export interface ImageValidation {
maxSize: {
length: number;
description: string;
};
}
/** @internal */

View file

@ -224,7 +224,7 @@ export class Field extends PureComponent {
}
const file = files[0];
const { maxSize } = this.props.setting.options;
const { maxSize } = this.props.setting.validation;
try {
const base64Image = await this.getImageAsBase64(file);
const isInvalid = !!(maxSize && maxSize.length && base64Image.length > maxSize.length);

View file

@ -72,10 +72,9 @@ const settings = {
defVal: null,
isCustom: false,
isOverridden: false,
options: {
validation: {
maxSize: {
length: 1000,
displayName: '1 kB',
description: 'Description for 1 kB',
},
},

View file

@ -43,12 +43,13 @@ export function toEditableConfig({ def, name, value, isCustom, isOverridden }) {
defVal: def.value,
type: getValType(def, value),
description: def.description,
validation: def.validation
? {
regex: new RegExp(def.validation.regexString),
message: def.validation.message,
}
: undefined,
validation:
def.validation && def.validation.regexString
? {
regex: new RegExp(def.validation.regexString),
message: def.validation.message,
}
: def.validation,
options: def.options,
optionLabels: def.optionLabels,
requiresPageReload: !!def.requiresPageReload,

View file

@ -59,7 +59,7 @@ export const reporting = (kibana: any) => {
defaultMessage: `Custom image to use in the PDF's footer`,
}),
type: 'image',
options: {
validation: {
maxSize: {
length: kbToBase64Length(200),
description: '200 kB',