-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Register AD as dashboard context menu option (opensearch-project#482)
* Register AD as dashboard context menu option Signed-off-by: Jackie Han <[email protected]> * addressing comments Signed-off-by: Jackie Han <[email protected]> * add getActions props Signed-off-by: Jackie Han <[email protected]> * add EmbeddableStart Signed-off-by: Jackie Han <[email protected]> * remove spread operator Signed-off-by: Jackie Han <[email protected]> * clenaup Signed-off-by: Jackie Han <[email protected]> * add overlay getter and setter Signed-off-by: Jackie Han <[email protected]> --------- Signed-off-by: Jackie Han <[email protected]>
- Loading branch information
1 parent
f81263a
commit 09de048
Showing
10 changed files
with
325 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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 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'; | ||
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 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'; | ||
import { get } from 'lodash'; | ||
import AddAnomalyDetector from '../CreateAnomalyDetector'; | ||
import { getEmbeddable } from '../../../../public/services'; | ||
|
||
const AnywhereParentFlyout = ({ startingFlyout, ...props }) => { | ||
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 | ||
{...{ | ||
...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 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 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 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 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 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 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.