Skip to content

Commit

Permalink
[Lens] Fix error in query from generated suggestion (#63018)
Browse files Browse the repository at this point in the history
* [Lens] Fix error in query from generated suggestion

* Update from review comments

* Fix test

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
Wylie Conlon and elasticmachine committed Apr 10, 2020
1 parent d5d610f commit f96f928
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -824,10 +824,10 @@ describe('IndexPattern Data Source suggestions', () => {
state: expect.objectContaining({
layers: expect.objectContaining({
currentLayer: expect.objectContaining({
columnOrder: ['cola', 'id1'],
columnOrder: ['cola', 'colb'],
columns: {
cola: initialState.layers.currentLayer.columns.cola,
id1: expect.objectContaining({
colb: expect.objectContaining({
operationType: 'avg',
sourceField: 'memory',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
operationDefinitionMap,
IndexPatternColumn,
} from './operations';
import { hasField } from './utils';
import { operationDefinitions } from './operations/definitions';
import { hasField } from './utils';
import {
IndexPattern,
IndexPatternPrivateState,
Expand Down Expand Up @@ -196,7 +196,7 @@ function addFieldAsMetricOperation(
suggestedPriority: undefined,
field,
});
const newColumnId = generateId();
const addedColumnId = generateId();

const [, metrics] = separateBucketColumns(layer);

Expand All @@ -206,20 +206,19 @@ function addFieldAsMetricOperation(
indexPatternId: indexPattern.id,
columns: {
...layer.columns,
[newColumnId]: newColumn,
[addedColumnId]: newColumn,
},
columnOrder: [...layer.columnOrder, newColumnId],
columnOrder: [...layer.columnOrder, addedColumnId],
};
}

// If only one metric, replace instead of add
const newColumns = { ...layer.columns, [newColumnId]: newColumn };
delete newColumns[metrics[0]];
// Replacing old column with new column, keeping the old ID
const newColumns = { ...layer.columns, [metrics[0]]: newColumn };

return {
indexPatternId: indexPattern.id,
columns: newColumns,
columnOrder: [...layer.columnOrder.filter(c => c !== metrics[0]), newColumnId],
columnOrder: layer.columnOrder, // Order is kept by replacing
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ describe('terms', () => {
expect(updatedColumn).toBe(initialColumn);
});

it('should switch to alphabetical ordering if the order column is removed', () => {
it('should switch to alphabetical ordering if there are no columns to order by', () => {
const termsColumn = termsOperation.onOtherColumnChanged!(
{
label: 'Top value of category',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const termsOperation: OperationDefinition<TermsIndexPatternColumn> = {
}
return currentColumn;
},
paramEditor: ({ state, setState, currentColumn, columnId: currentColumnId, layerId }) => {
paramEditor: ({ state, setState, currentColumn, layerId }) => {
const SEPARATOR = '$$$';
function toValue(orderBy: TermsIndexPatternColumn['params']['orderBy']) {
if (orderBy.type === 'alphabetical') {
Expand Down

0 comments on commit f96f928

Please sign in to comment.