Skip to content
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] Optimize dimension panel flow #41114

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,41 @@ describe('IndexPatternDimensionPanel', () => {
});
});

it('should select operation directly if only one field is possible', () => {
const initialState = {
...defaultProps.state,
indexPatterns: {
1: {
...defaultProps.state.indexPatterns['1'],
fields: defaultProps.state.indexPatterns['1'].fields.filter(
field => field.name !== 'memory'
),
},
},
};

wrapper = mount(
<IndexPatternDimensionPanel {...defaultProps} state={initialState} columnId={'col2'} />
);

openPopover();

wrapper.find('button[data-test-subj="lns-indexPatternDimension-avg"]').simulate('click');

expect(setState).toHaveBeenCalledWith({
...initialState,
columns: {
...state.columns,
col2: expect.objectContaining({
sourceField: 'bytes',
operationType: 'avg',
// Other parts of this don't matter for this test
}),
},
columnOrder: ['col1', 'col2'],
});
});

it('should indicate compatible fields when selecting the operation first', () => {
wrapper = mount(<IndexPatternDimensionPanel {...defaultProps} columnId={'col2'} />);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,19 @@ export function PopoverEditor(props: PopoverEditorProps) {
}),
'data-test-subj': `lns-indexPatternDimension-${operationType}`,
onClick() {
if (!selectedColumn || !compatibleWithCurrentField) {
if (!selectedColumn) {
const possibleColumns = _.uniq(
filteredColumns.filter(col => col.operationType === operationType),
'sourceField'
);
if (possibleColumns.length === 1) {
setState(changeColumn(state, columnId, possibleColumns[0]));
} else {
setInvalidOperationType(operationType);
}
return;
}
if (!compatibleWithCurrentField) {
setInvalidOperationType(operationType);
return;
}
Expand Down Expand Up @@ -179,6 +191,16 @@ export function PopoverEditor(props: PopoverEditorProps) {
</p>
</EuiCallOut>
)}
{incompatibleSelectedOperationType && !selectedColumn && (
<EuiCallOut
size="s"
data-test-subj="indexPattern-fieldless-operation"
title={i18n.translate('xpack.lens.indexPattern.fieldlessOperationLabel', {
defaultMessage: 'Choose a field the operation is applied to',
})}
iconType="alert"
></EuiCallOut>
)}
{!incompatibleSelectedOperationType && ParamEditor && (
<ParamEditor
state={state}
Expand Down