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

Finalize eligibility check for augmenting visualizations by vis augmenter #3687

Merged
Show file tree
Hide file tree
Changes from 3 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
33 changes: 33 additions & 0 deletions src/plugins/vis_augmenter/public/test_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { OpenSearchDashboardsDatatable } from '../../expressions/public';
import { VIS_LAYER_COLUMN_TYPE, VisLayerTypes, HOVER_PARAM } from './';

const TEST_X_AXIS_ID = 'test-x-axis-id';
const TEST_X_AXIS_ID_DIRTY = 'test.x.axis.id';
const TEST_VALUE_AXIS_ID = 'test-value-axis-id';
const TEST_VALUE_AXIS_ID_DIRTY = 'test.value.axis.id';
const TEST_X_AXIS_TITLE = 'time';
const TEST_VALUE_AXIS_TITLE = 'avg value';
const TEST_PLUGIN = 'test-plugin';
Expand Down Expand Up @@ -53,6 +55,20 @@ const TEST_VALUES_NO_VIS_LAYERS = [
{ [TEST_X_AXIS_ID]: 50, [TEST_VALUE_AXIS_ID]: 5 },
];

const TEST_VALUES_NO_VIS_LAYERS_DIRTY = [
{ [TEST_X_AXIS_ID_DIRTY]: 0, [TEST_VALUE_AXIS_ID_DIRTY]: 5 },
{ [TEST_X_AXIS_ID_DIRTY]: 5, [TEST_VALUE_AXIS_ID_DIRTY]: 10 },
{ [TEST_X_AXIS_ID_DIRTY]: 10, [TEST_VALUE_AXIS_ID_DIRTY]: 6 },
{ [TEST_X_AXIS_ID_DIRTY]: 15, [TEST_VALUE_AXIS_ID_DIRTY]: 4 },
{ [TEST_X_AXIS_ID_DIRTY]: 20, [TEST_VALUE_AXIS_ID_DIRTY]: 5 },
{ [TEST_X_AXIS_ID_DIRTY]: 25 },
{ [TEST_X_AXIS_ID_DIRTY]: 30 },
{ [TEST_X_AXIS_ID_DIRTY]: 35 },
{ [TEST_X_AXIS_ID_DIRTY]: 40 },
{ [TEST_X_AXIS_ID_DIRTY]: 45, [TEST_VALUE_AXIS_ID_DIRTY]: 3 },
{ [TEST_X_AXIS_ID_DIRTY]: 50, [TEST_VALUE_AXIS_ID_DIRTY]: 5 },
];

const TEST_VALUES_SINGLE_VIS_LAYER = [
{ [TEST_X_AXIS_ID]: 0, [TEST_VALUE_AXIS_ID]: 5 },
{ [TEST_X_AXIS_ID]: 5, [TEST_VALUE_AXIS_ID]: 10, [TEST_PLUGIN_RESOURCE_ID]: 2 },
Expand Down Expand Up @@ -111,6 +127,17 @@ export const TEST_COLUMNS_NO_VIS_LAYERS = [
},
];

export const TEST_COLUMNS_NO_VIS_LAYERS_DIRTY = [
{
id: TEST_X_AXIS_ID_DIRTY,
name: TEST_X_AXIS_TITLE,
},
{
id: TEST_VALUE_AXIS_ID_DIRTY,
name: TEST_VALUE_AXIS_TITLE,
},
];

export const TEST_COLUMNS_SINGLE_VIS_LAYER = [
...TEST_COLUMNS_NO_VIS_LAYERS,
{
Expand Down Expand Up @@ -157,6 +184,12 @@ export const TEST_DATATABLE_NO_VIS_LAYERS = {
rows: TEST_VALUES_NO_VIS_LAYERS,
} as OpenSearchDashboardsDatatable;

export const TEST_DATATABLE_NO_VIS_LAYERS_DIRTY = {
type: 'opensearch_dashboards_datatable',
columns: TEST_COLUMNS_NO_VIS_LAYERS_DIRTY,
rows: TEST_VALUES_NO_VIS_LAYERS_DIRTY,
} as OpenSearchDashboardsDatatable;

export const TEST_DATATABLE_SINGLE_VIS_LAYER_EMPTY = {
...TEST_DATATABLE_NO_VIS_LAYERS,
columns: TEST_COLUMNS_SINGLE_VIS_LAYER,
Expand Down
68 changes: 63 additions & 5 deletions src/plugins/vis_augmenter/public/utils/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import {
getMockAugmentVisSavedObjectClient,
generateAugmentVisSavedObject,
} from '../saved_augment_vis';
import { AggConfigs, AggTypesRegistryStart } from '../../../data/common/search/aggs';
import { stubIndexPatternWithFields } from '../../../data/common/index_patterns/index_pattern.stub';
import { IndexPattern } from '../../../data/common/index_patterns/index_patterns';
import { AggConfigs, AggTypesRegistryStart, IndexPattern } from '../../../data/common';
import { mockAggTypesRegistry } from '../../../data/common/search/aggs/test_helpers';

describe('utils', () => {
Expand All @@ -37,15 +35,31 @@ describe('utils', () => {
const configStates = [
{
enabled: true,
type: 'histogram',
type: 'max',
params: {},
schema: 'metric',
},
{
enabled: true,
type: 'date_histogram',
params: {},
schema: 'segment',
},
];
const stubIndexPatternWithFields = {
id: '1234',
title: 'logstash-*',
fields: [
{
name: 'response',
type: 'number',
esTypes: ['integer'],
aggregatable: true,
filterable: true,
searchable: true,
},
],
};
const typesRegistry: AggTypesRegistryStart = mockAggTypesRegistry();
const aggs = new AggConfigs(stubIndexPatternWithFields as IndexPattern, configStates, {
typesRegistry,
Expand All @@ -58,6 +72,11 @@ describe('utils', () => {
type: 'line',
},
],
categoryAxes: [
{
position: 'bottom',
},
],
},
data: {
aggs,
Expand All @@ -68,6 +87,11 @@ describe('utils', () => {
params: {
type: 'not-line',
seriesParams: [],
categoryAxes: [
{
position: 'bottom',
},
],
},
data: {
aggs,
Expand Down Expand Up @@ -115,13 +139,15 @@ describe('utils', () => {
},
{
enabled: true,
type: 'date_histogram',
type: 'dot',
params: {},
schema: 'radius',
},
{
enabled: true,
type: 'metrics',
params: {},
schema: 'metrics',
},
];
const invalidAggs = new AggConfigs(
Expand Down Expand Up @@ -151,13 +177,45 @@ describe('utils', () => {
type: 'area',
},
],
categoryAxes: [
{
position: 'bottom',
},
],
},
data: {
aggs,
},
} as unknown) as Vis;
expect(isEligibleForVisLayers(vis, validDimensions)).toEqual(false);
});
it('vis is ineligible with invalid dimensions', async () => {
const invalidDimensions = {
x: null,
} as VislibDimensions;
expect(isEligibleForVisLayers(validVis, invalidDimensions)).toEqual(false);
});
it('vis is ineligible with xaxis not on bottom', async () => {
const invalidVis = ({
params: {
type: 'line',
seriesParams: [
{
type: 'line',
},
],
categoryAxes: [
{
position: 'top',
},
],
},
data: {
aggs,
},
} as unknown) as Vis;
expect(isEligibleForVisLayers(invalidVis, validDimensions)).toEqual(false);
lezzago marked this conversation as resolved.
Show resolved Hide resolved
});
it('vis is eligible with valid type', async () => {
expect(isEligibleForVisLayers(validVis, validDimensions)).toEqual(true);
});
Expand Down
15 changes: 12 additions & 3 deletions src/plugins/vis_augmenter/public/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,23 @@ import {
import { ISavedAugmentVis, SavedAugmentVisLoader, VisLayerFunctionDefinition } from '../';

export const isEligibleForVisLayers = (vis: Vis, dimensions: VislibDimensions): boolean => {
const isDateHistogram =
vis.data.aggs?.byTypeName('date_histogram').length === 1 && vis.data.aggs?.aggs.length === 2;
// Only support date histogram and ensure there is only 1 x-axis and it has to be on the bottom
const isValidXaxis =
vis.data.aggs?.byTypeName('date_histogram').length === 1 &&
vis.params.categoryAxes.length === 1 &&
vis.params.categoryAxes[0].position === 'bottom';
joshuarrrr marked this conversation as resolved.
Show resolved Hide resolved
// Support 1 segment for x axis bucket (that is date_histogram) and support metrics for
// multiple supported yaxis only. If there are other aggregation types, this is not
// valid for augmentation
const hasCorrectAggregationCount =
vis.data.aggs !== undefined &&
vis.data.aggs?.bySchemaName('metric').length === vis.data.aggs?.aggs.length - 1;
lezzago marked this conversation as resolved.
Show resolved Hide resolved
let isOnlyLine = vis.params.type === 'line';
lezzago marked this conversation as resolved.
Show resolved Hide resolved
vis.params.seriesParams.forEach((seriesParam: { type: string }) => {
isOnlyLine = isOnlyLine && seriesParam.type === 'line';
});
const isValidDimensions = dimensions.x !== null;
lezzago marked this conversation as resolved.
Show resolved Hide resolved
return isDateHistogram && isOnlyLine && isValidDimensions;
return isValidXaxis && hasCorrectAggregationCount && isOnlyLine && isValidDimensions;
};

/**
Expand Down
Loading