-
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] Make operation order more clear to users #48305
Changes from 2 commits
630c738
41cef94
3529392
05da4b6
b96cf52
59646e2
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 |
---|---|---|
|
@@ -7,8 +7,11 @@ | |
import _ from 'lodash'; | ||
import React from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EuiFormRow, EuiHorizontalRule, EuiSwitch, EuiSelect } from '@elastic/eui'; | ||
import { EuiFormRow, EuiHorizontalRule, EuiRadio, EuiSelect, htmlIdGenerator } from '@elastic/eui'; | ||
import { IndexPatternLayer } from '../types'; | ||
import { hasField } from '../utils'; | ||
|
||
const generator = htmlIdGenerator('lens-nesting'); | ||
|
||
function nestColumn(columnOrder: string[], outer: string, inner: string) { | ||
const result = columnOrder.filter(c => c !== inner); | ||
|
@@ -32,35 +35,75 @@ export function BucketNestingEditor({ | |
const columns = Object.entries(layer.columns); | ||
const aggColumns = columns | ||
.filter(([id, c]) => id !== columnId && c.isBucketed) | ||
.map(([value, c]) => ({ value, text: c.label })); | ||
.map(([value, c]) => ({ | ||
value, | ||
text: c.label, | ||
fieldName: hasField(c) ? c.sourceField : '', | ||
})); | ||
|
||
if (!column || !column.isBucketed || !aggColumns.length) { | ||
return null; | ||
} | ||
|
||
const fieldName = hasField(column) ? column.sourceField : ''; | ||
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. This is the same logic as above. Not a big deal. But might be something we can tidy up later. |
||
|
||
const prevColumn = layer.columnOrder[layer.columnOrder.indexOf(columnId) - 1]; | ||
|
||
if (aggColumns.length === 1) { | ||
const [target] = aggColumns; | ||
|
||
function toggleNesting() { | ||
if (prevColumn) { | ||
setColumns(nestColumn(layer.columnOrder, columnId, target.value)); | ||
} else { | ||
setColumns(nestColumn(layer.columnOrder, target.value, columnId)); | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<EuiHorizontalRule margin="m" /> | ||
<EuiSwitch | ||
data-test-subj="indexPattern-nesting-switch" | ||
label={i18n.translate('xpack.lens.xyChart.nestUnderTarget', { | ||
defaultMessage: 'Nest under {target}', | ||
values: { target: target.text }, | ||
<EuiFormRow | ||
label={i18n.translate('xpack.lens.indexPattern.groupingControlLabel', { | ||
defaultMessage: 'Grouping', | ||
})} | ||
checked={!!prevColumn} | ||
onChange={() => { | ||
if (prevColumn) { | ||
setColumns(nestColumn(layer.columnOrder, columnId, target.value)); | ||
} else { | ||
setColumns(nestColumn(layer.columnOrder, target.value, columnId)); | ||
} | ||
}} | ||
/> | ||
> | ||
<> | ||
<EuiRadio | ||
id={generator()} | ||
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'm not familiar with this, but is this predictive, or is it going to cause render churn? It seems totally fine to me to just specify an ID schematically here. 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. Looks like I'm supposed to pass a string, and it'll generate consistent ids if given a string. |
||
data-test-subj="indexPattern-nesting-topLevel" | ||
label={ | ||
column.operationType === 'terms' | ||
? i18n.translate('xpack.lens.indexPattern.groupingOverallTerms', { | ||
defaultMessage: 'Overall top {field}', | ||
values: { field: fieldName }, | ||
}) | ||
: i18n.translate('xpack.lens.indexPattern.groupingOverallDateHistogram', { | ||
defaultMessage: 'Dates overall', | ||
}) | ||
} | ||
checked={!prevColumn} | ||
onChange={toggleNesting} | ||
/> | ||
<EuiRadio | ||
id={generator()} | ||
data-test-subj="indexPattern-nesting-bottomLevel" | ||
label={ | ||
column.operationType === 'terms' | ||
? i18n.translate('xpack.lens.indexPattern.groupingSecondTerms', { | ||
defaultMessage: 'Top values for each {target}', | ||
values: { target: target.fieldName }, | ||
}) | ||
: i18n.translate('xpack.lens.indexPattern.groupingSecondDateHistogram', { | ||
defaultMessage: 'Dates for each {target}', | ||
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 find this verbiage pretty confusing. I think 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 don't think it improves the readability to use field names like that- especially when the editor is showing the current field in multiple places. |
||
values: { target: target.fieldName }, | ||
}) | ||
} | ||
checked={!!prevColumn} | ||
onChange={toggleNesting} | ||
/> | ||
</> | ||
</EuiFormRow> | ||
</> | ||
); | ||
} | ||
|
@@ -69,8 +112,8 @@ export function BucketNestingEditor({ | |
<> | ||
<EuiHorizontalRule margin="m" /> | ||
<EuiFormRow | ||
label={i18n.translate('xpack.lens.xyChart.nestUnder', { | ||
defaultMessage: 'Nest under', | ||
label={i18n.translate('xpack.lens.indexPattern.groupByDropdown', { | ||
defaultMessage: 'Group by', | ||
})} | ||
display="rowCompressed" | ||
> | ||
|
@@ -81,7 +124,7 @@ export function BucketNestingEditor({ | |
{ | ||
value: '', | ||
text: i18n.translate('xpack.lens.xyChart.nestUnderRoot', { | ||
defaultMessage: 'Top level', | ||
defaultMessage: 'Entire data set', | ||
}), | ||
}, | ||
...aggColumns, | ||
|
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.
Could be simplified, I think: