Skip to content

Commit

Permalink
Merge branch '7.x' of github.com:elastic/kibana into backport/7.x/pr-…
Browse files Browse the repository at this point in the history
…37134
  • Loading branch information
andrew-goldstein committed May 28, 2019
2 parents 1ada4b6 + 00ee700 commit 86e4ac5
Show file tree
Hide file tree
Showing 27 changed files with 696 additions and 97 deletions.
12 changes: 12 additions & 0 deletions packages/kbn-config-schema/src/types/object_type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,15 @@ test('includes namespace in failure when wrong value type', () => {

expect(() => type.validate(value, {}, 'foo-namespace')).toThrowErrorMatchingSnapshot();
});

test('individual keys can validated', () => {
const type = schema.object({
foo: schema.boolean(),
});

const value = false;
expect(() => type.validateKey('foo', value)).not.toThrowError();
expect(() => type.validateKey('bar', '')).toThrowErrorMatchingInlineSnapshot(
`"bar is not a valid part of this schema"`
);
});
15 changes: 15 additions & 0 deletions packages/kbn-config-schema/src/types/object_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import typeDetect from 'type-detect';
import { AnySchema, internals } from '../internals';
import { Type, TypeOptions } from './type';
import { ValidationError } from '../errors';

export type Props = Record<string, Type<any>>;

Expand All @@ -31,6 +32,8 @@ export type TypeOf<RT extends Type<any>> = RT['type'];
export type ObjectResultType<P extends Props> = Readonly<{ [K in keyof P]: TypeOf<P[K]> }>;

export class ObjectType<P extends Props = any> extends Type<ObjectResultType<P>> {
private props: Record<string, AnySchema>;

constructor(props: P, options: TypeOptions<{ [K in keyof P]: TypeOf<P[K]> }> = {}) {
const schemaKeys = {} as Record<string, AnySchema>;
for (const [key, value] of Object.entries(props)) {
Expand All @@ -44,6 +47,7 @@ export class ObjectType<P extends Props = any> extends Type<ObjectResultType<P>>
.default();

super(schema, options);
this.props = schemaKeys;
}

protected handleError(type: string, { reason, value }: Record<string, any>) {
Expand All @@ -57,4 +61,15 @@ export class ObjectType<P extends Props = any> extends Type<ObjectResultType<P>>
return reason[0];
}
}

validateKey(key: string, value: any) {
if (!this.props[key]) {
throw new Error(`${key} is not a valid part of this schema`);
}
const { value: validatedValue, error } = this.props[key].validate(value);
if (error) {
throw new ValidationError(error as any, key);
}
return validatedValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@
<div class="visEditorSidebar__formRow" ng-hide="editorState.params.gauge.type === 'simple'">
<label
class="visEditorSidebar__formLabel"
for="verticalSplit"
i18n-id="kbnVislibVisTypes.controls.gaugeOptions.verticalSplitLabel"
i18n-default-message="Vertical Split"
for="alignment"
i18n-id="kbnVislibVisTypes.controls.gaugeOptions.alignmentLabel"
i18n-default-message="Alignment"
></label>
<div class="visEditorSidebar__formControl">
<input class="kuiCheckBox" id="verticalSplit" type="checkbox" ng-model="editorState.params.gauge.verticalSplit">&nbsp;
<icon-tip
content="'Shows gauges one under another'"
position="'right'"
></icon-tip>
<select
id="alignment"
class="kuiSelect visEditorSidebar__select"
ng-model="editorState.params.gauge.alignment"
ng-options="alignment.id as alignment.label for alignment in collections.alignments"
></select>
</div>
</div>

Expand Down
15 changes: 14 additions & 1 deletion src/legacy/core_plugins/kbn_vislib_vis_types/public/gauge.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function GaugeVisType(Private) {
addLegend: true,
isDisplayWarning: false,
gauge: {
verticalSplit: false,
alignment: 'automatic',
extendRange: true,
percentageMode: false,
gaugeType: 'Arc',
Expand Down Expand Up @@ -86,6 +86,19 @@ export default function GaugeVisType(Private) {
collections: {
gaugeTypes: ['Arc', 'Circle'],
gaugeColorMode: ['None', 'Labels', 'Background'],
alignments: [
{
id: 'automatic',
label: i18n.translate('kbnVislibVisTypes.gauge.alignmentAutomaticTitle', { defaultMessage: 'Automatic' })
},
{
id: 'horizontal',
label: i18n.translate('kbnVislibVisTypes.gauge.alignmentHorizontalTitle', { defaultMessage: 'Horizontal' })
},
{
id: 'vertical',
label: i18n.translate('kbnVislibVisTypes.gauge.alignmentVerticalTitle', { defaultMessage: 'Vertical' }) },
],
scales: ['linear', 'log', 'square root'],
colorSchemas: Object.values(vislibColorMaps).map(value => ({ id: value.id, label: value.label })),
},
Expand Down
30 changes: 29 additions & 1 deletion src/legacy/core_plugins/kibana/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,33 @@ function removeDateHistogramTimeZones(doc) {
return doc;
}

// migrate gauge verticalSplit to alignment
// https://github.com/elastic/kibana/issues/34636
function migrateGaugeVerticalSplitToAlignment(doc) {
const visStateJSON = get(doc, 'attributes.visState');

if (visStateJSON) {
try {
const visState = JSON.parse(visStateJSON);
if (visState && visState.type === 'gauge') {

visState.params.gauge.alignment = visState.params.gauge.verticalSplit ? 'vertical' : 'horizontal';
delete visState.params.gauge.verticalSplit;
return {
...doc,
attributes: {
...doc.attributes,
visState: JSON.stringify(visState),
},
};
}
} catch (e) {
// Let it go, the data is invalid and we'll leave it as is
}
}
return doc;
}

export const migrations = {
'index-pattern': {
'6.5.0': (doc) => {
Expand Down Expand Up @@ -264,7 +291,8 @@ export const migrations = {
}
},
'7.0.1': removeDateHistogramTimeZones,
'7.2.0': doc => executeMigrations720(doc)
'7.2.0': doc => executeMigrations720(doc),
'7.3.0': migrateGaugeVerticalSplitToAlignment
},
dashboard: {
'7.0.0': (doc) => {
Expand Down
48 changes: 48 additions & 0 deletions src/legacy/core_plugins/kibana/migrations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,54 @@ Object {
expect(aggs[3]).not.toHaveProperty('params.customInterval');
});
});
describe('7.3.0', () => {
const migrate = doc => migrations.visualization['7.3.0'](doc);

it('migrates type = gauge verticalSplit: false to alignment: vertical', () => {
const migratedDoc = migrate({
attributes: {
visState: JSON.stringify({ type: 'gauge', params: { gauge: { verticalSplit: false } } }),
},
});
expect(migratedDoc).toMatchInlineSnapshot(`
Object {
"attributes": Object {
"visState": "{\\"type\\":\\"gauge\\",\\"params\\":{\\"gauge\\":{\\"alignment\\":\\"horizontal\\"}}}",
},
}
`);
});

it('migrates type = gauge verticalSplit: false to alignment: horizontal', () => {
const migratedDoc = migrate({
attributes: {
visState: JSON.stringify({ type: 'gauge', params: { gauge: { verticalSplit: true } } }),
},
});
expect(migratedDoc).toMatchInlineSnapshot(`
Object {
"attributes": Object {
"visState": "{\\"type\\":\\"gauge\\",\\"params\\":{\\"gauge\\":{\\"alignment\\":\\"vertical\\"}}}",
},
}
`);
});

it('doesnt migrate type = gauge containing invalid visState object', () => {
const migratedDoc = migrate({
attributes: {
visState: JSON.stringify({ type: 'gauge' }),
},
});
expect(migratedDoc).toMatchInlineSnapshot(`
Object {
"attributes": Object {
"visState": "{\\"type\\":\\"gauge\\"}",
},
}
`);
});
});
});

describe('dashboard', () => {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 86e4ac5

Please sign in to comment.