From a1560e10772fd091805842ef6fb5f0d434d5c9e2 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Wed, 31 Aug 2022 10:27:17 +0200 Subject: [PATCH] improve "debug in sandbox" functionality (#139724) --- .../public/plugin.ts | 61 ++++--------------- x-pack/plugins/lens/public/app_plugin/app.tsx | 1 + .../lens/public/app_plugin/lens_top_nav.tsx | 3 + .../plugins/lens/public/app_plugin/types.ts | 2 + x-pack/plugins/lens/public/types.ts | 2 + 5 files changed, 21 insertions(+), 48 deletions(-) diff --git a/x-pack/examples/third_party_lens_navigation_prompt/public/plugin.ts b/x-pack/examples/third_party_lens_navigation_prompt/public/plugin.ts index b8f21580b24ab..aca5f5d0b37b8 100644 --- a/x-pack/examples/third_party_lens_navigation_prompt/public/plugin.ts +++ b/x-pack/examples/third_party_lens_navigation_prompt/public/plugin.ts @@ -10,7 +10,6 @@ import { Plugin, CoreSetup, AppNavLinkStatus } from '@kbn/core/public'; import { DataViewsPublicPluginStart, DataView } from '@kbn/data-views-plugin/public'; import { DateHistogramIndexPatternColumn, - IndexPatternPersistedState, LensPublicSetup, LensPublicStart, } from '@kbn/lens-plugin/public'; @@ -131,54 +130,20 @@ export class EmbeddedLensExamplePlugin ], }); - lens.registerTopNavMenuEntryGenerator( - ({ visualizationId, visualizationState, datasourceStates, query, filters }) => { - if (!datasourceStates.indexpattern.state || !visualizationState) return; + lens.registerTopNavMenuEntryGenerator(({ currentDoc }) => { + if (!currentDoc) return; - return { - label: 'Debug in Playground', - iconType: 'wrench', - run: async () => { - const [coreStart] = await core.getStartServices(); - const datasourceState = datasourceStates.indexpattern - .state as IndexPatternPersistedState; - const layersIds = Object.keys(datasourceState.layers); - const layers = Object.values(datasourceState.layers) as Array< - PersistedIndexPatternLayer & { indexPatternId: string } - >; - const serializedFilters = JSON.parse(JSON.stringify(filters)); - coreStart.application.navigateToApp('testing_embedded_lens', { - state: { - visualizationType: visualizationId, - title: 'Lens visualization', - references: [ - { - id: layers[0].indexPatternId, - name: 'indexpattern-datasource-current-indexpattern', - type: 'index-pattern', - }, - ...layers.map(({ indexPatternId }, i) => ({ - id: indexPatternId, - name: `indexpattern-datasource-layer-${layersIds[i]}`, - type: 'index-pattern', - })), - ], - state: { - datasourceStates: { - indexpattern: { - layers: datasourceState.layers, - }, - }, - visualization: visualizationState, - filters: serializedFilters, - query, - }, - }, - }); - }, - }; - } - ); + return { + label: 'Debug in Playground', + iconType: 'wrench', + run: async () => { + const [coreStart] = await core.getStartServices(); + coreStart.application.navigateToApp('testing_embedded_lens', { + state: { ...currentDoc, savedObjectId: undefined }, + }); + }, + }; + }); } public start() {} diff --git a/x-pack/plugins/lens/public/app_plugin/app.tsx b/x-pack/plugins/lens/public/app_plugin/app.tsx index da8549fef03e4..31b777c904c8c 100644 --- a/x-pack/plugins/lens/public/app_plugin/app.tsx +++ b/x-pack/plugins/lens/public/app_plugin/app.tsx @@ -402,6 +402,7 @@ export function App({ datasourceMap={datasourceMap} title={persistedDoc?.title} lensInspector={lensInspector} + currentDoc={currentDoc} goBackToOriginatingApp={goBackToOriginatingApp} contextOriginatingApp={contextOriginatingApp} initialContextIsEmbedded={initialContextIsEmbedded} diff --git a/x-pack/plugins/lens/public/app_plugin/lens_top_nav.tsx b/x-pack/plugins/lens/public/app_plugin/lens_top_nav.tsx index 582ee5327b1a7..a32cc5c4a532b 100644 --- a/x-pack/plugins/lens/public/app_plugin/lens_top_nav.tsx +++ b/x-pack/plugins/lens/public/app_plugin/lens_top_nav.tsx @@ -218,6 +218,7 @@ export const LensTopNavMenu = ({ initialContext, theme$, indexPatternService, + currentDoc, }: LensTopNavMenuProps) => { const { data, @@ -377,6 +378,7 @@ export const LensTopNavMenu = ({ query, filters, initialContext, + currentDoc, }); return menuEntry ? [menuEntry] : []; }); @@ -391,6 +393,7 @@ export const LensTopNavMenu = ({ query, filters, initialContext, + currentDoc, ]); const layerMetaInfo = useMemo(() => { diff --git a/x-pack/plugins/lens/public/app_plugin/types.ts b/x-pack/plugins/lens/public/app_plugin/types.ts index 65ceea382201c..52fe1aa98c500 100644 --- a/x-pack/plugins/lens/public/app_plugin/types.ts +++ b/x-pack/plugins/lens/public/app_plugin/types.ts @@ -53,6 +53,7 @@ import type { LensAttributeService } from '../lens_attribute_service'; import type { LensEmbeddableInput } from '../embeddable/embeddable'; import type { LensInspector } from '../lens_inspector_service'; import { IndexPatternServiceAPI } from '../indexpattern_service/service'; +import { Document } from '../persistence/saved_object_store'; export interface RedirectToOriginProps { input?: LensEmbeddableInput; @@ -112,6 +113,7 @@ export interface LensTopNavMenuProps { initialContextIsEmbedded?: boolean; topNavMenuEntryGenerators: LensTopNavMenuEntryGenerator[]; initialContext?: VisualizeFieldContext | VisualizeEditorContext; + currentDoc: Document | undefined; theme$: Observable; indexPatternService: IndexPatternServiceAPI; } diff --git a/x-pack/plugins/lens/public/types.ts b/x-pack/plugins/lens/public/types.ts index a5a032f0f6852..8fbfe35e975de 100644 --- a/x-pack/plugins/lens/public/types.ts +++ b/x-pack/plugins/lens/public/types.ts @@ -47,6 +47,7 @@ import type { LensInspector } from './lens_inspector_service'; import type { FormatSelectorOptions } from './indexpattern_datasource/dimension_panel/format_selector'; import type { DataViewsState } from './state_management/types'; import type { IndexPatternServiceAPI } from './indexpattern_service/service'; +import type { Document } from './persistence/saved_object_store'; export interface IndexPatternRef { id: string; @@ -1191,4 +1192,5 @@ export type LensTopNavMenuEntryGenerator = (props: { query: Query; filters: Filter[]; initialContext?: VisualizeFieldContext | VisualizeEditorContext; + currentDoc: Document | undefined; }) => undefined | TopNavMenuData;