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.
[8.x] [ML] AiOps: Action for adding Log Rate analysis embeddable to a…
… dashboard (elastic#200557) (elastic#200891) # Backport This will backport the following commits from `main` to `8.x`: - [[ML] AiOps: Action for adding Log Rate analysis embeddable to a dashboard (elastic#200557)](elastic#200557) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Robert Jaszczurek","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-20T00:29:40Z","message":"[ML] AiOps: Action for adding Log Rate analysis embeddable to a dashboard (elastic#200557)\n\n## Summary\r\n\r\nPart of: [elastic#197247](https://github.com/elastic/kibana/issues/197247)\r\n\r\n- Added the ability to add a Log Rate Analysis embeddable to a dashboard\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/37efd83e-9196-434d-a80d-9249623f3222\r\n\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies following conditions. \r\n\r\nReviewers should verify this PR satisfies this list as well.\r\n\r\n- [x] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"50a262692fc55ea513f1781eee9d14a7073f0368","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement",":ml","v9.0.0","Team:ML","Feature:ML/AIOps","backport:version","v8.17.0"],"number":200557,"url":"https://github.com/elastic/kibana/pull/200557","mergeCommit":{"message":"[ML] AiOps: Action for adding Log Rate analysis embeddable to a dashboard (elastic#200557)\n\n## Summary\r\n\r\nPart of: [elastic#197247](https://github.com/elastic/kibana/issues/197247)\r\n\r\n- Added the ability to add a Log Rate Analysis embeddable to a dashboard\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/37efd83e-9196-434d-a80d-9249623f3222\r\n\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies following conditions. \r\n\r\nReviewers should verify this PR satisfies this list as well.\r\n\r\n- [x] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"50a262692fc55ea513f1781eee9d14a7073f0368"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/200557","number":200557,"mergeCommit":{"message":"[ML] AiOps: Action for adding Log Rate analysis embeddable to a dashboard (elastic#200557)\n\n## Summary\r\n\r\nPart of: [elastic#197247](https://github.com/elastic/kibana/issues/197247)\r\n\r\n- Added the ability to add a Log Rate Analysis embeddable to a dashboard\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/37efd83e-9196-434d-a80d-9249623f3222\r\n\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies following conditions. \r\n\r\nReviewers should verify this PR satisfies this list as well.\r\n\r\n- [x] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"50a262692fc55ea513f1781eee9d14a7073f0368"}},{"branch":"8.x","label":"v8.17.0","labelRegex":"^v8.17.0$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/200835","number":200835,"state":"OPEN"}]}] BACKPORT-->
- Loading branch information
Showing
8 changed files
with
283 additions
and
24 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
176 changes: 176 additions & 0 deletions
176
...onents/log_rate_analysis/log_rate_analysis_content/log_rate_analysis_attachments_menu.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,176 @@ | ||
/* | ||
* 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 { SaveModalDashboardProps } from '@kbn/presentation-util-plugin/public'; | ||
import { LazySavedObjectSaveModalDashboard } from '@kbn/presentation-util-plugin/public'; | ||
import { withSuspense } from '@kbn/shared-ux-utility'; | ||
import React, { useState, useCallback, useMemo } from 'react'; | ||
import { useTimeRangeUpdates } from '@kbn/ml-date-picker'; | ||
import { EMBEDDABLE_LOG_RATE_ANALYSIS_TYPE } from '@kbn/aiops-log-rate-analysis/constants'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import type { EuiContextMenuProps } from '@elastic/eui'; | ||
import { | ||
EuiButton, | ||
EuiButtonIcon, | ||
EuiContextMenu, | ||
EuiFlexItem, | ||
EuiForm, | ||
EuiFormRow, | ||
EuiPanel, | ||
EuiPopover, | ||
EuiSpacer, | ||
EuiSwitch, | ||
} from '@elastic/eui'; | ||
import { useDataSource } from '../../../hooks/use_data_source'; | ||
import type { LogRateAnalysisEmbeddableState } from '../../../embeddables/log_rate_analysis/types'; | ||
import { useAiopsAppContext } from '../../../hooks/use_aiops_app_context'; | ||
|
||
const SavedObjectSaveModalDashboard = withSuspense(LazySavedObjectSaveModalDashboard); | ||
|
||
export const LogRateAnalysisAttachmentsMenu = () => { | ||
const { | ||
application: { capabilities }, | ||
embeddable, | ||
} = useAiopsAppContext(); | ||
const { dataView } = useDataSource(); | ||
|
||
const [applyTimeRange, setApplyTimeRange] = useState(false); | ||
const [isActionMenuOpen, setIsActionMenuOpen] = useState(false); | ||
const [dashboardAttachmentReady, setDashboardAttachmentReady] = useState(false); | ||
|
||
const timeRange = useTimeRangeUpdates(); | ||
|
||
const canEditDashboards = capabilities.dashboard.createNew; | ||
|
||
const onSave: SaveModalDashboardProps['onSave'] = useCallback( | ||
({ dashboardId, newTitle, newDescription }) => { | ||
const stateTransfer = embeddable!.getStateTransfer(); | ||
|
||
const embeddableInput: Partial<LogRateAnalysisEmbeddableState> = { | ||
title: newTitle, | ||
description: newDescription, | ||
dataViewId: dataView.id, | ||
hidePanelTitles: false, | ||
...(applyTimeRange && { timeRange }), | ||
}; | ||
|
||
const state = { | ||
input: embeddableInput, | ||
type: EMBEDDABLE_LOG_RATE_ANALYSIS_TYPE, | ||
}; | ||
|
||
const path = dashboardId === 'new' ? '#/create' : `#/view/${dashboardId}`; | ||
|
||
stateTransfer.navigateToWithEmbeddablePackage('dashboards', { state, path }); | ||
}, | ||
[dataView.id, embeddable, applyTimeRange, timeRange] | ||
); | ||
|
||
const panels = useMemo<Exclude<EuiContextMenuProps['panels'], undefined>>(() => { | ||
return [ | ||
{ | ||
id: 'attachMainPanel', | ||
size: 's', | ||
items: [ | ||
...(canEditDashboards | ||
? [ | ||
{ | ||
name: i18n.translate('xpack.aiops.logRateAnalysis.addToDashboardTitle', { | ||
defaultMessage: 'Add to dashboard', | ||
}), | ||
panel: 'attachToDashboardPanel', | ||
'data-test-subj': 'aiopsLogRateAnalysisAttachToDashboardButton', | ||
}, | ||
] | ||
: []), | ||
], | ||
}, | ||
{ | ||
id: 'attachToDashboardPanel', | ||
size: 's', | ||
title: i18n.translate('xpack.aiops.logRateAnalysis.attachToDashboardTitle', { | ||
defaultMessage: 'Add to dashboard', | ||
}), | ||
content: ( | ||
<EuiPanel paddingSize="s"> | ||
<EuiSpacer size="s" /> | ||
<EuiForm> | ||
<EuiFormRow> | ||
<EuiSwitch | ||
label={i18n.translate('xpack.aiops.logRateAnalysis.applyTimeRangeLabel', { | ||
defaultMessage: 'Apply time range', | ||
})} | ||
checked={applyTimeRange} | ||
onChange={(e) => setApplyTimeRange(e.target.checked)} | ||
/> | ||
</EuiFormRow> | ||
<EuiSpacer size="s" /> | ||
<EuiButton | ||
size="s" | ||
data-test-subj="aiopsLogRateAnalysisAttachToDashboardSubmitButton" | ||
fill | ||
fullWidth | ||
type={'submit'} | ||
onClick={() => { | ||
setIsActionMenuOpen(false); | ||
setDashboardAttachmentReady(true); | ||
}} | ||
> | ||
<FormattedMessage | ||
id="xpack.aiops.logRateAnalysis.attachToDashboardSubmitButtonLabel" | ||
defaultMessage="Add to dashboard" | ||
/> | ||
</EuiButton> | ||
</EuiForm> | ||
</EuiPanel> | ||
), | ||
}, | ||
]; | ||
}, [canEditDashboards, applyTimeRange]); | ||
|
||
return ( | ||
<> | ||
{!!panels[0]?.items?.length && ( | ||
<EuiFlexItem> | ||
<EuiPopover | ||
button={ | ||
<EuiButtonIcon | ||
data-test-subj="aiopsLogRateAnalysisAttachmentsMenuButton" | ||
aria-label={i18n.translate('xpack.aiops.logRateAnalysis.attachmentsMenuAriaLabel', { | ||
defaultMessage: 'Attachments', | ||
})} | ||
iconType="boxesHorizontal" | ||
color="text" | ||
onClick={() => setIsActionMenuOpen(!isActionMenuOpen)} | ||
/> | ||
} | ||
isOpen={isActionMenuOpen} | ||
closePopover={() => setIsActionMenuOpen(false)} | ||
panelPaddingSize="none" | ||
anchorPosition="downRight" | ||
> | ||
<EuiContextMenu panels={panels} initialPanelId="attachMainPanel" /> | ||
</EuiPopover> | ||
</EuiFlexItem> | ||
)} | ||
{dashboardAttachmentReady ? ( | ||
<SavedObjectSaveModalDashboard | ||
canSaveByReference={false} | ||
objectType={i18n.translate('xpack.aiops.logRateAnalysis.objectTypeLabel', { | ||
defaultMessage: 'Log rate analysis', | ||
})} | ||
documentInfo={{ | ||
title: 'Log rate analysis', | ||
}} | ||
onClose={() => setDashboardAttachmentReady(false)} | ||
onSave={onSave} | ||
/> | ||
) : null} | ||
</> | ||
); | ||
}; |
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