uiSettings - use validation field for image field maxSize (#54522)
* uiSettings - use validation field for image field maxSize
This commit is contained in:
parent
62e7edbe26
commit
2178ee38c0
|
@ -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;
|
||||
```
|
||||
|
|
|
@ -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<unknown, unknown, unknown, any> | LegacyRequest) => string</code> | returns <code>basePath</code> value, specific for an incoming request. |
|
||||
| [get](./kibana-plugin-server.basepath.get.md) | | <code>(request: LegacyRequest | KibanaRequest<unknown, unknown, unknown, any>) => string</code> | returns <code>basePath</code> value, specific for an incoming request. |
|
||||
| [prepend](./kibana-plugin-server.basepath.prepend.md) | | <code>(path: string) => string</code> | Prepends <code>path</code> with the basePath. |
|
||||
| [remove](./kibana-plugin-server.basepath.remove.md) | | <code>(path: string) => 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<unknown, unknown, unknown, any> | LegacyRequest, requestSpecificBasePath: string) => void</code> | sets <code>basePath</code> value, specific for an incoming request. |
|
||||
| [set](./kibana-plugin-server.basepath.set.md) | | <code>(request: LegacyRequest | KibanaRequest<unknown, unknown, unknown, any>, requestSpecificBasePath: string) => void</code> | sets <code>basePath</code> value, specific for an incoming request. |
|
||||
|
||||
|
|
|
@ -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;
|
||||
```
|
||||
|
|
|
@ -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 | 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 |
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) > [validation](./kibana-plugin-server.uisettingsparams.validation.md)
|
||||
|
||||
## UiSettingsParams.validation property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
validation?: ImageValidation | StringValidation;
|
||||
```
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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',
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue