Skip to content

Commit

Permalink
addressed more comments
Browse files Browse the repository at this point in the history
Signed-off-by: Amit Galitzky <[email protected]>
  • Loading branch information
amitgalitz committed May 22, 2023
1 parent 3d9a4eb commit e62cea8
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -18,7 +17,6 @@ const AnywhereParentFlyout = ({ startingFlyout, ...props }) => {
const [selectedDetectorId, setSelectedDetectorId] = useState();

const AnywhereFlyout = {
create: AddAnomalyDetector,
associated: AssociatedDetectors,
}[mode];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')
)
);

Expand All @@ -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}
Expand Down
152 changes: 82 additions & 70 deletions public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AnomalyDetectionSetupDeps, AnomalyDetectionStartDeps>
{
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<AnomalyDetectionSetupDeps, AnomalyDetectionStartDeps> {

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 {};
}
}
}

0 comments on commit e62cea8

Please sign in to comment.