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 bug of tooltip showing 'undefined' in certain cases #4281

Merged
Show file tree
Hide file tree
Changes from all 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
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 () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing this test? Is it because it would not be empty and have placeholder 0 values? If so, we should modify the test for that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is invalid now, since it was testing that nothing would be added to the datatable. But now we add 0s. The rest of the tests handle such scenarios

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally the test was hacky to begin with. The scenario should never happen and other tests to ensure the logic should never reach this state are already tested.

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