From b5e8151967a521b4e4bfb808eda20a2348d910bc Mon Sep 17 00:00:00 2001 From: Tyler Ohlsen Date: Tue, 13 Jun 2023 11:01:39 -0700 Subject: [PATCH 1/3] Fix undefined tooltip bug when multiple resource types Signed-off-by: Tyler Ohlsen --- .../vis_augmenter/public/test_constants.ts | 133 +++++++++++------- .../vis_augmenter/public/vega/helpers.test.ts | 14 -- .../vis_augmenter/public/vega/helpers.ts | 11 ++ 3 files changed, 93 insertions(+), 65 deletions(-) diff --git a/src/plugins/vis_augmenter/public/test_constants.ts b/src/plugins/vis_augmenter/public/test_constants.ts index c616897d095f..c063850755c3 100644 --- a/src/plugins/vis_augmenter/public/test_constants.ts +++ b/src/plugins/vis_augmenter/public/test_constants.ts @@ -39,17 +39,17 @@ const TEST_VALUES_SINGLE_ROW_SINGLE_VIS_LAYER = [ ]; const TEST_VALUES_ONLY_VIS_LAYERS = [ - { [TEST_X_AXIS_ID]: 0 }, + { [TEST_X_AXIS_ID]: 0, [TEST_PLUGIN_EVENT_TYPE]: 0 }, { [TEST_X_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE]: 2 }, - { [TEST_X_AXIS_ID]: 10 }, - { [TEST_X_AXIS_ID]: 15 }, - { [TEST_X_AXIS_ID]: 20 }, - { [TEST_X_AXIS_ID]: 25 }, - { [TEST_X_AXIS_ID]: 30 }, + { [TEST_X_AXIS_ID]: 10, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 15, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 20, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 25, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 30, [TEST_PLUGIN_EVENT_TYPE]: 0 }, { [TEST_X_AXIS_ID]: 35, [TEST_PLUGIN_EVENT_TYPE]: 1 }, - { [TEST_X_AXIS_ID]: 40 }, - { [TEST_X_AXIS_ID]: 45 }, - { [TEST_X_AXIS_ID]: 50 }, + { [TEST_X_AXIS_ID]: 40, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 45, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 50, [TEST_PLUGIN_EVENT_TYPE]: 0 }, ]; const TEST_VALUES_NO_VIS_LAYERS = [ @@ -66,6 +66,20 @@ const TEST_VALUES_NO_VIS_LAYERS = [ { [TEST_X_AXIS_ID]: 50, [TEST_VALUE_AXIS_ID]: 5 }, ]; +const TEST_VALUES_SINGLE_VIS_LAYER_EMPTY = [ + { [TEST_X_AXIS_ID]: 0, [TEST_VALUE_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 5, [TEST_VALUE_AXIS_ID]: 10, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 10, [TEST_VALUE_AXIS_ID]: 6, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 15, [TEST_VALUE_AXIS_ID]: 4, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 20, [TEST_VALUE_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 25, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 30, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 35, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 40, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 45, [TEST_VALUE_AXIS_ID]: 3, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 50, [TEST_VALUE_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE]: 0 }, +]; + 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 }, @@ -81,50 +95,80 @@ const TEST_VALUES_NO_VIS_LAYERS_DIRTY = [ ]; const TEST_VALUES_SINGLE_VIS_LAYER = [ - { [TEST_X_AXIS_ID]: 0, [TEST_VALUE_AXIS_ID]: 5 }, + { [TEST_X_AXIS_ID]: 0, [TEST_VALUE_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE]: 0 }, { [TEST_X_AXIS_ID]: 5, [TEST_VALUE_AXIS_ID]: 10, [TEST_PLUGIN_EVENT_TYPE]: 2 }, - { [TEST_X_AXIS_ID]: 10, [TEST_VALUE_AXIS_ID]: 6 }, - { [TEST_X_AXIS_ID]: 15, [TEST_VALUE_AXIS_ID]: 4 }, - { [TEST_X_AXIS_ID]: 20, [TEST_VALUE_AXIS_ID]: 5 }, - { [TEST_X_AXIS_ID]: 25 }, - { [TEST_X_AXIS_ID]: 30 }, + { [TEST_X_AXIS_ID]: 10, [TEST_VALUE_AXIS_ID]: 6, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 15, [TEST_VALUE_AXIS_ID]: 4, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 20, [TEST_VALUE_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 25, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 30, [TEST_PLUGIN_EVENT_TYPE]: 0 }, { [TEST_X_AXIS_ID]: 35, [TEST_PLUGIN_EVENT_TYPE]: 1 }, - { [TEST_X_AXIS_ID]: 40 }, - { [TEST_X_AXIS_ID]: 45, [TEST_VALUE_AXIS_ID]: 3 }, - { [TEST_X_AXIS_ID]: 50, [TEST_VALUE_AXIS_ID]: 5 }, + { [TEST_X_AXIS_ID]: 40, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 45, [TEST_VALUE_AXIS_ID]: 3, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 50, [TEST_VALUE_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE]: 0 }, ]; const TEST_VALUES_SINGLE_VIS_LAYER_ON_BOUNDS = [ { [TEST_X_AXIS_ID]: 0, [TEST_VALUE_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE]: 2 }, - { [TEST_X_AXIS_ID]: 5, [TEST_VALUE_AXIS_ID]: 10 }, - { [TEST_X_AXIS_ID]: 10, [TEST_VALUE_AXIS_ID]: 6 }, - { [TEST_X_AXIS_ID]: 15, [TEST_VALUE_AXIS_ID]: 4 }, - { [TEST_X_AXIS_ID]: 20, [TEST_VALUE_AXIS_ID]: 5 }, - { [TEST_X_AXIS_ID]: 25 }, - { [TEST_X_AXIS_ID]: 30 }, - { [TEST_X_AXIS_ID]: 35 }, - { [TEST_X_AXIS_ID]: 40 }, - { [TEST_X_AXIS_ID]: 45, [TEST_VALUE_AXIS_ID]: 3 }, + { [TEST_X_AXIS_ID]: 5, [TEST_VALUE_AXIS_ID]: 10, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 10, [TEST_VALUE_AXIS_ID]: 6, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 15, [TEST_VALUE_AXIS_ID]: 4, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 20, [TEST_VALUE_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 25, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 30, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 35, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 40, [TEST_PLUGIN_EVENT_TYPE]: 0 }, + { [TEST_X_AXIS_ID]: 45, [TEST_VALUE_AXIS_ID]: 3, [TEST_PLUGIN_EVENT_TYPE]: 0 }, { [TEST_X_AXIS_ID]: 50, [TEST_VALUE_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE]: 1 }, ]; const TEST_VALUES_MULTIPLE_VIS_LAYERS = [ - { [TEST_X_AXIS_ID]: 0, [TEST_VALUE_AXIS_ID]: 5 }, + { + [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]: 1, }, - { [TEST_X_AXIS_ID]: 10, [TEST_VALUE_AXIS_ID]: 6 }, - { [TEST_X_AXIS_ID]: 15, [TEST_VALUE_AXIS_ID]: 4, [TEST_PLUGIN_EVENT_TYPE_2]: 1 }, - { [TEST_X_AXIS_ID]: 20, [TEST_VALUE_AXIS_ID]: 5 }, - { [TEST_X_AXIS_ID]: 25 }, - { [TEST_X_AXIS_ID]: 30 }, - { [TEST_X_AXIS_ID]: 35, [TEST_PLUGIN_EVENT_TYPE]: 1 }, - { [TEST_X_AXIS_ID]: 40 }, - { [TEST_X_AXIS_ID]: 45, [TEST_VALUE_AXIS_ID]: 3 }, - { [TEST_X_AXIS_ID]: 50, [TEST_VALUE_AXIS_ID]: 5, [TEST_PLUGIN_EVENT_TYPE_2]: 2 }, + { + [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]: 1, + }, + { + [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]: 2, + }, ]; export const TEST_COLUMNS_NO_VIS_LAYERS = [ @@ -204,6 +248,7 @@ export const TEST_DATATABLE_NO_VIS_LAYERS_DIRTY = { export const TEST_DATATABLE_SINGLE_VIS_LAYER_EMPTY = { ...TEST_DATATABLE_NO_VIS_LAYERS, columns: TEST_COLUMNS_SINGLE_VIS_LAYER, + rows: TEST_VALUES_SINGLE_VIS_LAYER_EMPTY, } as OpenSearchDashboardsDatatable; export const TEST_DATATABLE_SINGLE_VIS_LAYER = { @@ -390,20 +435,6 @@ 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, - }, - pluginEventType: TEST_PLUGIN_EVENT_TYPE, - }, -]; - export const TEST_VIS_LAYERS_SINGLE_ON_BOUNDS = [ { originPlugin: TEST_PLUGIN, diff --git a/src/plugins/vis_augmenter/public/vega/helpers.test.ts b/src/plugins/vis_augmenter/public/vega/helpers.test.ts index f0df25a81546..ce5c68075afe 100644 --- a/src/plugins/vis_augmenter/public/vega/helpers.test.ts +++ b/src/plugins/vis_augmenter/public/vega/helpers.test.ts @@ -38,7 +38,6 @@ 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'; @@ -409,19 +408,6 @@ 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( diff --git a/src/plugins/vis_augmenter/public/vega/helpers.ts b/src/plugins/vis_augmenter/public/vega/helpers.ts index fa2073e3bb63..5783bc36375f 100644 --- a/src/plugins/vis_augmenter/public/vega/helpers.ts +++ b/src/plugins/vis_augmenter/public/vega/helpers.ts @@ -228,6 +228,17 @@ export const addPointInTimeEventsLayersToTable = ( if (isEmpty(visLayer.events)) return; const visLayerColumnId = `${visLayer.pluginEventType}`; + // Add placeholder values of 0 for every event value. This is so the tooltip + // can render correctly without showing the 'undefined' string + let row = 0; + while (row < augmentedTable.rows.length) { + augmentedTable.rows[row] = { + ...augmentedTable.rows[row], + [visLayerColumnId]: 0, + }; + row++; + } + // if only one row / one datapoint, put all events into this bucket if (augmentedTable.rows.length === 1) { augmentedTable.rows[0] = { From 344b4bae055893ee985a81bb6caf8aeb17cfd3ef Mon Sep 17 00:00:00 2001 From: Tyler Ohlsen Date: Tue, 13 Jun 2023 11:10:08 -0700 Subject: [PATCH 2/3] Dont overwrite to 0 by default Signed-off-by: Tyler Ohlsen --- src/plugins/vis_augmenter/public/vega/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/vis_augmenter/public/vega/helpers.ts b/src/plugins/vis_augmenter/public/vega/helpers.ts index 5783bc36375f..ec30e25c14aa 100644 --- a/src/plugins/vis_augmenter/public/vega/helpers.ts +++ b/src/plugins/vis_augmenter/public/vega/helpers.ts @@ -234,7 +234,7 @@ export const addPointInTimeEventsLayersToTable = ( while (row < augmentedTable.rows.length) { augmentedTable.rows[row] = { ...augmentedTable.rows[row], - [visLayerColumnId]: 0, + [visLayerColumnId]: get(augmentedTable.rows[0], visLayerColumnId, 0) as number, }; row++; } From 796edb604f4a09200cfcf30c4b2e611cb9fd262a Mon Sep 17 00:00:00 2001 From: Tyler Ohlsen Date: Thu, 15 Jun 2023 08:36:19 -0700 Subject: [PATCH 3/3] Fix to not hardcode only overriding index 0 in table Signed-off-by: Tyler Ohlsen --- src/plugins/vis_augmenter/public/vega/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/vis_augmenter/public/vega/helpers.ts b/src/plugins/vis_augmenter/public/vega/helpers.ts index ec30e25c14aa..846a40adf33e 100644 --- a/src/plugins/vis_augmenter/public/vega/helpers.ts +++ b/src/plugins/vis_augmenter/public/vega/helpers.ts @@ -234,7 +234,7 @@ export const addPointInTimeEventsLayersToTable = ( while (row < augmentedTable.rows.length) { augmentedTable.rows[row] = { ...augmentedTable.rows[row], - [visLayerColumnId]: get(augmentedTable.rows[0], visLayerColumnId, 0) as number, + [visLayerColumnId]: get(augmentedTable.rows[row], visLayerColumnId, 0) as number, }; row++; }