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

[Feature Anywhere] Fix visibleVisLayers ser/deser #3758

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 13 additions & 0 deletions src/plugins/vis_augmenter/public/test_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,19 @@ export const TEST_VIS_LAYERS_SINGLE_INVALID_BOUNDS = [
},
];

export const TEST_VIS_LAYERS_SINGLE_EMPTY_EVENTS = [
{
originPlugin: TEST_PLUGIN,
type: VisLayerTypes.PointInTimeEvents,
pluginResource: {
type: TEST_PLUGIN_RESOURCE_TYPE,
id: TEST_PLUGIN_RESOURCE_ID,
name: TEST_PLUGIN_RESOURCE_NAME,
urlPath: TEST_PLUGIN_RESOURCE_PATH,
},
},
];

export const TEST_VIS_LAYERS_SINGLE_ON_BOUNDS = [
{
originPlugin: TEST_PLUGIN,
Expand Down
34 changes: 24 additions & 10 deletions src/plugins/vis_augmenter/public/vega/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
TEST_SPEC_SINGLE_VIS_LAYER,
TEST_VIS_LAYERS_MULTIPLE,
TEST_VIS_LAYERS_SINGLE,
TEST_VIS_LAYERS_SINGLE_EMPTY_EVENTS,
TEST_VIS_LAYERS_SINGLE_INVALID_BOUNDS,
TEST_VIS_LAYERS_SINGLE_ON_BOUNDS,
} from '../test_constants';
Expand Down Expand Up @@ -81,11 +82,11 @@ describe('helpers', function () {
const updatedConfig = enableVisLayersInSpecConfig({ config: baseConfig }, [
pointInTimeEventsVisLayer,
]);
const expectedMap = new Map<VisLayerTypes, boolean>([
[VisLayerTypes.PointInTimeEvents, true],
]);
const expectedArr = [
...new Map<VisLayerTypes, boolean>([[VisLayerTypes.PointInTimeEvents, true]]),
];
// @ts-ignore
baseConfig.kibana.visibleVisLayers = expectedMap;
baseConfig.kibana.visibleVisLayers = expectedArr;
expect(updatedConfig).toStrictEqual(baseConfig);
});
it('updates config with a valid and invalid VisLayer', function () {
Expand All @@ -98,11 +99,11 @@ describe('helpers', function () {
pointInTimeEventsVisLayer,
invalidVisLayer,
]);
const expectedMap = new Map<VisLayerTypes, boolean>([
[VisLayerTypes.PointInTimeEvents, true],
]);
const expectedArr = [
...new Map<VisLayerTypes, boolean>([[VisLayerTypes.PointInTimeEvents, true]]),
];
// @ts-ignore
baseConfig.kibana.visibleVisLayers = expectedMap;
baseConfig.kibana.visibleVisLayers = expectedArr;
expect(updatedConfig).toStrictEqual(baseConfig);
});
it('does not update config if no valid VisLayer', function () {
Expand All @@ -113,7 +114,7 @@ describe('helpers', function () {
};
const updatedConfig = enableVisLayersInSpecConfig({ config: baseConfig }, [invalidVisLayer]);
// @ts-ignore
baseConfig.kibana.visibleVisLayers = new Map<VisLayerTypes, boolean>();
baseConfig.kibana.visibleVisLayers = [...new Map<VisLayerTypes, boolean>()];
expect(updatedConfig).toStrictEqual(baseConfig);
});
it('does not update config if empty VisLayer list', function () {
Expand All @@ -124,7 +125,7 @@ describe('helpers', function () {
};
const updatedConfig = enableVisLayersInSpecConfig({ config: baseConfig }, []);
// @ts-ignore
baseConfig.kibana.visibleVisLayers = new Map<VisLayerTypes, boolean>();
baseConfig.kibana.visibleVisLayers = [...new Map<VisLayerTypes, boolean>()];
expect(updatedConfig).toStrictEqual(baseConfig);
});
});
Expand Down Expand Up @@ -389,6 +390,19 @@ describe('helpers', function () {
)
).toStrictEqual(TEST_DATATABLE_SINGLE_VIS_LAYER_EMPTY);
});
// below case should not happen since only VisLayers with a populated
// set of events should be passed from the plugins. but, if it does
// happen, we can handle it more gracefully instead of throwing an error
it('vis layer with empty events adds nothing to datatable', function () {
expect(
addPointInTimeEventsLayersToTable(
TEST_DATATABLE_NO_VIS_LAYERS,
TEST_DIMENSIONS,
// @ts-ignore
TEST_VIS_LAYERS_SINGLE_EMPTY_EVENTS
)
).toStrictEqual(TEST_DATATABLE_SINGLE_VIS_LAYER_EMPTY);
});
it('vis layer with events on edge of bounds are added', function () {
expect(
addPointInTimeEventsLayersToTable(
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/vis_augmenter/public/vega/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
VisLayerTypes,
} from '../';

// Given any visLayers, create a map to indicate which VisLayer types are present.
// Convert to an array since ES6 Maps cannot be stringified.
export const enableVisLayersInSpecConfig = (spec: object, visLayers: VisLayers): {} => {
const config = get(spec, 'config', { kibana: {} });
const visibleVisLayers = new Map<VisLayerTypes, boolean>();
Expand All @@ -41,7 +43,7 @@ export const enableVisLayersInSpecConfig = (spec: object, visLayers: VisLayers):
...config,
kibana: {
...config.kibana,
visibleVisLayers,
visibleVisLayers: [...visibleVisLayers],
},
};
};
Expand Down Expand Up @@ -176,9 +178,7 @@ export const addPointInTimeEventsLayersToTable = (
},
});

if (augmentedTable.rows.length === 0) {
return false;
}
if (augmentedTable.rows.length === 0 || isEmpty(visLayer.events)) return false;

// if only one row / one datapoint, put all events into this bucket
if (augmentedTable.rows.length === 1) {
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/vis_type_vega/public/data_model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { SearchResponse, SearchParams } from 'elasticsearch';

import { Filter } from 'src/plugins/data/public';
import { DslQuery } from 'src/plugins/data/common';
import { VisLayerTypes } from 'src/plugins/vis_augmenter/public';
import { OpenSearchQueryParser } from './opensearch_query_parser';
import { EmsFileParser } from './ems_file_parser';
import { UrlParser } from './url_parser';
Expand Down Expand Up @@ -113,6 +114,7 @@ export interface OpenSearchDashboards {
hideWarnings: boolean;
type: string;
renderer: Renderer;
visibleVisLayers?: Map<VisLayerTypes, boolean>;
}

export interface VegaSpec {
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/vis_type_vega/public/data_model/vega_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ The URL is an identifier only. OpenSearch Dashboards and your browser will never
)
);
}
// Converting the visibleVisLayers array back to a map
ohltyler marked this conversation as resolved.
Show resolved Hide resolved
if (result.visibleVisLayers !== undefined && Array.isArray(result.visibleVisLayers)) {
ananzh marked this conversation as resolved.
Show resolved Hide resolved
result.visibleVisLayers = new Map<VisLayerTypes, boolean>(result.visibleVisLayers);
ohltyler marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
return result || {};
Expand Down