Skip to content

Commit

Permalink
[Feature Anywhere] Fix bug of tooltip showing 'undefined' in certain …
Browse files Browse the repository at this point in the history
…cases (#4281)

* Fix undefined tooltip bug when multiple resource types

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Dont overwrite to 0 by default

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* Fix to not hardcode only overriding index 0 in table

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

---------

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
Co-authored-by: Ashish Agrawal <ashish81394@gmail.com>
  • Loading branch information
ohltyler and lezzago authored Jun 15, 2023
1 parent 1009efe commit 83e2ff9
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 65 deletions.
133 changes: 82 additions & 51 deletions src/plugins/vis_augmenter/public/test_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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 },
Expand All @@ -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 = [
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 0 additions & 14 deletions src/plugins/vis_augmenter/public/vega/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/vis_augmenter/public/vega/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]: get(augmentedTable.rows[row], visLayerColumnId, 0) as number,
};
row++;
}

// if only one row / one datapoint, put all events into this bucket
if (augmentedTable.rows.length === 1) {
augmentedTable.rows[0] = {
Expand Down

0 comments on commit 83e2ff9

Please sign in to comment.