Skip to content

Commit

Permalink
fix notification and clean up associated detectors
Browse files Browse the repository at this point in the history
Signed-off-by: Amit Galitzky <[email protected]>
  • Loading branch information
amitgalitz committed May 8, 2023
1 parent 8a2fadb commit e1d9ac4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import {
import { get, isEmpty } from 'lodash';
import '../styles.scss';
import { getColumns } from '../utils/helpers';
import { CoreServicesContext } from '../../../../components/CoreServices/CoreServices';
import { CoreStart } from '../../../../../../../src/core/public';
import { useDispatch, useSelector } from 'react-redux';
import { AppState } from '../../../../redux/reducers';
import { DetectorListItem } from '../../../../models/interfaces';
Expand All @@ -35,11 +33,7 @@ import {
} from '../../../../../server/utils/helpers';
import { SavedObjectLoader } from '../../../../../../../src/plugins/saved_objects/public';
import { EmptyAssociatedDetectorFlyoutMessage } from '../components/EmptyMessage/EmptyMessage';
import {
ISavedAugmentVis,
VisLayerExpressionFn,
createAugmentVisSavedObject,
} from '../../../../../../../src/plugins/vis_augmenter/public';
import { ISavedAugmentVis } from '../../../../../../../src/plugins/vis_augmenter/public';
import { ASSOCIATED_DETECTOR_ACTION } from '../utils/constants';
import { ConfirmUnlinkDetectorModal } from '../components/ConfirmUnlinkDetectorModal/ConfirmUnlinkDetectorModal';

Expand All @@ -51,8 +45,7 @@ interface ConfirmModalState {
affectedDetector: DetectorListItem;
}

function AssociatedDetectors({ embeddable, closeFlyout, setMode }) {
const core = React.useContext(CoreServicesContext) as CoreStart;
function AssociatedDetectors({ embeddable, closeFlyout, core, setMode }) {
const dispatch = useDispatch();
const allDetectors = useSelector((state: AppState) => state.ad.detectorList);
const isRequestingFromES = useSelector(
Expand Down Expand Up @@ -199,15 +192,11 @@ function AssociatedDetectors({ embeddable, closeFlyout, setMode }) {
await savedObjectLoader
.delete(savedObjectToUnlinkId)
.then(async (resp: any) => {
console.log('inside delete after unlinking');
core.notifications.toasts.addSuccess(
`Detector created: ${values.name}`
);
// core.notifications.toasts.addSuccess({
// title: `Association removed between the ${detectorToUnlink.name}
// and the ${embeddableTitle} visualization`,
// text: 'The detector\'s anomalies do not appear on the visualization. Refresh your dashboard to update the visualization',
// })
core.notifications.toasts.addSuccess({
title: `Association removed between the ${detectorToUnlink.name}
and the ${embeddableTitle} visualization`,
text: "The detector's anomalies do not appear on the visualization. Refresh your dashboard to update the visualization",
});
})
.catch((error) => {
core.notifications.toasts.addDanger(
Expand Down Expand Up @@ -260,45 +249,6 @@ function AssociatedDetectors({ embeddable, closeFlyout, setMode }) {
console.log('inside create anomaly detector');
};

// This method is only here for development/testing purposes.
const createSavedObjects = async () => {
enum VisLayerTypes {
PointInTimeEvents = 'PointInTimeEvents',
}
console.log('all Detectors: ' + JSON.stringify(allDetectors));

const fn = {
type: VisLayerTypes.PointInTimeEvents,
name: 'overlay_anomalies',
args: {
detectorId: 'pggP7ocBbTXmavYrSMaD',
},
} as VisLayerExpressionFn;

// const fn = {
// type: VisLayerTypes.PointInTimeEvents,
// name: 'test-fn',
// args: {
// testArg: 'bNZIp4UB3stq6UHwpWwS',
// },
// } as VisLayerExpressionFn;

const savedObjectToCreate = {
title: 'test-title',
pluginResourceId: 'pggP7ocBbTXmavYrSMaD',
visId: embeddable.vis.id,
visLayerExpressionFn: fn,
} as ISavedAugmentVis;

const savedObject = await createAugmentVisSavedObject(savedObjectToCreate);
console.log('savedObject: ' + JSON.stringify(savedObject));

const response = await savedObject.save({});
console.log('response: ' + JSON.stringify(response));
core.notifications.toasts.addSuccess(`Detector created: ${values.name}`);
getDetectors();
};

const handleUnlinkDetectorAction = (detector: DetectorListItem) => {
setDetectorToUnlink(detector);
if (!isEmpty(detector)) {
Expand Down Expand Up @@ -388,15 +338,6 @@ function AssociatedDetectors({ embeddable, closeFlyout, setMode }) {
</EuiFlexGroup>
<EuiSpacer size="m" />
<EuiInMemoryTable {...tableProps} />
<EuiFlexItem grow={false}>
<EuiButton
onClick={() => {
createSavedObjects();
}}
>
Create saved objects{' '}
</EuiButton>
</EuiFlexItem>
</EuiFlyoutBody>
</EuiFlyout>
</div>
Expand Down
15 changes: 2 additions & 13 deletions public/utils/contextMenu/getActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { toMountPoint } from '../../../../../src/plugins/opensearch_dashboards_r
import { Action } from '../../../../../src/plugins/ui_actions/public';
import { createADAction } from '../../action/ad_dashboard_action';
import Container from '../../components/FeatureAnywhereContextMenu/Container';
//import DocumentationTitle from '../../components/FeatureAnywhereContextMenu/DocumentationTitle';
import { Provider } from 'react-redux';
import { CoreServicesContext } from '../../../public/components/CoreServices/CoreServices';
import configureStore from '../../redux/configureStore';
Expand Down Expand Up @@ -75,17 +74,7 @@ export const getActions = ({ core, plugins }) => {
order: 99,
onClick: getOnClick('associated'),
},
// {
// id: 'documentationAnomalyDetector',
// title: <DocumentationTitle />,
// icon: 'documentation' as EuiIconType,
// order: 98,
// onExecute: () => {
// window.open(
// 'https://opensearch.org/docs/latest/monitoring-plugins/anomaly-detection/index/',
// '_blank'
// );
// },
// },
//TODO: Jackie's PR has additional documentation link here but this anyway might have changes once
// this PR is merged in OSD: https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3924
].map((options) => createADAction({ ...options, grouping }));
};

0 comments on commit e1d9ac4

Please sign in to comment.