Skip to content

Commit

Permalink
uiSettings - use validation field for image field maxSize (#54522)
Browse files Browse the repository at this point in the history
* uiSettings - use validation field for image field maxSize
  • Loading branch information
mattkime authored Jan 13, 2020
1 parent 62e7edb commit 2178ee3
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
```
4 changes: 2 additions & 2 deletions docs/development/core/server/kibana-plugin-server.basepath.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |

Original file line number Diff line number Diff line change
Expand Up @@ -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;
```
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Original file line number Diff line number Diff line change
@@ -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;
```
5 changes: 5 additions & 0 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
17 changes: 17 additions & 0 deletions src/core/server/ui_settings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/reporting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 2178ee3

Please sign in to comment.