Skip to content

Commit

Permalink
✅ Add custom range test case + adds better comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dej611 committed Oct 15, 2020
1 parent eefab3b commit ae5406f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,81 @@ describe('IndexPattern Data Source suggestions', () => {
);
});

it('adds date histogram over default time field for custom range intervals', async () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
...initialState,
layers: {
first: {
indexPatternId: '1',
columnOrder: ['colb', 'cola'],
columns: {
cola: {
dataType: 'number',
isBucketed: false,
sourceField: 'dest',
label: 'Unique count of dest',
operationType: 'cardinality',
},
colb: {
label: 'My Custom Range',
dataType: 'string',
isBucketed: true,
operationType: 'range',
sourceField: 'bytes',
scale: 'ordinal',
params: {
type: 'range',
maxBars: 100,
ranges: [{ from: 1, to: 2, label: '' }],
},
},
},
},
},
};

expect(getDatasourceSuggestionsFromCurrentState(state)).toContainEqual(
expect.objectContaining({
table: {
changeType: 'extended',
columns: [
{
columnId: 'colb',
operation: {
dataType: 'string',
isBucketed: true,
label: 'My Custom Range',
scale: 'ordinal',
},
},
{
columnId: 'id1',
operation: {
dataType: 'date',
isBucketed: true,
label: 'timestampLabel',
scale: 'interval',
},
},
{
columnId: 'cola',
operation: {
dataType: 'number',
isBucketed: false,
label: 'Unique count of dest',
scale: undefined,
},
},
],
isMultiRow: true,
label: 'Over time',
layerId: 'first',
},
})
);
});

it('does not create an over time suggestion if there is no default time field', async () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,8 @@ export function getDatasourceSuggestionsFromCurrentState(
} else {
suggestions.push(...createSimplifiedTableSuggestions(state, layerId));

// base range intervals are of number dataType.
// Custom range/intervals have a different dataType so they still receive the Over Time suggestion
if (!timeDimension && timeField && !hasNumericDimension) {
// suggest current configuration over time if there is a default time field
// and no time dimension yet
Expand Down

0 comments on commit ae5406f

Please sign in to comment.