Skip to content

Commit

Permalink
improve "debug in sandbox" functionality (elastic#139724)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored and Mpdreamz committed Sep 6, 2022
1 parent 4252c80 commit a1560e1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 48 deletions.
61 changes: 13 additions & 48 deletions x-pack/examples/third_party_lens_navigation_prompt/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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() {}
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/lens/public/app_plugin/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ export function App({
datasourceMap={datasourceMap}
title={persistedDoc?.title}
lensInspector={lensInspector}
currentDoc={currentDoc}
goBackToOriginatingApp={goBackToOriginatingApp}
contextOriginatingApp={contextOriginatingApp}
initialContextIsEmbedded={initialContextIsEmbedded}
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/lens/public/app_plugin/lens_top_nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ export const LensTopNavMenu = ({
initialContext,
theme$,
indexPatternService,
currentDoc,
}: LensTopNavMenuProps) => {
const {
data,
Expand Down Expand Up @@ -377,6 +378,7 @@ export const LensTopNavMenu = ({
query,
filters,
initialContext,
currentDoc,
});
return menuEntry ? [menuEntry] : [];
});
Expand All @@ -391,6 +393,7 @@ export const LensTopNavMenu = ({
query,
filters,
initialContext,
currentDoc,
]);

const layerMetaInfo = useMemo(() => {
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/lens/public/app_plugin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -112,6 +113,7 @@ export interface LensTopNavMenuProps {
initialContextIsEmbedded?: boolean;
topNavMenuEntryGenerators: LensTopNavMenuEntryGenerator[];
initialContext?: VisualizeFieldContext | VisualizeEditorContext;
currentDoc: Document | undefined;
theme$: Observable<CoreTheme>;
indexPatternService: IndexPatternServiceAPI;
}
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/lens/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1191,4 +1192,5 @@ export type LensTopNavMenuEntryGenerator = (props: {
query: Query;
filters: Filter[];
initialContext?: VisualizeFieldContext | VisualizeEditorContext;
currentDoc: Document | undefined;
}) => undefined | TopNavMenuData;

0 comments on commit a1560e1

Please sign in to comment.