diff --git a/x-pack/plugins/observability_solution/investigate_app/public/items/embeddable_item/register_embeddable_item.tsx b/x-pack/plugins/observability_solution/investigate_app/public/items/embeddable_item/register_embeddable_item.tsx index 77833e80ec199..8507ec8944c7c 100644 --- a/x-pack/plugins/observability_solution/investigate_app/public/items/embeddable_item/register_embeddable_item.tsx +++ b/x-pack/plugins/observability_solution/investigate_app/public/items/embeddable_item/register_embeddable_item.tsx @@ -4,15 +4,11 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { EuiLoadingSpinner, EuiFlexItem } from '@elastic/eui'; +import { EuiFlexItem } from '@elastic/eui'; import { css } from '@emotion/css'; import { ReactEmbeddableRenderer } from '@kbn/embeddable-plugin/public'; import type { GlobalWidgetParameters } from '@kbn/investigate-plugin/public'; -import { useAbortableAsync } from '@kbn/observability-utils-browser/hooks/use_abortable_async'; -import React, { useEffect, useMemo, useRef, useState } from 'react'; -import { v4 } from 'uuid'; -import { ErrorMessage } from '../../components/error_message'; -import { useKibana } from '../../hooks/use_kibana'; +import React, { useMemo, useRef } from 'react'; import { Options } from '../register_items'; export const EMBEDDABLE_ITEM_TYPE = 'embeddable'; @@ -62,101 +58,6 @@ function ReactEmbeddable({ type, config, timeRange: { from, to }, savedObjectId ); } -function LegacyEmbeddable({ type, config, timeRange: { from, to }, savedObjectId }: Props) { - const { - dependencies: { - start: { embeddable }, - }, - } = useKibana(); - - const [targetElement, setTargetElement] = useState(null); - - const embeddableInstanceAsync = useAbortableAsync(async () => { - const factory = embeddable.getEmbeddableFactory(type); - - if (!factory) { - throw new Error(`Cannot find embeddable factory for ${type}`); - } - - const configWithId = { - id: savedObjectId ?? v4(), - ...config, - }; - - const configWithOverrides = { - ...configWithId, - timeRange: { - from, - to, - }, - overrides: { - axisX: { hide: true }, - axisLeft: { style: { axisTitle: { visible: false } } }, - settings: { showLegend: false }, - }, - }; - - if (savedObjectId) { - return factory.createFromSavedObject(configWithOverrides.id, configWithOverrides); - } - - const instance = await factory.create(configWithOverrides); - - return instance; - }, [type, savedObjectId, config, from, to, embeddable]); - - const embeddableInstance = embeddableInstanceAsync.value; - - useEffect(() => { - if (!targetElement || !embeddableInstance) { - return; - } - - embeddableInstance.render(targetElement); - - return () => {}; - }, [embeddableInstance, targetElement]); - - useEffect(() => { - return () => { - if (embeddableInstance) { - embeddableInstance.destroy(); - } - }; - }, [embeddableInstance]); - - if (embeddableInstanceAsync.error) { - return ; - } - - if (!embeddableInstance) { - return ; - } - - return ( -
{ - setTargetElement(element); - }} - /> - ); -} - -function EmbeddableWidget(props: Props) { - const { - dependencies: { - start: { embeddable }, - }, - } = useKibana(); - - if (embeddable.reactEmbeddableRegistryHasKey(props.type)) { - return ; - } - - return ; -} - interface EmbeddableItemParams { type: string; config: Record; @@ -197,7 +98,7 @@ export function registerEmbeddableItem({ } `} > - + ); },