-
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
[ES|QL] Adds the ability to breakdown the histogram in Discover #193820
Changes from 16 commits
7c79925
ef0e4e6
a4c9d0b
b05bcbf
6ec8eb8
906cc89
7609ce9
128a1a2
59a3d48
e1698d7
baf8933
97d8cbd
cc03575
527bf1b
3fb5319
1b95c94
cae1002
9e731df
e757a54
b66c58d
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 |
---|---|---|
|
@@ -11,7 +11,9 @@ import React, { useCallback, useMemo } from 'react'; | |
import { EuiSelectableOption } from '@elastic/eui'; | ||
import { FieldIcon, getFieldIconProps, comboBoxFieldOptionMatcher } from '@kbn/field-utils'; | ||
import { css } from '@emotion/react'; | ||
import type { DataView, DataViewField } from '@kbn/data-views-plugin/common'; | ||
import { type DataView, DataViewField } from '@kbn/data-views-plugin/common'; | ||
import type { DatatableColumn } from '@kbn/expressions-plugin/common'; | ||
import { convertDatatableColumnToDataViewFieldSpec } from '@kbn/data-view-utils'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { UnifiedHistogramBreakdownContext } from '../types'; | ||
import { fieldSupportsBreakdown } from '../utils/field_supports_breakdown'; | ||
|
@@ -25,17 +27,31 @@ import { | |
export interface BreakdownFieldSelectorProps { | ||
dataView: DataView; | ||
breakdown: UnifiedHistogramBreakdownContext; | ||
esqlColumns?: DatatableColumn[]; | ||
onBreakdownFieldChange?: (breakdownField: DataViewField | undefined) => void; | ||
} | ||
|
||
const mapToDropdownFields = (dataView: DataView, esqlColumns?: DatatableColumn[]) => { | ||
if (esqlColumns) { | ||
return esqlColumns.map((column) => ({ | ||
name: column.name, | ||
displayName: column.name, | ||
type: column.meta?.type, | ||
})); | ||
} | ||
|
||
return dataView.fields.filter(fieldSupportsBreakdown); | ||
}; | ||
|
||
export const BreakdownFieldSelector = ({ | ||
dataView, | ||
breakdown, | ||
esqlColumns, | ||
onBreakdownFieldChange, | ||
}: BreakdownFieldSelectorProps) => { | ||
const fields = useMemo(() => mapToDropdownFields(dataView, esqlColumns), [dataView, esqlColumns]); | ||
const fieldOptions: SelectableEntry[] = useMemo(() => { | ||
const options: SelectableEntry[] = dataView.fields | ||
.filter(fieldSupportsBreakdown) | ||
const options: SelectableEntry[] = fields | ||
.map((field) => ({ | ||
key: field.name, | ||
name: field.name, | ||
|
@@ -69,16 +85,24 @@ export const BreakdownFieldSelector = ({ | |
}); | ||
|
||
return options; | ||
}, [dataView, breakdown.field]); | ||
}, [fields, breakdown?.field]); | ||
|
||
const onChange = useCallback<NonNullable<ToolbarSelectorProps['onChange']>>( | ||
(chosenOption) => { | ||
const field = chosenOption?.value | ||
? dataView.fields.find((currentField) => currentField.name === chosenOption.value) | ||
: undefined; | ||
onBreakdownFieldChange?.(field); | ||
let breakdownField: DataViewField | undefined; | ||
if (esqlColumns) { | ||
const breakdownColumn = esqlColumns?.find((column) => column.name === chosenOption?.value); | ||
breakdownField = breakdownColumn | ||
? new DataViewField(convertDatatableColumnToDataViewFieldSpec(breakdownColumn)) | ||
: undefined; | ||
} else { | ||
breakdownField = chosenOption?.value | ||
? dataView.fields.find((currentField) => currentField.name === chosenOption.value) | ||
: undefined; | ||
} | ||
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. We could simplify this: remove 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. Sure! Done here 9e731df |
||
onBreakdownFieldChange?.(breakdownField); | ||
}, | ||
[dataView.fields, onBreakdownFieldChange] | ||
[dataView.fields, esqlColumns, onBreakdownFieldChange] | ||
); | ||
|
||
return ( | ||
|
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.
We could use
convertDatatableColumnToDataViewFieldSpec
here too for consistency in how types are treated and map asnew DataViewField(convertDatatableColumnToDataViewFieldSpec(column))
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.
We might also want to filter out unsupported field types with
fieldSupportsBreakdown
for ES|QL case too.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.
Very nice suggestion, implemented here 9e731df
Note: I don't filter out as we do with the dataview mode as they are not the same operations. Here you can group by with all the filed types. But I added a filter out for unsupported fields as these are not supported by the
BY
operator e757a54