diff --git a/public/components/FeatureAnywhereContextMenu/AnywhereParentFlyout/AnywhereParentFlyout.tsx b/public/components/FeatureAnywhereContextMenu/AnywhereParentFlyout/AnywhereParentFlyout.tsx index d106b332..70c27e68 100644 --- a/public/components/FeatureAnywhereContextMenu/AnywhereParentFlyout/AnywhereParentFlyout.tsx +++ b/public/components/FeatureAnywhereContextMenu/AnywhereParentFlyout/AnywhereParentFlyout.tsx @@ -4,7 +4,6 @@ */ import React, { useState } from 'react'; import { get } from 'lodash'; -import AddAnomalyDetector from '../CreateAnomalyDetector'; import AssociatedDetectors from '../AssociatedDetectors/containers/AssociatedDetectors'; import { getEmbeddable } from '../../../../public/services'; @@ -18,7 +17,6 @@ const AnywhereParentFlyout = ({ startingFlyout, ...props }) => { const [selectedDetectorId, setSelectedDetectorId] = useState(); const AnywhereFlyout = { - create: AddAnomalyDetector, associated: AssociatedDetectors, }[mode]; diff --git a/public/components/FeatureAnywhereContextMenu/AssociatedDetectors/containers/AssociatedDetectors.tsx b/public/components/FeatureAnywhereContextMenu/AssociatedDetectors/containers/AssociatedDetectors.tsx index deef439c..85f7c9a5 100644 --- a/public/components/FeatureAnywhereContextMenu/AssociatedDetectors/containers/AssociatedDetectors.tsx +++ b/public/components/FeatureAnywhereContextMenu/AssociatedDetectors/containers/AssociatedDetectors.tsx @@ -162,7 +162,7 @@ function AssociatedDetectors({ embeddable, closeFlyout, core, setMode }) { // Map all detector IDs for all the found augmented vis objects const savedAugmentDetectorsSet = new Set( savedAugmentForThisVisualization.map((savedObject) => - get(savedObject, 'pluginResourceId', '') + get(savedObject, 'pluginResource.id', '') ) ); @@ -177,22 +177,20 @@ function AssociatedDetectors({ embeddable, closeFlyout, core, setMode }) { setIsLoadingFinalDetectors(true); await savedObjectLoader.findAll().then(async (resp: any) => { if (resp != undefined) { - const savedAugmentObjects: ISavedAugmentVis[] = get(resp, 'hits', []); // gets all the saved object for this visualization const savedAugmentForThisVisualization: ISavedAugmentVis[] = - savedAugmentObjects.filter( - (savedObj) => get(savedObj, 'visId', '') === embeddable.vis.id + get(resp, 'hits', [] as ISavedAugmentVis[]).filter( + (savedObj: ISavedAugmentVis[]) => get(savedObj, 'visId', '') === embeddable.vis.id ); - // find saved Augment object matching detector we want to unlink + // find saved augment object matching detector we want to unlink // There should only be one detector and vis pairing const savedAugmentToUnlink = savedAugmentForThisVisualization.find( (savedObject) => - get(savedObject, 'pluginResourceId', '') === detectorToUnlink.id + get(savedObject, 'pluginResource.id', '') === detectorToUnlink.id ); - const savedObjectToUnlinkId = get(savedAugmentToUnlink, 'id', ''); await savedObjectLoader - .delete(savedObjectToUnlinkId) + .delete(get(savedAugmentToUnlink, 'id', '')) .then(async (resp: any) => { core.notifications.toasts.addSuccess({ title: `Association removed between the ${detectorToUnlink.name} diff --git a/public/plugin.ts b/public/plugin.ts index a54bf191..a5df7ed5 100644 --- a/public/plugin.ts +++ b/public/plugin.ts @@ -10,76 +10,88 @@ */ import { - AppMountParameters, - CoreSetup, - CoreStart, - Plugin, - } from '../../../src/core/public'; - import { CONTEXT_MENU_TRIGGER, EmbeddableSetup, EmbeddableStart } from '../../../src/plugins/embeddable/public'; - 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, setOverlays } from './services'; - import { AnomalyDetectionOpenSearchDashboardsPluginStart } from 'public'; - - declare module '../../../src/plugins/ui_actions/public' { - export interface ActionContextMapping { - [ACTION_AD]: {}; - } + AppMountParameters, + CoreSetup, + CoreStart, + Plugin, +} from '../../../src/core/public'; +import { + CONTEXT_MENU_TRIGGER, + EmbeddableSetup, + EmbeddableStart, +} from '../../../src/plugins/embeddable/public'; +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, + setOverlays, + setSavedFeatureAnywhereLoader, +} from './services'; +import { AnomalyDetectionOpenSearchDashboardsPluginStart } from 'public'; +import { VisAugmenterStart } from '../../../src/plugins/vis_augmenter/public'; + +declare module '../../../src/plugins/ui_actions/public' { + export interface ActionContextMapping { + [ACTION_AD]: {}; } - - export interface AnomalyDetectionSetupDeps { - embeddable: EmbeddableSetup; +} + +export interface AnomalyDetectionSetupDeps { + embeddable: EmbeddableSetup; +} + +export interface AnomalyDetectionStartDeps { + embeddable: EmbeddableStart; + visAugmenter: VisAugmenterStart; +} + +export class AnomalyDetectionOpenSearchDashboardsPlugin + implements Plugin +{ + public setup(core: CoreSetup, plugins: any) { + core.application.register({ + id: PLUGIN_NAME, + title: 'Anomaly Detection', + category: { + id: 'opensearch', + label: 'OpenSearch Plugins', + order: 2000, + }, + order: 5000, + mount: async (params: AppMountParameters) => { + const { renderApp } = await import('./anomaly_detection_app'); + const [coreStart] = await core.getStartServices(); + return renderApp(coreStart, params); + }, + }); + + // Set the HTTP client so it can be pulled into expression fns to make + // direct server-side calls + setClient(core.http); + + // Create context menu actions. Pass core, to access service for flyouts. + const actions = getActions(); + + // Add actions to uiActions + actions.forEach((action) => { + plugins.uiActions.addTriggerAction(CONTEXT_MENU_TRIGGER, action); + }); + + // registers the expression function used to render anomalies on an Augmented Visualization + plugins.expressions.registerFunction(overlayAnomaliesFunction); + return {}; } - - export interface AnomalyDetectionStartDeps { - embeddable: EmbeddableStart; + + public start( + core: CoreStart, + { embeddable, visAugmenter }: AnomalyDetectionStartDeps + ): AnomalyDetectionOpenSearchDashboardsPluginStart { + setEmbeddable(embeddable); + setOverlays(core.overlays); + setSavedFeatureAnywhereLoader(visAugmenter.savedAugmentVisLoader); + return {}; } - - export class AnomalyDetectionOpenSearchDashboardsPlugin implements - Plugin { - - public setup(core: CoreSetup, plugins: any) { - core.application.register({ - id: PLUGIN_NAME, - title: 'Anomaly Detection', - category: { - id: 'opensearch', - label: 'OpenSearch Plugins', - order: 2000, - }, - order: 5000, - mount: async (params: AppMountParameters) => { - const { renderApp } = await import('./anomaly_detection_app'); - const [coreStart] = await core.getStartServices(); - return renderApp(coreStart, params); - }, - }); - - // Set the HTTP client so it can be pulled into expression fns to make - // direct server-side calls - setClient(core.http); - - // Create context menu actions. Pass core, to access service for flyouts. - const actions = getActions(); - - // Add actions to uiActions - actions.forEach((action) => { - plugins.uiActions.addTriggerAction(CONTEXT_MENU_TRIGGER, action); - }); - - // registers the expression function used to render anomalies on an Augmented Visualization - plugins.expressions.registerFunction(overlayAnomaliesFunction); - return {}; - } - - public start( - core: CoreStart, - {embeddable }: AnomalyDetectionStartDeps - ): AnomalyDetectionOpenSearchDashboardsPluginStart { - setEmbeddable(embeddable); - setOverlays(core.overlays); - return {}; - } - } \ No newline at end of file +}