-
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 all 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; | ||
}; | ||
|
||
export 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 |
---|---|---|
|
@@ -27,7 +27,6 @@ describe('LensStore', () => { | |
title: 'Hello', | ||
visualizationType: 'bar', | ||
expression: '', | ||
activeDatasourceId: 'indexpattern', | ||
state: { | ||
datasourceMetaData: { | ||
filterableIndexPatterns: [], | ||
|
@@ -46,7 +45,6 @@ describe('LensStore', () => { | |
title: 'Hello', | ||
visualizationType: 'bar', | ||
expression: '', | ||
activeDatasourceId: 'indexpattern', | ||
state: { | ||
datasourceMetaData: { | ||
filterableIndexPatterns: [], | ||
|
@@ -64,18 +62,16 @@ describe('LensStore', () => { | |
expect(client.create).toHaveBeenCalledWith('lens', { | ||
title: 'Hello', | ||
visualizationType: 'bar', | ||
|
||
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: [], | ||
}), | ||
}, | ||
}); | ||
}); | ||
|
||
|
@@ -86,7 +82,6 @@ describe('LensStore', () => { | |
title: 'Even the very wise cannot see all ends.', | ||
visualizationType: 'line', | ||
expression: '', | ||
activeDatasourceId: 'indexpattern', | ||
state: { | ||
datasourceMetaData: { filterableIndexPatterns: [] }, | ||
datasourceStates: { indexpattern: { type: 'index_pattern', indexPattern: 'lotr' } }, | ||
|
@@ -101,7 +96,6 @@ describe('LensStore', () => { | |
title: 'Even the very wise cannot see all ends.', | ||
visualizationType: 'line', | ||
expression: '', | ||
activeDatasourceId: 'indexpattern', | ||
state: { | ||
datasourceMetaData: { filterableIndexPatterns: [] }, | ||
datasourceStates: { indexpattern: { type: 'index_pattern', indexPattern: 'lotr' } }, | ||
|
@@ -116,46 +110,18 @@ describe('LensStore', () => { | |
title: 'Even the very wise cannot see all ends.', | ||
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 () => ({ | ||
|
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.