mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[Canvas] Disable Edit in Lens action for legacy savedVisualization Canvas function (#154656)
This commit is contained in:
parent
acb12665d2
commit
575397b48b
3 changed files with 26 additions and 5 deletions
|
@ -97,6 +97,7 @@ export function savedVisualization(): ExpressionFunctionDefinition<
|
|||
id,
|
||||
savedObjectId: id,
|
||||
disableTriggers: true,
|
||||
disabledActions: ['ACTION_EDIT_IN_LENS'],
|
||||
timeRange: timerange ? omit(timerange, 'type') : defaultTimeRange,
|
||||
filters: getQueryFilters(filters),
|
||||
vis: visOptions,
|
||||
|
|
|
@ -16,6 +16,11 @@ export const ErrorStrings = {
|
|||
index,
|
||||
},
|
||||
}),
|
||||
getConvertToLensUnsupportedSavedVisualization: () =>
|
||||
i18n.translate('xpack.canvas.error.actionsElements.convertToLensUnsupportedErrrorMessage', {
|
||||
defaultMessage:
|
||||
"The legacy 'savedVisualization' Canvas function does not support Lens visualizations. Try replacing this element with an 'embeddable' Canvas function.",
|
||||
}),
|
||||
},
|
||||
esPersist: {
|
||||
getSaveFailureTitle: () =>
|
||||
|
|
|
@ -8,12 +8,13 @@
|
|||
import { useEffect } from 'react';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { fromExpression } from '@kbn/interpreter';
|
||||
import { ErrorStrings } from '../../../../i18n';
|
||||
import { CANVAS_APP } from '../../../../common/lib';
|
||||
import { decode, encode } from '../../../../common/lib/embeddable_dataurl';
|
||||
import { CanvasElement, CanvasPage } from '../../../../types';
|
||||
import { useEmbeddablesService, useLabsService } from '../../../services';
|
||||
import { useEmbeddablesService, useLabsService, useNotifyService } from '../../../services';
|
||||
// @ts-expect-error unconverted file
|
||||
import { addElement } from '../../../state/actions/elements';
|
||||
import { addElement, fetchAllRenderables } from '../../../state/actions/elements';
|
||||
// @ts-expect-error unconverted file
|
||||
import { selectToplevelNodes } from '../../../state/actions/transient';
|
||||
|
||||
|
@ -23,10 +24,13 @@ import {
|
|||
} from '../../../state/actions/embeddable';
|
||||
import { clearValue } from '../../../state/actions/resolved_args';
|
||||
|
||||
const { actionsElements: strings } = ErrorStrings;
|
||||
|
||||
export const useIncomingEmbeddable = (selectedPage: CanvasPage) => {
|
||||
const embeddablesService = useEmbeddablesService();
|
||||
const labsService = useLabsService();
|
||||
const dispatch = useDispatch();
|
||||
const notifyService = useNotifyService();
|
||||
const isByValueEnabled = labsService.isProjectEnabled('labs:canvas:byValueEmbeddable');
|
||||
const stateTransferService = embeddablesService.getStateTransfer();
|
||||
|
||||
|
@ -45,10 +49,21 @@ export const useIncomingEmbeddable = (selectedPage: CanvasPage) => {
|
|||
if (originalElement) {
|
||||
const originalAst = fromExpression(originalElement!.expression);
|
||||
|
||||
const functionIndex = originalAst.chain.findIndex(
|
||||
({ function: fn }) => fn === 'embeddable'
|
||||
const functionIndex = originalAst.chain.findIndex(({ function: fn }) =>
|
||||
['embeddable', 'savedVisualization'].includes(fn)
|
||||
);
|
||||
|
||||
if (functionIndex === -1) {
|
||||
dispatch(fetchAllRenderables());
|
||||
return;
|
||||
}
|
||||
|
||||
if (originalAst.chain[functionIndex].function === 'savedVisualization') {
|
||||
notifyService.error(strings.getConvertToLensUnsupportedSavedVisualization());
|
||||
dispatch(fetchAllRenderables());
|
||||
return;
|
||||
}
|
||||
|
||||
const originalInput = decode(
|
||||
originalAst.chain[functionIndex].arguments.config[0] as string
|
||||
);
|
||||
|
@ -91,5 +106,5 @@ export const useIncomingEmbeddable = (selectedPage: CanvasPage) => {
|
|||
dispatch(addElement(selectedPage.id, { expression }));
|
||||
}
|
||||
}
|
||||
}, [dispatch, selectedPage, incomingEmbeddable, isByValueEnabled]);
|
||||
}, [dispatch, notifyService, selectedPage, incomingEmbeddable, isByValueEnabled]);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue