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

Register AD as dashboard context menu option #482

Merged
merged 7 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import { ACTION_AD } from './action/ad_dashboard_action';
import { PLUGIN_NAME } from './utils/constants';
import { getActions } from './utils/contextMenu/getActions';
import { overlayAnomaliesFunction } from './expressions/overlay_anomalies';
import { setClient, setEmbeddable } from './services';
import { setClient, setEmbeddable, setOverlays } from './services';
import { AnomalyDetectionOpenSearchDashboardsPluginStart } from 'public';
import { createStartServicesGetter } from '../../../src/plugins/opensearch_dashboards_utils/public';

declare module '../../../src/plugins/ui_actions/public' {
export interface ActionContextMapping {
Expand All @@ -39,6 +40,7 @@ export interface AnomalyDetectionStartDeps {

export class AnomalyDetectionOpenSearchDashboardsPlugin implements
Plugin<AnomalyDetectionSetupDeps, AnomalyDetectionStartDeps> {

public setup(core: CoreSetup, plugins: any) {
core.application.register({
id: PLUGIN_NAME,
Expand All @@ -61,7 +63,7 @@ export class AnomalyDetectionOpenSearchDashboardsPlugin implements
setClient(core.http);

// Create context menu actions. Pass core, to access service for flyouts.
Copy link
Member

Choose a reason for hiding this comment

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

nit: can update this comment

const actions = getActions({ core });
const actions = getActions();

// Add actions to uiActions
actions.forEach((action) => {
Expand All @@ -78,6 +80,7 @@ export class AnomalyDetectionOpenSearchDashboardsPlugin implements
{embeddable }: AnomalyDetectionStartDeps
): AnomalyDetectionOpenSearchDashboardsPluginStart {
setEmbeddable(embeddable);
setOverlays(core.overlays);
return {};
}
}
5 changes: 4 additions & 1 deletion public/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { CoreStart } from '../../../src/core/public';
import { CoreStart, OverlayStart } from '../../../src/core/public';
import { EmbeddableStart } from '../../../src/plugins/embeddable/public';
import { createGetterSetter } from '../../../src/plugins/opensearch_dashboards_utils/public';
import { SavedObjectLoader } from '../../../src/plugins/saved_objects/public';
Expand All @@ -16,3 +16,6 @@ export const [getClient, setClient] =

export const [getEmbeddable, setEmbeddable] =
createGetterSetter<EmbeddableStart>('Embeddable');

export const [getOverlays, setOverlays] =
createGetterSetter<OverlayStart>('Overlays');
21 changes: 6 additions & 15 deletions public/utils/contextMenu/getActions.tsx
ohltyler marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { Action } from '../../../../../src/plugins/ui_actions/public';
import { createADAction } from '../../action/ad_dashboard_action';
import AnywhereParentFlyout from '../../components/FeatureAnywhereContextMenu/AnywhereParentFlyout';
jackiehanyang marked this conversation as resolved.
Show resolved Hide resolved
import { Provider } from 'react-redux';
import { CoreServicesContext } from '../../../public/components/CoreServices/CoreServices';
import configureStore from '../../redux/configureStore';
import DocumentationTitle from '../../components/FeatureAnywhereContextMenu/DocumentationTitle/containers/DocumentationTitle';
import { AD_DOCS_LINK, APM_TRACE } from '../constants';
import { getClient, getOverlays } from '../../../public/services';

// This is used to create all actions in the same context menu
const grouping: Action['grouping'] = [
Expand All @@ -20,30 +20,21 @@ const grouping: Action['grouping'] = [
},
];


interface GetActionsProps {
core: CoreSetup;
}

export const getActions = ({ core }: GetActionsProps) => {
export const getActions = () => {
const getOnClick =
(startingFlyout) =>
async ({ embeddable }) => {
const services = await core.getStartServices();
const openFlyout = services[0].overlays.openFlyout;
const http = services[0].http;
const store = configureStore(http);
const overlayService = getOverlays();
const openFlyout = overlayService.openFlyout;
const store = configureStore(getClient());
const overlay = openFlyout(
toMountPoint(
<Provider store={store}>
<CoreServicesContext.Provider value={services}>
<AnywhereParentFlyout
<AnywhereParentFlyout
startingFlyout={startingFlyout}
embeddable={embeddable}
closeFlyout={() => overlay.close()}
services={services}
/>
</CoreServicesContext.Provider>
</Provider>
),
{ size: 'm', className: 'context-menu__flyout' }
Expand Down