Skip to content

Commit

Permalink
Fix formula auto reordering (#18)
Browse files Browse the repository at this point in the history
* fix formula auto reordering

* add unit test
  • Loading branch information
flash1293 authored May 20, 2021
1 parent 342c23d commit 4d7d2ba
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
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

0 comments on commit 4d7d2ba

Please sign in to comment.