forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ES|QL][Lens] Remove allColumns from state (elastic#174500)
## Summary The basic feature that this PR offers is the removal of allColumns from the state. It now retrieves them from the cache when they are needed. This is going to make the SO much lighter and improve a bit the performance. This must be bwc. I also think that it makes the state much easier to understand and the code so it is a very nice technical improvement. ### Checklist - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- Loading branch information
Showing
26 changed files
with
345 additions
and
552 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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
111 changes: 111 additions & 0 deletions
111
x-pack/plugins/lens/public/datasources/text_based/components/dimension_editor.tsx
This file contains 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,111 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EuiFormRow } from '@elastic/eui'; | ||
import { euiThemeVars } from '@kbn/ui-theme'; | ||
import type { ExpressionsStart } from '@kbn/expressions-plugin/public'; | ||
import type { DatasourceDimensionEditorProps, DataType } from '../../../types'; | ||
import { FieldSelect } from './field_select'; | ||
import type { TextBasedPrivateState } from '../types'; | ||
import { retrieveLayerColumnsFromCache, getColumnsFromCache } from '../fieldlist_cache'; | ||
|
||
export type TextBasedDimensionEditorProps = | ||
DatasourceDimensionEditorProps<TextBasedPrivateState> & { | ||
expressions: ExpressionsStart; | ||
}; | ||
|
||
export function TextBasedDimensionEditor(props: TextBasedDimensionEditorProps) { | ||
const query = props.state.layers[props.layerId]?.query; | ||
|
||
const allColumns = retrieveLayerColumnsFromCache( | ||
props.state.layers[props.layerId]?.columns ?? [], | ||
query | ||
); | ||
const allFields = query ? getColumnsFromCache(query) : []; | ||
const hasNumberTypeColumns = allColumns?.some((c) => c?.meta?.type === 'number'); | ||
const fields = allFields.map((col) => { | ||
return { | ||
id: col.id, | ||
name: col.name, | ||
meta: col?.meta ?? { type: 'number' }, | ||
compatible: | ||
props.isMetricDimension && hasNumberTypeColumns | ||
? props.filterOperations({ | ||
dataType: col?.meta?.type as DataType, | ||
isBucketed: Boolean(col?.meta?.type !== 'number'), | ||
scale: 'ordinal', | ||
}) | ||
: true, | ||
}; | ||
}); | ||
const selectedField = allColumns?.find((column) => column.columnId === props.columnId); | ||
|
||
return ( | ||
<> | ||
<EuiFormRow | ||
data-test-subj="text-based-languages-field-selection-row" | ||
label={i18n.translate('xpack.lens.textBasedLanguages.chooseField', { | ||
defaultMessage: 'Field', | ||
})} | ||
fullWidth | ||
className="lnsIndexPatternDimensionEditor--padded" | ||
> | ||
<FieldSelect | ||
existingFields={fields ?? []} | ||
selectedField={selectedField} | ||
onChoose={(choice) => { | ||
const meta = fields?.find((f) => f.name === choice.field)?.meta; | ||
const newColumn = { | ||
columnId: props.columnId, | ||
fieldName: choice.field, | ||
meta, | ||
}; | ||
return props.setState( | ||
!selectedField | ||
? { | ||
...props.state, | ||
layers: { | ||
...props.state.layers, | ||
[props.layerId]: { | ||
...props.state.layers[props.layerId], | ||
columns: [...props.state.layers[props.layerId].columns, newColumn], | ||
}, | ||
}, | ||
} | ||
: { | ||
...props.state, | ||
layers: { | ||
...props.state.layers, | ||
[props.layerId]: { | ||
...props.state.layers[props.layerId], | ||
columns: props.state.layers[props.layerId].columns.map((col) => | ||
col.columnId !== props.columnId | ||
? col | ||
: { ...col, fieldName: choice.field, meta } | ||
), | ||
}, | ||
}, | ||
} | ||
); | ||
}} | ||
/> | ||
</EuiFormRow> | ||
{props.dataSectionExtra && ( | ||
<div | ||
style={{ | ||
paddingLeft: euiThemeVars.euiSize, | ||
paddingRight: euiThemeVars.euiSize, | ||
}} | ||
> | ||
{props.dataSectionExtra} | ||
</div> | ||
)} | ||
</> | ||
); | ||
} |
Oops, something went wrong.