-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Lens] Move runtime other migration to CM transforms #235286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e701a88
[Lens] Move runtime other migration to CM transforms
nickofthyme b708a7c
update code to align with new schema constraints
nickofthyme 604b0ff
Merge branch 'main' into runtime-migrations
nickofthyme 54f8a99
Merge branch 'main' into runtime-migrations
markov00 aeee81b
chore: fix lens xy type string
nickofthyme 4310aba
Merge branch 'main' into runtime-migrations
nickofthyme 7a37888
update fix color logic
nickofthyme 45a1330
add comments to mismatch type fixes
nickofthyme 23e9526
fix: error handling tests
nickofthyme 23d4477
Merge branch 'main' into runtime-migrations
nickofthyme 05334ca
Merge branch 'main' into runtime-migrations
nickofthyme b1fa550
Merge branch 'main' into runtime-migrations
nickofthyme 871a3ea
Merge branch 'main' into runtime-migrations
nickofthyme e70b73d
Merge branch 'main' into runtime-migrations
nickofthyme 0e98e45
Merge branch 'main' into runtime-migrations
nickofthyme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
x-pack/platform/plugins/shared/lens/common/content_management/v1/transforms/attributes.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import type { LensAttributes } from '../../../../server/content_management'; | ||
| import type { LensSOAttributesV0 } from '../../../../server/content_management/v0'; | ||
|
|
||
| export const LENS_UNKNOWN_VIS = 'UNKNOWN'; | ||
|
|
||
| /** | ||
| * Cleanup null and loose SO attribute types | ||
| * - `description` should not allow `null` | ||
| * - `visualizationType` should not allow `null` or `undefined` | ||
| */ | ||
| export function attributesCleanup(attributes: LensSOAttributesV0): LensAttributes { | ||
| return { | ||
| ...attributes, | ||
| // fix type mismatches, null -> undefined | ||
| description: attributes.description ?? undefined, | ||
| // fix type mismatches, null | undefined -> string | ||
| visualizationType: attributes.visualizationType ?? LENS_UNKNOWN_VIS, // should never happen | ||
nickofthyme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
| } | ||
55 changes: 55 additions & 0 deletions
55
x-pack/platform/plugins/shared/lens/common/content_management/v1/transforms/metric.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import type { MetricVisualizationState } from '../../../../public'; | ||
| import type { LensAttributes } from '../../../../server/content_management'; | ||
|
|
||
| /** | ||
| * Cleanup metric properties | ||
| * - Move `valuesTextAlign` to `primaryAlign` and `secondaryAlign` | ||
| * - Move `secondaryPrefix` to `secondaryLabel` | ||
| */ | ||
| export function metricMigrations(attributes: LensAttributes): LensAttributes { | ||
| if (!attributes.state || attributes.visualizationType !== 'lnsMetric') { | ||
| return attributes; | ||
| } | ||
|
|
||
| const state = attributes.state as { | ||
| visualization: MetricVisualizationState; | ||
| }; | ||
| const newVisualizationState = getUpdatedMetricState(state.visualization); | ||
|
|
||
| return { | ||
| ...attributes, | ||
| state: { | ||
| ...state, | ||
| visualization: newVisualizationState, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| const getUpdatedMetricState = (state: MetricVisualizationState): MetricVisualizationState => { | ||
| const { secondaryPrefix, valuesTextAlign, ...restState } = state; | ||
| let newState = { ...restState }; | ||
|
|
||
| if (valuesTextAlign) { | ||
| newState = { | ||
| ...newState, | ||
| primaryAlign: state.primaryAlign ?? valuesTextAlign, | ||
| secondaryAlign: state.secondaryAlign ?? valuesTextAlign, | ||
| }; | ||
| } | ||
|
|
||
| if (secondaryPrefix && !newState.secondaryLabel) { | ||
| newState = { | ||
| ...newState, | ||
| secondaryLabel: secondaryPrefix, | ||
| }; | ||
| } | ||
|
|
||
| return newState; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
x-pack/platform/plugins/shared/lens/public/persistence/lens_client.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import { coreMock } from '@kbn/core/public/mocks'; | ||
|
|
||
| import type { LooseLensAttributes } from './lens_client'; | ||
| import { LensClient } from './lens_client'; | ||
|
|
||
| const mockResponse = { | ||
| data: {}, | ||
| meta: {}, | ||
| }; | ||
|
|
||
| const mockAttributes: LooseLensAttributes = { | ||
| title: 'Test Visualization', | ||
| visualizationType: 'lensXY', | ||
| state: { | ||
| visualization: {}, | ||
| }, | ||
| version: 1, | ||
| description: 'bar', | ||
| }; | ||
|
|
||
| describe('LensClient', () => { | ||
| const httpMock = coreMock.createStart().http; | ||
| const client = new LensClient(httpMock); | ||
|
|
||
| beforeAll(() => { | ||
| httpMock.get.mockResolvedValue(mockResponse); | ||
| httpMock.post.mockResolvedValue(mockResponse); | ||
| httpMock.put.mockResolvedValue(mockResponse); | ||
| httpMock.delete.mockResolvedValue({ response: { ok: true } }); | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it.todo('get'); | ||
| it.todo('update'); | ||
| it.todo('delete'); | ||
|
|
||
| describe('create', () => { | ||
| it('should throw an error if visualizationType is null', async () => { | ||
| await expect( | ||
| client.create( | ||
| { | ||
| ...mockAttributes, | ||
| visualizationType: null, | ||
| }, | ||
| [] | ||
| ) | ||
| ).rejects.toThrowErrorMatchingInlineSnapshot(`"Missing visualization type"`); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.