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 @@ -390,6 +390,42 @@ describe('state_helpers', () => {
).toEqual(expect.objectContaining({ columnOrder: ['col1', 'col2', 'col3'] }));
});

it('should not change order of metrics and references on inserting new buckets', () => {
const layer: IndexPatternLayer = {
indexPatternId: '1',
columnOrder: ['col1', 'col2'],
columns: {
col1: {
label: 'Cumulative sum of count of records',
dataType: 'number',
isBucketed: false,

// Private
operationType: 'cumulative_sum',
references: ['col2'],
},
col2: {
label: 'Count of records',
dataType: 'document',
isBucketed: false,

// Private
operationType: 'count',
sourceField: 'Records',
},
},
};
expect(
insertNewColumn({
layer,
indexPattern,
columnId: 'col3',
op: 'filters',
visualizationGroups: [],
})
).toEqual(expect.objectContaining({ columnOrder: ['col3', 'col1', 'col2'] }));
});

it('should insert both incomplete states if the aggregation does not support the field', () => {
expect(
insertNewColumn({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,10 @@ function addBucket(
visualizationGroups: VisualizationDimensionGroupConfig[],
targetGroup?: string
): IndexPatternLayer {
const [buckets, metrics, references] = getExistingColumnGroups(layer);
const [buckets, metrics] = _.partition(
layer.columnOrder,
(colId) => layer.columns[colId].isBucketed
);

const oldDateHistogramIndex = layer.columnOrder.findIndex(
(columnId) => layer.columns[columnId].operationType === 'date_histogram'
Expand All @@ -864,12 +867,11 @@ function addBucket(
addedColumnId,
...buckets.slice(oldDateHistogramIndex, buckets.length),
...metrics,
...references,
];
} else {
// Insert the new bucket after existing buckets. Users will see the same data
// they already had, with an extra level of detail.
updatedColumnOrder = [...buckets, addedColumnId, ...metrics, ...references];
updatedColumnOrder = [...buckets, addedColumnId, ...metrics];
}
updatedColumnOrder = reorderByGroups(
visualizationGroups,
Expand Down