-
Notifications
You must be signed in to change notification settings - Fork 71
Register AD as dashboard context menu option #482
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
Merged
jackiehanyang
merged 7 commits into
opensearch-project:featureAnywhere
from
jackiehanyang:codeReviewBranch
May 19, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
53a3324
Register AD as dashboard context menu option
jackiehanyang 5711948
addressing comments
jackiehanyang cde1797
add getActions props
jackiehanyang 8b12e8c
add EmbeddableStart
jackiehanyang e145bd3
remove spread operator
jackiehanyang 8a37e4c
clenaup
jackiehanyang 152ba99
add overlay getter and setter
jackiehanyang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| import { IEmbeddable } from '../../../../src/plugins/dashboard/public/embeddable_plugin'; | ||
|
jackiehanyang marked this conversation as resolved.
|
||
| import { | ||
| DASHBOARD_CONTAINER_TYPE, | ||
| DashboardContainer, | ||
| } from '../../../../src/plugins/dashboard/public'; | ||
| import { | ||
| IncompatibleActionError, | ||
| createAction, | ||
| Action, | ||
| } from '../../../../src/plugins/ui_actions/public'; | ||
| import { isReferenceOrValueEmbeddable } from '../../../../src/plugins/embeddable/public'; | ||
| import { EuiIconType } from '@elastic/eui/src/components/icon/icon'; | ||
|
|
||
| export const ACTION_AD = 'ad'; | ||
|
|
||
| function isDashboard( | ||
| embeddable: IEmbeddable | ||
| ): embeddable is DashboardContainer { | ||
| return embeddable.type === DASHBOARD_CONTAINER_TYPE; | ||
| } | ||
|
|
||
| export interface ActionContext { | ||
| embeddable: IEmbeddable; | ||
| } | ||
|
|
||
| export interface CreateOptions { | ||
| grouping: Action['grouping']; | ||
| title: string; | ||
| icon: EuiIconType; | ||
| id: string; | ||
| order: number; | ||
| onClick: Function; | ||
| } | ||
|
|
||
| export const createADAction = ({ | ||
| grouping, | ||
| title, | ||
| icon, | ||
| id, | ||
| order, | ||
| onClick, | ||
| }: CreateOptions) => | ||
| createAction({ | ||
| id, | ||
| order, | ||
| getDisplayName: ({ embeddable }: ActionContext) => { | ||
| if (!embeddable.parent || !isDashboard(embeddable.parent)) { | ||
| throw new IncompatibleActionError(); | ||
| } | ||
| return title; | ||
| }, | ||
| getIconType: () => icon, | ||
| type: ACTION_AD, | ||
| grouping, | ||
| isCompatible: async ({ embeddable }: ActionContext) => { | ||
| const paramsType = embeddable.vis?.params?.type; | ||
| const seriesParams = embeddable.vis?.params?.seriesParams || []; | ||
| const series = embeddable.vis?.params?.series || []; | ||
| const isLineGraph = | ||
| seriesParams.find((item) => item.type === 'line') || | ||
| series.find((item) => item.chart_type === 'line'); | ||
| const isValidVis = isLineGraph && paramsType !== 'table'; | ||
| return Boolean( | ||
| embeddable.parent && isDashboard(embeddable.parent) && isValidVis | ||
| ); | ||
| }, | ||
| execute: async ({ embeddable }: ActionContext) => { | ||
| if (!isReferenceOrValueEmbeddable(embeddable)) { | ||
| throw new IncompatibleActionError(); | ||
| } | ||
|
|
||
| onClick({ embeddable }); | ||
| }, | ||
| }); | ||
37 changes: 37 additions & 0 deletions
37
public/components/FeatureAnywhereContextMenu/AnywhereParentFlyout/AnywhereParentFlyout.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| import React, { useState } from 'react'; | ||
|
jackiehanyang marked this conversation as resolved.
|
||
| import { get } from 'lodash'; | ||
| import AddAnomalyDetector from '../CreateAnomalyDetector'; | ||
| import { getEmbeddable } from '../../../../public/services'; | ||
|
|
||
| const AnywhereParentFlyout = ({ startingFlyout, ...props }) => { | ||
|
ohltyler marked this conversation as resolved.
|
||
| const embeddable = getEmbeddable().getEmbeddableFactory; | ||
| const indices: { label: string }[] = [ | ||
| { label: get(embeddable, 'vis.data.indexPattern.title', '') }, | ||
| ]; | ||
|
|
||
| const [mode, setMode] = useState(startingFlyout); | ||
| const [selectedDetectorId, setSelectedDetectorId] = useState(); | ||
|
|
||
| const AnywhereFlyout = { | ||
| create: AddAnomalyDetector, | ||
| }[mode]; | ||
|
|
||
| return ( | ||
| <AnywhereFlyout | ||
| {...{ | ||
|
jackiehanyang marked this conversation as resolved.
|
||
| ...props, | ||
| setMode, | ||
| mode, | ||
| indices, | ||
| selectedDetectorId, | ||
| setSelectedDetectorId, | ||
| }} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export default AnywhereParentFlyout; | ||
8 changes: 8 additions & 0 deletions
8
public/components/FeatureAnywhereContextMenu/AnywhereParentFlyout/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import AnywhereParentFlyout from './AnywhereParentFlyout'; | ||
|
|
||
| export default AnywhereParentFlyout; |
28 changes: 28 additions & 0 deletions
28
...omponents/FeatureAnywhereContextMenu/DocumentationTitle/containers/DocumentationTitle.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
| import { EuiIcon, EuiFlexItem, EuiFlexGroup } from '@elastic/eui'; | ||
| import { i18n } from '@osd/i18n'; | ||
|
|
||
| const DocumentationTitle = () => ( | ||
| <EuiFlexGroup> | ||
| <EuiFlexItem> | ||
| <span data-ui="documentation-title-text"> | ||
| {i18n.translate( | ||
| 'dashboard.actions.adMenuItem.documentation.displayName', | ||
| { | ||
| defaultMessage: 'Documentation', | ||
| } | ||
| )} | ||
| </span> | ||
| </EuiFlexItem> | ||
| <EuiFlexItem grow={false}> | ||
| <EuiIcon type="popout" /> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| ); | ||
|
|
||
| export default DocumentationTitle; |
8 changes: 8 additions & 0 deletions
8
public/components/FeatureAnywhereContextMenu/DocumentationTitle/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import DocumentationTitle from './containers/DocumentationTitle'; | ||
|
|
||
| export default DocumentationTitle; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,58 +14,73 @@ import { | |
| CoreSetup, | ||
| CoreStart, | ||
| Plugin, | ||
| PluginInitializerContext, | ||
| } from '../../../src/core/public'; | ||
| import { | ||
| AnomalyDetectionOpenSearchDashboardsPluginSetup, | ||
| AnomalyDetectionOpenSearchDashboardsPluginStart, | ||
| } from '.'; | ||
| 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 } from './services'; | ||
| import { setClient, setEmbeddable, setOverlays } from './services'; | ||
| import { AnomalyDetectionOpenSearchDashboardsPluginStart } from 'public'; | ||
| import { createStartServicesGetter } from '../../../src/plugins/opensearch_dashboards_utils/public'; | ||
|
|
||
| export class AnomalyDetectionOpenSearchDashboardsPlugin | ||
| implements | ||
| Plugin< | ||
| AnomalyDetectionOpenSearchDashboardsPluginSetup, | ||
| AnomalyDetectionOpenSearchDashboardsPluginStart | ||
| > | ||
| { | ||
| constructor(private readonly initializerContext: PluginInitializerContext) { | ||
| // can retrieve config from initializerContext | ||
| declare module '../../../src/plugins/ui_actions/public' { | ||
| export interface ActionContextMapping { | ||
| [ACTION_AD]: {}; | ||
| } | ||
| } | ||
|
|
||
| public setup( | ||
| core: CoreSetup, | ||
| plugins | ||
| ): AnomalyDetectionOpenSearchDashboardsPluginSetup { | ||
| core.application.register({ | ||
| id: 'anomaly-detection-dashboards', | ||
| 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, depsStart] = await core.getStartServices(); | ||
| return renderApp(coreStart, params); | ||
| }, | ||
| }); | ||
| export interface AnomalyDetectionSetupDeps { | ||
| embeddable: EmbeddableSetup; | ||
| } | ||
|
|
||
| // Set the HTTP client so it can be pulled into expression fns to make | ||
| // direct server-side calls | ||
| setClient(core.http); | ||
| export interface AnomalyDetectionStartDeps { | ||
| embeddable: EmbeddableStart; | ||
| } | ||
|
|
||
| // registers the expression function used to render anomalies on an Augmented Visualization | ||
| plugins.expressions.registerFunction(overlayAnomaliesFunction); | ||
| 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); | ||
| }, | ||
| }); | ||
|
|
||
| public start( | ||
| core: CoreStart | ||
| ): AnomalyDetectionOpenSearchDashboardsPluginStart { | ||
| return {}; | ||
| } | ||
| } | ||
| // 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. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: can update this comment |
||
| 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 {}; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.