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 @@ -144,6 +144,58 @@ describe('datatable_expression', () => {
});
});

test('it invokes executeTriggerActions with correct context on click on timefield from range', () => {
const data: LensMultiTable = {
type: 'lens_multitable',
tables: {
l1: {
type: 'kibana_datatable',
columns: [
{ id: 'a', name: 'a', meta: { type: 'date_range', aggConfigParams: { field: 'a' } } },
{ id: 'b', name: 'b', meta: { type: 'count' } },
],
rows: [{ a: 1588024800000, b: 3 }],
},
},
};

const args: DatatableProps['args'] = {
title: '',
columns: { columnIds: ['a', 'b'], type: 'lens_datatable_columns' },
};

const wrapper = mountWithIntl(
<DatatableComponent
data={{
...data,
dateRange: {
fromDate: new Date('2020-04-20T05:00:00.000Z'),
toDate: new Date('2020-05-03T05:00:00.000Z'),
},
}}
args={args}
formatFactory={(x) => x as IFieldFormat}
onClickValue={onClickValue}
getType={jest.fn(() => ({ type: 'buckets' } as IAggType))}
/>
);

wrapper.find('[data-test-subj="lensDatatableFilterFor"]').at(1).simulate('click');

expect(onClickValue).toHaveBeenCalledWith({
data: [
{
column: 0,
row: 0,
table: data.tables.l1,
value: 1588024800000,
},
],
negate: false,
timeFieldName: 'a',
});
});

test('it shows emptyPlaceholder for undefined bucketed data', () => {
const { args, data } = sampleArgs();
const emptyData: LensMultiTable = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,8 @@ export function DatatableComponent(props: DatatableRenderProps) {
const handleFilterClick = useMemo(
() => (field: string, value: unknown, colIndex: number, negate: boolean = false) => {
const col = firstTable.columns[colIndex];
const isDateHistogram = col.meta?.type === 'date_histogram';
const timeFieldName =
negate && isDateHistogram ? undefined : col?.meta?.aggConfigParams?.field;
const isDate = col.meta?.type === 'date_histogram' || col.meta?.type === 'date_range';
const timeFieldName = negate && isDate ? undefined : col?.meta?.aggConfigParams?.field;
const rowIndex = firstTable.rows.findIndex((row) => row[field] === value);

const data: LensFilterEvent['data'] = {
Expand Down
36 changes: 35 additions & 1 deletion x-pack/plugins/lens/public/pie_visualization/suggestions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,41 @@ describe('suggestions', () => {
columns: [
{
columnId: 'b',
operation: { label: 'Days', dataType: 'date' as DataType, isBucketed: true },
operation: {
label: 'Days',
dataType: 'date' as DataType,
isBucketed: true,
scale: 'interval',
},
},
{
columnId: 'c',
operation: { label: 'Count', dataType: 'number' as DataType, isBucketed: false },
},
],
changeType: 'initial',
},
state: undefined,
keptLayerIds: ['first'],
})
).toHaveLength(0);
});

it('should reject any histogram operations', () => {
expect(
suggestions({
table: {
layerId: 'first',
isMultiRow: true,
columns: [
{
columnId: 'b',
operation: {
label: 'Durations',
dataType: 'number' as DataType,
isBucketed: true,
scale: 'interval',
},
},
{
columnId: 'c',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function shouldReject({ table, keptLayerIds }: SuggestionRequest<PieVisualizatio
keptLayerIds.length > 1 ||
(keptLayerIds.length && table.layerId !== keptLayerIds[0]) ||
table.changeType === 'reorder' ||
table.columns.some((col) => col.operation.dataType === 'date')
table.columns.some((col) => col.operation.scale === 'interval') // Histograms are not good for pie
);
}

Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/lens/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ export interface OperationMetadata {
// A bucketed operation is grouped by duplicate values, otherwise each row is
// treated as unique
isBucketed: boolean;
/**
* ordinal: Each name is a unique value, but the names are in sorted order, like "Top values"
* interval: Histogram data, like date or number histograms
* ratio: Most number data is rendered as a ratio that includes 0
*/
scale?: 'ordinal' | 'interval' | 'ratio';
// Extra meta-information like cardinality, color
// TODO currently it's not possible to differentiate between a field from a raw
Expand Down
39 changes: 39 additions & 0 deletions x-pack/plugins/lens/public/xy_visualization/xy_suggestions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ describe('xy_suggestions', () => {
};
}

function histogramCol(columnId: string): TableSuggestionColumn {
return {
columnId,
operation: {
dataType: 'number',
isBucketed: true,
label: `${columnId} histogram`,
scale: 'interval',
},
};
}

// Helper that plucks out the important part of a suggestion for
// most test assertions
function suggestionSubset(suggestion: VisualizationSuggestion<State>) {
Expand Down Expand Up @@ -274,6 +286,33 @@ describe('xy_suggestions', () => {
`);
});

test('suggests all basic x y chart with histogram on x', () => {
(generateId as jest.Mock).mockReturnValueOnce('aaa');
const [suggestion, ...rest] = getSuggestions({
table: {
isMultiRow: true,
columns: [numCol('bytes'), histogramCol('duration')],
layerId: 'first',
changeType: 'unchanged',
},
keptLayerIds: [],
});

expect(rest).toHaveLength(visualizationTypes.length - 1);
expect(suggestionSubset(suggestion)).toMatchInlineSnapshot(`
Array [
Object {
"seriesType": "bar_stacked",
"splitAccessor": undefined,
"x": "duration",
"y": Array [
"bytes",
],
},
]
`);
});

test('does not suggest multiple splits', () => {
const suggestions = getSuggestions({
table: {
Expand Down
10 changes: 5 additions & 5 deletions x-pack/plugins/lens/public/xy_visualization/xy_suggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ function getBucketMappings(table: TableSuggestion, currentState?: State) {
const currentXColumnIndex = prioritizedBuckets.findIndex(
({ columnId }) => columnId === currentLayer.xAccessor
);
const currentXDataType =
currentXColumnIndex > -1 && prioritizedBuckets[currentXColumnIndex].operation.dataType;
const currentXScaleType =
currentXColumnIndex > -1 && prioritizedBuckets[currentXColumnIndex].operation.scale;

if (
currentXDataType &&
// make sure time gets mapped to x dimension even when changing current bucket/dimension mapping
(currentXDataType === 'date' || prioritizedBuckets[0].operation.dataType !== 'date')
currentXScaleType &&
// make sure histograms get mapped to x dimension even when changing current bucket/dimension mapping
(currentXScaleType === 'interval' || prioritizedBuckets[0].operation.scale !== 'interval')
) {
const [x] = prioritizedBuckets.splice(currentXColumnIndex, 1);
prioritizedBuckets.unshift(x);
Expand Down