From 25ad2be63439e031ccb5238a8625516fa2042bcf Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Fri, 14 Jul 2023 15:59:37 -0700 Subject: [PATCH] [Vis Augmenter] Fix bug of undefined tooltip when all plugin layers are empty (#4577) (#4579) (cherry picked from commit 1249d3d0e67c96852ea177a8b556da15dd8b69b9) Signed-off-by: Tyler Ohlsen Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- .../vis_augmenter/public/test_constants.ts | 71 +++++++++++++++++++ .../vis_augmenter/public/vega/helpers.test.ts | 12 ++++ .../vis_augmenter/public/vega/helpers.ts | 1 - 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/src/plugins/vis_augmenter/public/test_constants.ts b/src/plugins/vis_augmenter/public/test_constants.ts index fdd3fa4373af..e792c100a55e 100644 --- a/src/plugins/vis_augmenter/public/test_constants.ts +++ b/src/plugins/vis_augmenter/public/test_constants.ts @@ -171,6 +171,55 @@ const TEST_VALUES_MULTIPLE_VIS_LAYERS = [ }, ]; +const TEST_VALUES_MULTIPLE_VIS_LAYERS_ONE_EMPTY = [ + { + [TEST_X_AXIS_ID]: 0, + [TEST_VALUE_AXIS_ID]: 5, + [TEST_PLUGIN_EVENT_TYPE]: 0, + [TEST_PLUGIN_EVENT_TYPE_2]: 0, + }, + { + [TEST_X_AXIS_ID]: 5, + [TEST_VALUE_AXIS_ID]: 10, + [TEST_PLUGIN_EVENT_TYPE]: 2, + [TEST_PLUGIN_EVENT_TYPE_2]: 0, + }, + { + [TEST_X_AXIS_ID]: 10, + [TEST_VALUE_AXIS_ID]: 6, + [TEST_PLUGIN_EVENT_TYPE]: 0, + [TEST_PLUGIN_EVENT_TYPE_2]: 0, + }, + { + [TEST_X_AXIS_ID]: 15, + [TEST_VALUE_AXIS_ID]: 4, + [TEST_PLUGIN_EVENT_TYPE]: 0, + [TEST_PLUGIN_EVENT_TYPE_2]: 0, + }, + { + [TEST_X_AXIS_ID]: 20, + [TEST_VALUE_AXIS_ID]: 5, + [TEST_PLUGIN_EVENT_TYPE]: 0, + [TEST_PLUGIN_EVENT_TYPE_2]: 0, + }, + { [TEST_X_AXIS_ID]: 25, [TEST_PLUGIN_EVENT_TYPE]: 0, [TEST_PLUGIN_EVENT_TYPE_2]: 0 }, + { [TEST_X_AXIS_ID]: 30, [TEST_PLUGIN_EVENT_TYPE]: 0, [TEST_PLUGIN_EVENT_TYPE_2]: 0 }, + { [TEST_X_AXIS_ID]: 35, [TEST_PLUGIN_EVENT_TYPE]: 1, [TEST_PLUGIN_EVENT_TYPE_2]: 0 }, + { [TEST_X_AXIS_ID]: 40, [TEST_PLUGIN_EVENT_TYPE]: 0, [TEST_PLUGIN_EVENT_TYPE_2]: 0 }, + { + [TEST_X_AXIS_ID]: 45, + [TEST_VALUE_AXIS_ID]: 3, + [TEST_PLUGIN_EVENT_TYPE]: 0, + [TEST_PLUGIN_EVENT_TYPE_2]: 0, + }, + { + [TEST_X_AXIS_ID]: 50, + [TEST_VALUE_AXIS_ID]: 5, + [TEST_PLUGIN_EVENT_TYPE]: 0, + [TEST_PLUGIN_EVENT_TYPE_2]: 0, + }, +]; + export const TEST_COLUMNS_NO_VIS_LAYERS = [ { id: TEST_X_AXIS_ID, @@ -269,6 +318,12 @@ export const TEST_DATATABLE_MULTIPLE_VIS_LAYERS = { rows: TEST_VALUES_MULTIPLE_VIS_LAYERS, } as OpenSearchDashboardsDatatable; +export const TEST_DATATABLE_MULTIPLE_VIS_LAYERS_ONE_EMPTY = { + type: 'opensearch_dashboards_datatable', + columns: TEST_COLUMNS_MULTIPLE_VIS_LAYERS, + rows: TEST_VALUES_MULTIPLE_VIS_LAYERS_ONE_EMPTY, +} as OpenSearchDashboardsDatatable; + const TEST_BASE_CONFIG = { view: { stroke: null }, concat: { spacing: 0 }, @@ -510,6 +565,22 @@ export const TEST_VIS_LAYERS_MULTIPLE = [ }, ]; +export const TEST_VIS_LAYERS_MULTIPLE_ONE_EMPTY = [ + ...TEST_VIS_LAYERS_SINGLE, + { + originPlugin: TEST_PLUGIN, + type: VisLayerTypes.PointInTimeEvents, + pluginResource: { + type: TEST_PLUGIN_RESOURCE_TYPE, + id: TEST_PLUGIN_RESOURCE_ID_2, + name: TEST_PLUGIN_RESOURCE_NAME_2, + urlPath: TEST_PLUGIN_RESOURCE_PATH_2, + }, + pluginEventType: TEST_PLUGIN_EVENT_TYPE_2, + events: [], + }, +]; + const TEST_RULE_LAYER_SINGLE_VIS_LAYER = { mark: { type: 'rule', color: EVENT_COLOR, opacity: 1 }, transform: [{ filter: `datum['${TEST_PLUGIN_EVENT_TYPE}'] > 0` }], diff --git a/src/plugins/vis_augmenter/public/vega/helpers.test.ts b/src/plugins/vis_augmenter/public/vega/helpers.test.ts index fbba0cb5bf7d..2e746950f71c 100644 --- a/src/plugins/vis_augmenter/public/vega/helpers.test.ts +++ b/src/plugins/vis_augmenter/public/vega/helpers.test.ts @@ -31,6 +31,7 @@ import { } from '../'; import { TEST_DATATABLE_MULTIPLE_VIS_LAYERS, + TEST_DATATABLE_MULTIPLE_VIS_LAYERS_ONE_EMPTY, TEST_DATATABLE_NO_VIS_LAYERS, TEST_DATATABLE_ONLY_VIS_LAYERS, TEST_DATATABLE_SINGLE_ROW_NO_VIS_LAYERS, @@ -48,6 +49,7 @@ import { TEST_SPEC_NO_VIS_LAYERS, TEST_SPEC_SINGLE_VIS_LAYER, TEST_VIS_LAYERS_MULTIPLE, + TEST_VIS_LAYERS_MULTIPLE_ONE_EMPTY, TEST_VIS_LAYERS_SINGLE, TEST_VIS_LAYERS_SINGLE_INVALID_BOUNDS, TEST_VIS_LAYERS_SINGLE_ON_BOUNDS, @@ -410,6 +412,16 @@ describe('helpers', function () { ) ).toStrictEqual(TEST_DATATABLE_ONLY_VIS_LAYERS); }); + it('vis layers with one having events and the other empty are added correctly', function () { + expect( + addPointInTimeEventsLayersToTable( + TEST_DATATABLE_NO_VIS_LAYERS, + + TEST_DIMENSIONS, + TEST_VIS_LAYERS_MULTIPLE_ONE_EMPTY + ) + ).toStrictEqual(TEST_DATATABLE_MULTIPLE_VIS_LAYERS_ONE_EMPTY); + }); it('vis layer with out-of-bounds timestamps are not added', function () { expect( addPointInTimeEventsLayersToTable( diff --git a/src/plugins/vis_augmenter/public/vega/helpers.ts b/src/plugins/vis_augmenter/public/vega/helpers.ts index a8d7280fe93a..de1e03d57632 100644 --- a/src/plugins/vis_augmenter/public/vega/helpers.ts +++ b/src/plugins/vis_augmenter/public/vega/helpers.ts @@ -224,7 +224,6 @@ export const addPointInTimeEventsLayersToTable = ( }); visLayers.forEach((visLayer: PointInTimeEventsVisLayer) => { - if (isEmpty(visLayer.events)) return; const visLayerColumnId = `${visLayer.pluginEventType}`; // Add placeholder values of 0 for every event value. This is so the tooltip