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] Fix error in query from generated suggestion #63018

Merged
merged 6 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -827,7 +827,7 @@ describe('IndexPattern Data Source suggestions', () => {
columnOrder: ['cola', 'id1'],
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 }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused: How did this compile before this PR? I mean I see why it needs to change, but I don't get how the old version was able to compile at all?

Copy link
Contributor Author

@wylieconlon wylieconlon Apr 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was a case that was not being caught by the linter, potentially because the name columnId is used. My editor showed the grayed-out text indicating an unused name, so I removed it.

const SEPARATOR = '$$$';
function toValue(orderBy: TermsIndexPatternColumn['params']['orderBy']) {
if (orderBy.type === 'alphabetical') {
Expand Down