Skip to content

Commit

Permalink
Integrate with Vis Augmenter to augment Dashboard visualizations (#596)
Browse files Browse the repository at this point in the history
Signed-off-by: Ashish Agrawal <[email protected]>
Co-authored-by: David Sinclair <[email protected]>
  • Loading branch information
lezzago and sikhote authored Jul 10, 2023
1 parent 353aa25 commit 12c65ec
Show file tree
Hide file tree
Showing 121 changed files with 5,639 additions and 901 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cypress-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: E2E Cypress tests
on:
pull_request:
branches:
- "*"
- "**"
push:
branches:
- "*"
- "**"
env:
OPENSEARCH_DASHBOARDS_VERSION: 'main'
OPENSEARCH_VERSION: '3.0.0-SNAPSHOT'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit-tests-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: Unit tests workflow
on:
push:
branches:
- "*"
- "**"
pull_request:
branches:
- "*"
- "**"
env:
OPENSEARCH_DASHBOARDS_VERSION: 'main'
jobs:
Expand Down
3 changes: 2 additions & 1 deletion cypress/integration/query_level_monitor_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const addVisualQueryLevelTrigger = (
thresholdValue
) => {
// Click 'Add trigger' button
cy.contains('Add trigger', { timeout: 20000 }).click({ force: true });
if (triggerIndex === 0) cy.contains('Add trigger', { timeout: 20000 }).click({ force: true });
else cy.contains('Add another trigger', { timeout: 20000 }).click({ force: true });

if (isEdit) {
// TODO: Passing button props in EUI accordion was added in newer versions (31.7.0+).
Expand Down
12 changes: 11 additions & 1 deletion opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
"version": "3.0.0.0",
"opensearchDashboardsVersion": "3.0.0",
"configPath": ["opensearch_alerting"],
"requiredPlugins": [],
"requiredPlugins": [
"uiActions",
"dashboard",
"embeddable",
"opensearchDashboardsReact",
"savedObjects",
"expressions",
"data",
"visAugmenter",
"opensearchDashboardsUtils"
],
"server": true,
"ui": true
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
}
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.16.5",
"@elastic/elastic-eslint-config-kibana": "link:../../packages/opensearch-eslint-config-opensearch-dashboards",
"@elastic/eslint-import-resolver-kibana": "link:../../packages/osd-eslint-import-resolver-opensearch-dashboards",
"cypress": "^6.0.0",
Expand Down
70 changes: 70 additions & 0 deletions public/actions/alerting_dashboard_action.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { EuiIconType } from '@elastic/eui/src/components/icon/icon';
import { IEmbeddable } from '../../../../src/plugins/dashboard/public/embeddable_plugin';
import {
DASHBOARD_CONTAINER_TYPE,
DashboardContainer,
} from '../../../../src/plugins/dashboard/public';
import { IncompatibleActionError, createAction } from '../../../../src/plugins/ui_actions/public';
import { isReferenceOrValueEmbeddable } from '../../../../src/plugins/embeddable/public';
import { Action } from '../../../../src/plugins/ui_actions/public';
import { isEligibleForVisLayers } from '../../../../src/plugins/vis_augmenter/public';
import { getUISettings } from '../services';

export const ACTION_ALERTING = 'alerting';

function isDashboard(embeddable: IEmbeddable): embeddable is DashboardContainer {
return embeddable.type === DASHBOARD_CONTAINER_TYPE;
}

export interface ActionContext {
embeddable: IEmbeddable;
}

export interface CreateOptions {
grouping: Action['grouping'];
title: JSX.Element | string;
icon: EuiIconType;
id: string;
type: Action['type'];
order: number;
onExecute: Function;
}

export const createAlertingAction = ({
grouping,
title,
icon,
id,
order,
onExecute,
type,
}: CreateOptions) =>
createAction({
id,
order,
getDisplayName: ({ embeddable }: ActionContext) => {
if (!embeddable.parent || !isDashboard(embeddable.parent)) {
throw new IncompatibleActionError();
}
return title;
},
getIconType: () => icon,
type,
grouping,
// Do not show actions for certin visualizations
isCompatible: async ({ embeddable }: ActionContext) => {
return Boolean(
embeddable.parent &&
embeddable.getInput()?.viewMode === 'view' &&
isDashboard(embeddable.parent) &&
isEligibleForVisLayers(embeddable.vis, getUISettings())
);
},
execute: async (context: ActionContext) => {
if (!isReferenceOrValueEmbeddable(context.embeddable)) {
throw new IncompatibleActionError();
}

onExecute(context);
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { httpServiceMock, notificationServiceMock } from '../../../../../../src/core/public/mocks';
import { shallow } from 'enzyme';
import AddAlertingMonitor from './AddAlertingMonitor';
import { setClient, setNotifications } from '../../../services';

describe('AddAlertingMonitor', () => {
const httpClient = httpServiceMock.createStartContract();
setClient(httpClient);
const notifications = notificationServiceMock.createStartContract();
setNotifications(notifications);
test('renders', () => {
const wrapper = shallow(<AddAlertingMonitor {...{ embeddable: { vis: { title: '' } } }} />);
expect(wrapper).toMatchSnapshot();
});
});
Loading

0 comments on commit 12c65ec

Please sign in to comment.