Skip to content

Commit

Permalink
Fix type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
wylieconlon committed Apr 7, 2020
1 parent da65b8e commit 7ccd6e1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
13 changes: 7 additions & 6 deletions x-pack/legacy/plugins/lens/migrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { migrations } from './migrations';
import { migrations, RawLensSavedXYObject770 } from './migrations';
import { SimpleSavedObject } from 'src/core/public';

describe('Lens migrations', () => {
describe('7.7.0 missing dimensions in XY', () => {
const migrate = (doc: unknown) => migrations['7.7.0'](doc);
const migrate = (doc: SimpleSavedObject | RawLensSavedXYObject770) => migrations['7.7.0'](doc);

const example = {
const example: RawLensSavedXYObject770 = {
type: 'lens',
attributes: {
expression:
Expand Down Expand Up @@ -105,7 +106,7 @@ describe('Lens migrations', () => {
visualizationType: 'lnsMetric',
},
};
const result = migrate(target);
const result = migrate(target as SimpleSavedObject);
expect(result).toEqual(target);
});

Expand All @@ -123,7 +124,7 @@ describe('Lens migrations', () => {
},
},
},
});
} as SimpleSavedObject) as RawLensSavedXYObject770;

expect(result.attributes.state.visualization.layers).toEqual([
{
Expand All @@ -139,7 +140,7 @@ describe('Lens migrations', () => {
});

it('should remove only missing accessors', () => {
const result = migrate(example);
const result = migrate(example) as RawLensSavedXYObject770;

expect(result.attributes.state.visualization.layers).toEqual([
{
Expand Down
28 changes: 15 additions & 13 deletions x-pack/legacy/plugins/lens/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@
import { cloneDeep } from 'lodash';
import { SimpleSavedObject } from 'src/core/public';

interface RawLensSavedXYObject770 {
export interface RawLensSavedXYObject770 {
type: 'lens';
attributes: {
attributes: Record<string, unknown> & {
visualizationType: string;
state: {
datasourceStates?: {
indexpattern?: {
layers: Record<string, { columns: Record<string, unknown> }>;
state: Record<string, unknown> & {
datasourceStates?: Record<string, unknown> & {
indexpattern?: Record<string, unknown> & {
layers: Record<string, Record<string, unknown> & { columns: Record<string, unknown> }>;
};
};
visualization: {
layers: Array<{
layerId: string;
accessors: string[];
xAccessor: string;
splitAccessor: string;
}>;
visualization: Record<string, unknown> & {
layers: Array<
Record<string, unknown> & {
layerId: string;
accessors: string[];
xAccessor: string;
splitAccessor: string;
}
>;
};
};
};
Expand Down

0 comments on commit 7ccd6e1

Please sign in to comment.