forked from elastic/kibana
-
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.
[ML] AIOps: UI action for Change Point Detection embeddable to open i…
…n the ML app (elastic#176694) ## Summary Closes elastic#161248 Added a UI action to open change point detection in the AIOps labs. <img width="1137" alt="image" src="https://github.com/elastic/kibana/assets/5236598/077c0e34-0ac0-4790-8cbe-c6048ee90d22"> ### Checklist - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [x] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [x] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [x] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
- Loading branch information
Showing
7 changed files
with
191 additions
and
3 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
58 changes: 58 additions & 0 deletions
58
x-pack/plugins/aiops/public/ui_actions/open_change_point_ml.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,58 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { UiActionsActionDefinition } from '@kbn/ui-actions-plugin/public'; | ||
import { i18n } from '@kbn/i18n'; | ||
import type { CoreStart } from '@kbn/core/public'; | ||
import type { AiopsPluginStartDeps } from '../types'; | ||
import type { EditChangePointChartsPanelContext } from '../embeddable/types'; | ||
import { EMBEDDABLE_CHANGE_POINT_CHART_TYPE } from '../../common/constants'; | ||
|
||
export const OPEN_CHANGE_POINT_IN_ML_APP_ACTION = 'openChangePointInMlAppAction'; | ||
|
||
export function createOpenChangePointInMlAppAction( | ||
coreStart: CoreStart, | ||
pluginStart: AiopsPluginStartDeps | ||
): UiActionsActionDefinition<EditChangePointChartsPanelContext> { | ||
return { | ||
id: 'open-change-point-in-ml-app', | ||
type: OPEN_CHANGE_POINT_IN_ML_APP_ACTION, | ||
getIconType(context): string { | ||
return 'link'; | ||
}, | ||
getDisplayName: () => | ||
i18n.translate('xpack.aiops.actions.openChangePointInMlAppName', { | ||
defaultMessage: 'Open in AIOps Labs', | ||
}), | ||
async getHref(context): Promise<string | undefined> { | ||
const locator = pluginStart.share.url.locators.get('ML_APP_LOCATOR')!; | ||
|
||
const { timeRange, metricField, fn, splitField, dataViewId } = context.embeddable.getInput(); | ||
|
||
return locator.getUrl({ | ||
page: 'aiops/change_point_detection', | ||
pageState: { | ||
index: dataViewId, | ||
timeRange, | ||
fieldConfigs: [{ fn, metricField, ...(splitField ? { splitField } : {}) }], | ||
}, | ||
}); | ||
}, | ||
async execute(context) { | ||
if (!context.embeddable) { | ||
throw new Error('Not possible to execute an action without the embeddable context'); | ||
} | ||
const aiopsChangePointUrl = await this.getHref!(context); | ||
if (aiopsChangePointUrl) { | ||
await coreStart.application.navigateToUrl(aiopsChangePointUrl!); | ||
} | ||
}, | ||
async isCompatible({ embeddable }) { | ||
return embeddable.type === EMBEDDABLE_CHANGE_POINT_CHART_TYPE; | ||
}, | ||
}; | ||
} |
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,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/public'; | ||
import { ML_PAGES } from '../../../common/constants/locator'; | ||
import type { ChangePointDetectionUrlState } from '../../../common/types/locator'; | ||
|
||
/** | ||
* Creates URL to the Change Point Detection page | ||
*/ | ||
export function formatChangePointDetectionUrl( | ||
appBasePath: string, | ||
params: ChangePointDetectionUrlState['pageState'] | ||
): string { | ||
let url = `${appBasePath}/${ML_PAGES.AIOPS_CHANGE_POINT_DETECTION}`; | ||
|
||
if (!params?.fieldConfigs) { | ||
throw new Error('Field configs are required to create a change point detection URL'); | ||
} | ||
|
||
if (!params.index) { | ||
throw new Error('Data view is required to create a change point detection URL'); | ||
} | ||
|
||
url = `${url}?index=${params.index}`; | ||
|
||
const { timeRange, fieldConfigs } = params; | ||
|
||
const appState = { | ||
fieldConfigs, | ||
}; | ||
const queryState = { | ||
time: timeRange, | ||
}; | ||
|
||
url = setStateToKbnUrl('_g', queryState, { useHash: false, storeInHashQuery: false }, url); | ||
url = setStateToKbnUrl( | ||
'_a', | ||
{ changePoint: appState }, | ||
{ useHash: false, storeInHashQuery: false }, | ||
url | ||
); | ||
|
||
return url; | ||
} |
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