-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into main_issue569
Signed-off-by: AWSHurneyt <[email protected]>
- Loading branch information
Showing
121 changed files
with
5,637 additions
and
892 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
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
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,70 @@ | ||
import { EuiIconType } from '@elastic/eui/src/components/icon/icon'; | ||
import { IEmbeddable } from '../../../../src/plugins/dashboard/public/embeddable_plugin'; | ||
import { | ||
DASHBOARD_CONTAINER_TYPE, | ||
DashboardContainer, | ||
} from '../../../../src/plugins/dashboard/public'; | ||
import { IncompatibleActionError, createAction } from '../../../../src/plugins/ui_actions/public'; | ||
import { isReferenceOrValueEmbeddable } from '../../../../src/plugins/embeddable/public'; | ||
import { Action } from '../../../../src/plugins/ui_actions/public'; | ||
import { isEligibleForVisLayers } from '../../../../src/plugins/vis_augmenter/public'; | ||
import { getUISettings } from '../services'; | ||
|
||
export const ACTION_ALERTING = 'alerting'; | ||
|
||
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: JSX.Element | string; | ||
icon: EuiIconType; | ||
id: string; | ||
type: Action['type']; | ||
order: number; | ||
onExecute: Function; | ||
} | ||
|
||
export const createAlertingAction = ({ | ||
grouping, | ||
title, | ||
icon, | ||
id, | ||
order, | ||
onExecute, | ||
type, | ||
}: CreateOptions) => | ||
createAction({ | ||
id, | ||
order, | ||
getDisplayName: ({ embeddable }: ActionContext) => { | ||
if (!embeddable.parent || !isDashboard(embeddable.parent)) { | ||
throw new IncompatibleActionError(); | ||
} | ||
return title; | ||
}, | ||
getIconType: () => icon, | ||
type, | ||
grouping, | ||
// Do not show actions for certin visualizations | ||
isCompatible: async ({ embeddable }: ActionContext) => { | ||
return Boolean( | ||
embeddable.parent && | ||
embeddable.getInput()?.viewMode === 'view' && | ||
isDashboard(embeddable.parent) && | ||
isEligibleForVisLayers(embeddable.vis, getUISettings()) | ||
); | ||
}, | ||
execute: async (context: ActionContext) => { | ||
if (!isReferenceOrValueEmbeddable(context.embeddable)) { | ||
throw new IncompatibleActionError(); | ||
} | ||
|
||
onExecute(context); | ||
}, | ||
}); |
21 changes: 21 additions & 0 deletions
21
public/components/FeatureAnywhereContextMenu/AddAlertingMonitor/AddAlertingMonitor.test.js
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,21 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { httpServiceMock, notificationServiceMock } from '../../../../../../src/core/public/mocks'; | ||
import { shallow } from 'enzyme'; | ||
import AddAlertingMonitor from './AddAlertingMonitor'; | ||
import { setClient, setNotifications } from '../../../services'; | ||
|
||
describe('AddAlertingMonitor', () => { | ||
const httpClient = httpServiceMock.createStartContract(); | ||
setClient(httpClient); | ||
const notifications = notificationServiceMock.createStartContract(); | ||
setNotifications(notifications); | ||
test('renders', () => { | ||
const wrapper = shallow(<AddAlertingMonitor {...{ embeddable: { vis: { title: '' } } }} />); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.