-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Lens] Remove unnecessary fields and indexing from mappings #43285
Changes from 3 commits
cd75f01
f9ac2df
e07c5ed
92486e2
2d47bc1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,21 @@ export type Action = | |
newDatasourceId: string; | ||
}; | ||
|
||
function getActiveDatasourceIdFromDoc(doc?: Document) { | ||
if (!doc) { | ||
return null; | ||
} | ||
|
||
const [initialDatasourceId] = Object.keys(doc.state.datasourceStates); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well you were asking about what the role of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think using the first one in the doc is fine. |
||
return initialDatasourceId || null; | ||
} | ||
|
||
function getInitialDatasourceId(props: EditorFrameProps) { | ||
return props.initialDatasourceId | ||
? props.initialDatasourceId | ||
: getActiveDatasourceIdFromDoc(props.doc); | ||
} | ||
|
||
export const getInitialState = (props: EditorFrameProps): EditorFrameState => { | ||
const datasourceStates: EditorFrameState['datasourceStates'] = {}; | ||
|
||
|
@@ -81,7 +96,7 @@ export const getInitialState = (props: EditorFrameProps): EditorFrameState => { | |
return { | ||
title: i18n.translate('xpack.lens.chartTitle', { defaultMessage: 'New visualization' }), | ||
datasourceStates, | ||
activeDatasourceId: props.initialDatasourceId ? props.initialDatasourceId : null, | ||
activeDatasourceId: getInitialDatasourceId(props), | ||
visualization: { | ||
state: null, | ||
activeId: props.initialVisualizationId, | ||
|
@@ -124,7 +139,7 @@ export const reducer = (state: EditorFrameState, action: Action): EditorFrameSta | |
}), | ||
{} | ||
), | ||
activeDatasourceId: action.doc.activeDatasourceId, | ||
activeDatasourceId: getActiveDatasourceIdFromDoc(action.doc), | ||
visualization: { | ||
...state.visualization, | ||
activeId: action.doc.visualizationType, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,15 +67,15 @@ describe('LensStore', () => { | |
|
||
expression: '', | ||
activeDatasourceId: 'indexpattern', | ||
state: JSON.stringify({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 |
||
state: { | ||
datasourceMetaData: { filterableIndexPatterns: [] }, | ||
datasourceStates: { | ||
indexpattern: { type: 'index_pattern', indexPattern: '.kibana_test' }, | ||
}, | ||
visualization: { x: 'foo', y: 'baz' }, | ||
query: { query: '', language: 'lucene' }, | ||
filters: [], | ||
}), | ||
}, | ||
}); | ||
}); | ||
|
||
|
@@ -117,45 +117,18 @@ describe('LensStore', () => { | |
visualizationType: 'line', | ||
expression: '', | ||
activeDatasourceId: 'indexpattern', | ||
state: JSON.stringify({ | ||
state: { | ||
datasourceMetaData: { filterableIndexPatterns: [] }, | ||
datasourceStates: { indexpattern: { type: 'index_pattern', indexPattern: 'lotr' } }, | ||
visualization: { gear: ['staff', 'pointy hat'] }, | ||
query: { query: '', language: 'lucene' }, | ||
filters: [], | ||
}), | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('load', () => { | ||
test('parses the visState', async () => { | ||
const { client, store } = testStore(); | ||
client.get = jest.fn(async () => ({ | ||
id: 'Paul', | ||
type: 'lens', | ||
attributes: { | ||
title: 'Hope clouds observation.', | ||
visualizationType: 'dune', | ||
state: '{ "datasource": { "giantWorms": true } }', | ||
}, | ||
})); | ||
const doc = await store.load('Paul'); | ||
|
||
expect(doc).toEqual({ | ||
id: 'Paul', | ||
type: 'lens', | ||
title: 'Hope clouds observation.', | ||
visualizationType: 'dune', | ||
state: { | ||
datasource: { giantWorms: true }, | ||
}, | ||
}); | ||
|
||
expect(client.get).toHaveBeenCalledTimes(1); | ||
expect(client.get).toHaveBeenCalledWith('lens', 'Paul'); | ||
}); | ||
|
||
test('throws if an error is returned', async () => { | ||
const { client, store } = testStore(); | ||
client.get = jest.fn(async () => ({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ export interface Document { | |
type?: string; | ||
visualizationType: string | null; | ||
title: string; | ||
activeDatasourceId: string; | ||
expression: string; | ||
state: { | ||
datasourceMetaData: { | ||
|
@@ -62,18 +61,17 @@ export class SavedObjectIndexStore implements SavedObjectStore { | |
|
||
async save(vis: Document) { | ||
const { id, type, ...rest } = vis; | ||
const attributes = { | ||
...rest, | ||
state: JSON.stringify(rest.state), | ||
}; | ||
|
||
// Any is the most straighforward way out here, since the saved | ||
// object client doesn't allow unknowns, and we have them in | ||
// our object. | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const attributes: any = rest; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, the types of the saved object client can be improved in this regard. However we don't need to fall back to disabling linting rules, the "any-less" way of doing that would be
|
||
const result = await (id | ||
? this.client.update(DOC_TYPE, id, attributes) | ||
: this.client.create(DOC_TYPE, attributes)); | ||
|
||
return { | ||
...vis, | ||
id: result.id, | ||
}; | ||
return { ...vis, id: result.id }; | ||
} | ||
|
||
async load(id: string): Promise<Document> { | ||
|
@@ -87,7 +85,6 @@ export class SavedObjectIndexStore implements SavedObjectStore { | |
...attributes, | ||
id, | ||
type, | ||
state: JSON.parse(((attributes as unknown) as { state: string }).state as string), | ||
} as Document; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an elasticsearch mapping, right?
state.datasourceMetadata
and all of the other object properties seem important to map individuallyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this approach is the right one. It's a blob as far as elasticsearch is concerned. We don't need to dive into the details of it now. If we ever do, we can migrate and extract state as needed.