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

[Backport 2.9] [Vis Augmenter] Fix bug of undefined tooltip when all plugin layers are empty #4579

Merged
merged 1 commit into from
Jul 14, 2023
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
71 changes: 71 additions & 0 deletions src/plugins/vis_augmenter/public/test_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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` }],
Expand Down
12 changes: 12 additions & 0 deletions src/plugins/vis_augmenter/public/vega/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion src/plugins/vis_augmenter/public/vega/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down