Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -542,6 +542,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