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

render embeddable by using vis embeddable #521

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
import './styles.scss';
import {
createAugmentVisSavedObject,
fetchVisEmbeddable,
ISavedAugmentVis,
ISavedPluginResource,
SavedAugmentVisLoader,
Expand All @@ -50,7 +51,7 @@ import {
matchDetector,
startDetector,
} from '../../../../public/redux/reducers/ad';
import { EmbeddableRenderer } from '../../../../../../src/plugins/embeddable/public';
import { EmbeddableRenderer, ErrorEmbeddable } from '../../../../../../src/plugins/embeddable/public';
import './styles.scss';
import EnhancedAccordion from '../EnhancedAccordion';
import MinimalAccordion from '../MinimalAccordion';
Expand Down Expand Up @@ -86,10 +87,12 @@ import {
MAX_FEATURE_NUM,
} from '../../../../public/utils/constants';
import {
getEmbeddable,
getNotifications,
getSavedFeatureAnywhereLoader,
getUISettings,
getUiActions,
getQueryService
} from '../../../../public/services';
import { prettifyErrorMessage } from '../../../../server/utils/helpers';
import {
Expand All @@ -104,6 +107,7 @@ import { AssociateExisting } from './AssociateExisting';
import { mountReactNode } from '../../../../../../src/core/public/utils';
import { FLYOUT_MODES } from '../AnywhereParentFlyout/constants';
import { DetectorListItem } from '../../../../public/models/interfaces';
import { VisualizeEmbeddable } from '../../../../../../src/plugins/visualizations/public';

function AddAnomalyDetector({
embeddable,
Expand All @@ -115,14 +119,24 @@ function AddAnomalyDetector({
}) {
const dispatch = useDispatch();
const [queryText, setQueryText] = useState('');
const [generatedEmbeddable, setGeneratedEmbeddable] = useState<
VisualizeEmbeddable | ErrorEmbeddable
>();

useEffect(() => {
const getInitialIndices = async () => {
await dispatch(getIndices(queryText));
};
getInitialIndices();
dispatch(getMappings(embeddable.vis.data.aggs.indexPattern.title));
}, []);

const createEmbeddable = async () => {
const visEmbeddable = await fetchVisEmbeddable(embeddable.vis.id, getEmbeddable(), getQueryService());
setGeneratedEmbeddable(visEmbeddable);
};

createEmbeddable();
}, []);
const [isShowVis, setIsShowVis] = useState(false);
const [accordionsOpen, setAccordionsOpen] = useState({ modelFeatures: true });
const [detectorNameFromVis, setDetectorNameFromVis] = useState(
Expand Down Expand Up @@ -557,7 +571,7 @@ function AddAnomalyDetector({
}`}
>
<EuiSpacer size="s" />
<EmbeddableRenderer embeddable={embeddable} />
<EmbeddableRenderer embeddable={generatedEmbeddable} />
</div>
<EuiSpacer size="l" />
<EuiTitle size="s">
Expand Down
6 changes: 5 additions & 1 deletion public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ import {
setSavedFeatureAnywhereLoader,
setUiActions,
setUISettings,
setQueryService
} from './services';
import { AnomalyDetectionOpenSearchDashboardsPluginStart } from 'public';
import {
VisAugmenterSetup,
VisAugmenterStart,
} from '../../../src/plugins/vis_augmenter/public';
import { UiActionsStart } from '../../../src/plugins/ui_actions/public';
import { DataPublicPluginStart } from '../../../src/plugins/data/public';

declare module '../../../src/plugins/ui_actions/public' {
export interface ActionContextMapping {
Expand All @@ -61,6 +63,7 @@ export interface AnomalyDetectionStartDeps {
notifications: NotificationsStart;
visAugmenter: VisAugmenterStart;
uiActions: UiActionsStart;
data: DataPublicPluginStart;
}

export class AnomalyDetectionOpenSearchDashboardsPlugin
Expand Down Expand Up @@ -104,14 +107,15 @@ export class AnomalyDetectionOpenSearchDashboardsPlugin

public start(
core: CoreStart,
{ embeddable, visAugmenter, uiActions }: AnomalyDetectionStartDeps
{ embeddable, visAugmenter, uiActions, data }: AnomalyDetectionStartDeps
): AnomalyDetectionOpenSearchDashboardsPluginStart {
setUISettings(core.uiSettings);
setEmbeddable(embeddable);
setOverlays(core.overlays);
setSavedFeatureAnywhereLoader(visAugmenter.savedAugmentVisLoader);
setNotifications(core.notifications);
setUiActions(uiActions);
setQueryService(data.query);
return {};
}
}
5 changes: 5 additions & 0 deletions public/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
NotificationsStart,
OverlayStart,
} from '../../../src/core/public';
import { DataPublicPluginStart } from '../../../src/plugins/data/public';
import { EmbeddableStart } from '../../../src/plugins/embeddable/public';
import { createGetterSetter } from '../../../src/plugins/opensearch_dashboards_utils/public';
import { UiActionsStart } from '../../../src/plugins/ui_actions/public';
Expand All @@ -35,6 +36,9 @@ export const [getUiActions, setUiActions] =
export const [getUISettings, setUISettings] =
createGetterSetter<IUiSettingsClient>('UISettings');

export const [getQueryService, setQueryService] =
createGetterSetter<DataPublicPluginStart['query']>('Query');

// This is primarily used for mocking this module and each of its fns in tests.
export default {
getSavedFeatureAnywhereLoader,
Expand All @@ -44,4 +48,5 @@ export default {
getNotifications,
getOverlays,
setUISettings,
setQueryService,
};
2 changes: 1 addition & 1 deletion public/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ export enum MISSING_FEATURE_DATA_SEVERITY {

export const SPACE_STR = ' ';

export const APM_TRACE = 'apmTrace';
export const ANOMALY_DETECTION_ICON = 'anomalyDetection';
4 changes: 2 additions & 2 deletions public/utils/contextMenu/getActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import AnywhereParentFlyout from '../../components/FeatureAnywhereContextMenu/An
import { Provider } from 'react-redux';
import configureStore from '../../redux/configureStore';
import DocumentationTitle from '../../components/FeatureAnywhereContextMenu/DocumentationTitle/containers/DocumentationTitle';
import { AD_FEATURE_ANYWHERE_LINK, APM_TRACE } from '../constants';
import { AD_FEATURE_ANYWHERE_LINK, ANOMALY_DETECTION_ICON } from '../constants';
import { getClient, getOverlays } from '../../../public/services';
import { FLYOUT_MODES } from '../../../public/components/FeatureAnywhereContextMenu/AnywhereParentFlyout/constants';

Expand All @@ -22,7 +22,7 @@ const grouping: Action['grouping'] = [
{
id: 'ad-dashboard-context-menu',
getDisplayName: () => 'Anomaly Detection',
getIconType: () => APM_TRACE,
getIconType: () => ANOMALY_DETECTION_ICON,
category: 'vis_augmenter',
order: 20,
},
Expand Down