mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
# Backport This will backport the following commits from `main` to `8.11`: - [[Cases] Disabling editing ESQL visualizations (#171191)](https://github.com/elastic/kibana/pull/171191) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Christos Nasikas","email":"christos.nasikas@elastic.co"},"sourceCommit":{"committedDate":"2023-11-14T16:20:22Z","message":"[Cases] Disabling editing ESQL visualizations (#171191)\n\n## Summary\r\n\r\nThis PR disables editing an ESQL visualization from within Cases.\r\n\r\nFixes: https://github.com/elastic/kibana/issues/171154\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\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\r\n\r\n### For maintainers\r\n\r\n- [x] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"b7bdb58e7c8a9321bf86d0f24d35435feb8aac6d","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","Feature:Cases","backport:prev-minor","Feature:ES|QL","v8.12.0","v8.11.2"],"number":171191,"url":"https://github.com/elastic/kibana/pull/171191","mergeCommit":{"message":"[Cases] Disabling editing ESQL visualizations (#171191)\n\n## Summary\r\n\r\nThis PR disables editing an ESQL visualization from within Cases.\r\n\r\nFixes: https://github.com/elastic/kibana/issues/171154\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\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\r\n\r\n### For maintainers\r\n\r\n- [x] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"b7bdb58e7c8a9321bf86d0f24d35435feb8aac6d"}},"sourceBranch":"main","suggestedTargetBranches":["8.11"],"targetPullRequestStates":[{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/171191","number":171191,"mergeCommit":{"message":"[Cases] Disabling editing ESQL visualizations (#171191)\n\n## Summary\r\n\r\nThis PR disables editing an ESQL visualization from within Cases.\r\n\r\nFixes: https://github.com/elastic/kibana/issues/171154\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\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\r\n\r\n### For maintainers\r\n\r\n- [x] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"b7bdb58e7c8a9321bf86d0f24d35435feb8aac6d"}},{"branch":"8.11","label":"v8.11.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Christos Nasikas <christos.nasikas@elastic.co>
This commit is contained in:
parent
005e1899fd
commit
124d2bfb57
4 changed files with 45 additions and 11 deletions
|
@ -8,6 +8,7 @@
|
|||
import { useCallback } from 'react';
|
||||
import type { TypedLensByValueInput } from '@kbn/lens-plugin/public';
|
||||
|
||||
import { isOfAggregateQueryType } from '@kbn/es-query';
|
||||
import { AttachmentActionType } from '../../../../client/attachment_framework/types';
|
||||
import { useKibana } from '../../../../common/lib/kibana';
|
||||
import {
|
||||
|
@ -24,6 +25,8 @@ export const useLensOpenVisualization = ({ comment }: { comment: string }) => {
|
|||
lens: { navigateToPrefilledEditor, canUseEditor },
|
||||
} = useKibana().services;
|
||||
|
||||
const hasLensPermissions = canUseEditor();
|
||||
|
||||
const handleClick = useCallback(() => {
|
||||
navigateToPrefilledEditor(
|
||||
{
|
||||
|
@ -38,15 +41,26 @@ export const useLensOpenVisualization = ({ comment }: { comment: string }) => {
|
|||
);
|
||||
}, [lensVisualization, navigateToPrefilledEditor]);
|
||||
|
||||
if (!lensVisualization.length || lensVisualization?.[0]?.attributes == null) {
|
||||
return { canUseEditor: hasLensPermissions, actionConfig: null };
|
||||
}
|
||||
|
||||
const lensAttributes = lensVisualization[0]
|
||||
.attributes as unknown as TypedLensByValueInput['attributes'];
|
||||
|
||||
const isESQLQuery = isOfAggregateQueryType(lensAttributes.state.query);
|
||||
|
||||
if (isESQLQuery) {
|
||||
return { canUseEditor: hasLensPermissions, actionConfig: null };
|
||||
}
|
||||
|
||||
return {
|
||||
canUseEditor: canUseEditor(),
|
||||
actionConfig: !lensVisualization.length
|
||||
? null
|
||||
: {
|
||||
type: AttachmentActionType.BUTTON as const,
|
||||
iconType: 'lensApp',
|
||||
label: OPEN_IN_VISUALIZATION,
|
||||
onClick: handleClick,
|
||||
},
|
||||
canUseEditor: hasLensPermissions,
|
||||
actionConfig: {
|
||||
type: AttachmentActionType.BUTTON as const,
|
||||
iconType: 'lensApp',
|
||||
label: OPEN_IN_VISUALIZATION,
|
||||
onClick: handleClick,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
|
|
@ -24,7 +24,10 @@ describe('getVisualizationAttachmentType', () => {
|
|||
|
||||
const attachmentViewProps: PersistableStateAttachmentViewProps = {
|
||||
persistableStateAttachmentTypeId: LENS_ATTACHMENT_TYPE,
|
||||
persistableStateAttachmentState: { attributes: {}, timeRange: {} },
|
||||
persistableStateAttachmentState: {
|
||||
attributes: { state: { query: {} } },
|
||||
timeRange: {},
|
||||
},
|
||||
attachmentId: 'test',
|
||||
caseData: { title: basicCase.title, id: basicCase.id },
|
||||
};
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { set } from 'lodash';
|
||||
import React from 'react';
|
||||
import { screen } from '@testing-library/react';
|
||||
import type { AppMockRenderer } from '../../common/mock';
|
||||
|
@ -60,4 +61,18 @@ describe('OpenLensButton', () => {
|
|||
|
||||
expect(screen.queryByText('Open visualization')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not show the button if the query is an ESQL', () => {
|
||||
const esqlProps = {
|
||||
attachmentId: 'test',
|
||||
...lensVisualization,
|
||||
};
|
||||
|
||||
set(esqlProps, 'attributes.state.query', { esql: '' });
|
||||
|
||||
// @ts-expect-error: props are correct
|
||||
appMockRender.render(<OpenLensButton {...esqlProps} />);
|
||||
|
||||
expect(screen.queryByText('Open visualization')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { isOfAggregateQueryType } from '@kbn/es-query';
|
||||
import { EuiButtonEmpty } from '@elastic/eui';
|
||||
import React, { useCallback } from 'react';
|
||||
import { useKibana } from '../../common/lib/kibana';
|
||||
|
@ -32,8 +33,9 @@ const OpenLensButtonComponent: React.FC<Props> = ({ attachmentId, attributes, ti
|
|||
}, [attachmentId, attributes, navigateToPrefilledEditor, timeRange]);
|
||||
|
||||
const hasLensPermissions = canUseEditor();
|
||||
const isESQLQuery = isOfAggregateQueryType(attributes.state.query);
|
||||
|
||||
if (!hasLensPermissions) {
|
||||
if (!hasLensPermissions || isESQLQuery) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue