diff --git a/src/legacy/ui/public/field_editor/components/field_format_editor/editors/url/__snapshots__/url.test.js.snap b/src/legacy/ui/public/field_editor/components/field_format_editor/editors/url/__snapshots__/url.test.js.snap
index 9d2793beb426f..796de886dc5bc 100644
--- a/src/legacy/ui/public/field_editor/components/field_format_editor/editors/url/__snapshots__/url.test.js.snap
+++ b/src/legacy/ui/public/field_editor/components/field_format_editor/editors/url/__snapshots__/url.test.js.snap
@@ -392,3 +392,207 @@ exports[`UrlFormatEditor should render url template help 1`] = `
/>
`;
+
+exports[`UrlFormatEditor should render width and height fields if image 1`] = `
+
+
+
+
+ }
+ labelType="label"
+ >
+
+
+
+
+
+ }
+ isInvalid={false}
+ label={
+
+ }
+ labelType="label"
+ >
+
+
+
+
+
+ }
+ isInvalid={false}
+ label={
+
+ }
+ labelType="label"
+ >
+
+
+
+ }
+ labelType="label"
+ >
+
+
+
+ }
+ labelType="label"
+ >
+
+
+
+
+`;
diff --git a/src/legacy/ui/public/field_editor/components/field_format_editor/editors/url/url.js b/src/legacy/ui/public/field_editor/components/field_format_editor/editors/url/url.js
index afa5e2834d94d..72466c4e327e8 100644
--- a/src/legacy/ui/public/field_editor/components/field_format_editor/editors/url/url.js
+++ b/src/legacy/ui/public/field_editor/components/field_format_editor/editors/url/url.js
@@ -25,6 +25,7 @@ import {
EuiLink,
EuiSelect,
EuiSwitch,
+ EuiFieldNumber
} from '@elastic/eui';
import {
@@ -68,23 +69,29 @@ export class UrlFormatEditor extends DefaultFormatEditor {
};
}
+ sanitizeNumericValue = (val) => {
+ const sanitizedValue = parseInt(val);
+ if (isNaN(sanitizedValue)) {
+ return '';
+ }
+ return sanitizedValue;
+ }
+
onTypeChange = (newType) => {
- const { urlTemplate } = this.props.formatParams;
- if(newType === 'img' && !urlTemplate) {
- this.onChange({
- type: newType,
- urlTemplate: this.iconPattern,
- });
- } else if(newType !== 'img' && urlTemplate === this.iconPattern) {
- this.onChange({
- type: newType,
- urlTemplate: null,
- });
- } else {
- this.onChange({
- type: newType,
- });
+ const { urlTemplate, width, height } = this.props.formatParams;
+ const params = {
+ type: newType
+ };
+ if (newType === 'img') {
+ params.width = width;
+ params.height = height;
+ if (!urlTemplate) {
+ params.urlTemplate = this.iconPattern;
+ }
+ } else if (newType !== 'img' && urlTemplate === this.iconPattern) {
+ params.urlTemplate = null;
}
+ this.onChange(params);
}
showUrlTemplateHelp = () => {
@@ -113,6 +120,37 @@ export class UrlFormatEditor extends DefaultFormatEditor {
});
}
+ renderWidthHeightParameters = () => {
+ const width = this.sanitizeNumericValue(this.props.formatParams.width);
+ const height = this.sanitizeNumericValue(this.props.formatParams.height);
+ return (
+
+ }
+ >
+ {
+ this.onChange({ width: e.target.value });
+ }}
+ />
+
+ }
+ >
+ {
+ this.onChange({ height: e.target.value });
+ }}
+ />
+
+
+ );
+ }
+
render() {
const { format, formatParams } = this.props;
const { error, samples, sampleConverterType } = this.state;
@@ -197,6 +235,8 @@ export class UrlFormatEditor extends DefaultFormatEditor {
/>
+ { formatParams.type === 'img' && this.renderWidthHeightParameters() }
+
{
component.update();
expect(component).toMatchSnapshot();
});
+
+ it('should render width and height fields if image', async () => {
+ const component = shallow(
+
+ );
+ expect(component).toMatchSnapshot();
+ });
});