Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens][Inspector] Close the inspector on Lens unmount #114317

Merged
merged 5 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/app_plugin/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ describe('Lens App', () => {

await runInspect(instance);

expect(services.inspector.open).toHaveBeenCalledTimes(1);
expect(services.inspector.inspect).toHaveBeenCalledTimes(1);
});
});

Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/lens/public/app_plugin/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
getLastKnownDocWithoutPinnedFilters,
runSaveLensVisualization,
} from './save_modal_container';
import { getLensInspectorService, LensInspector } from '../lens_inspector_service';
import { LensInspector } from '../lens_inspector_service';
import { getEditPath } from '../../common';

export type SaveProps = Omit<OnSaveProps, 'onTitleDuplicate' | 'newDescription'> & {
Expand Down Expand Up @@ -101,7 +101,7 @@ export function App({
const [isSaveModalVisible, setIsSaveModalVisible] = useState(false);
const [lastKnownDoc, setLastKnownDoc] = useState<Document | undefined>(undefined);

const lensInspector = getLensInspectorService(inspector);
const lensInspector = inspector;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: what if instead we do in line 65

const {
    data,
    chrome,
    uiSettings,
    inspector: lensInspector,
    application,
    notifications,
    savedObjectsTagging,
    getOriginatingAppName,
    spaces,
    http,
    // Temporarily required until the 'by value' paradigm is default.
    dashboardFeatureFlag,
  } = lensAppServices;


useEffect(() => {
if (currentDoc) {
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/lens/public/app_plugin/mounter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
LensState,
} from '../state_management';
import { getPreloadedState } from '../state_management/lens_slice';
import { getLensInspectorService } from '../lens_inspector_service';

export async function getLensServices(
coreStart: CoreStart,
Expand All @@ -65,7 +66,7 @@ export async function getLensServices(
return {
data,
storage,
inspector,
inspector: getLensInspectorService(inspector),
navigation,
fieldFormats,
stateTransfer,
Expand Down Expand Up @@ -278,6 +279,7 @@ export async function mountApp(
return () => {
data.search.session.clear();
unmountComponentAtNode(params.element);
lensServices.inspector.close();
unlistenParentHistory();
lensStore.dispatch(navigateAway());
};
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/lens/public/app_plugin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import type {
import type { DataPublicPluginStart } from '../../../../../src/plugins/data/public';
import type { UsageCollectionStart } from '../../../../../src/plugins/usage_collection/public';
import type { DashboardStart } from '../../../../../src/plugins/dashboard/public';
import type { Start as InspectorStart } from '../../../../../src/plugins/inspector/public';
import type { LensEmbeddableInput } from '../embeddable/embeddable';
import type { NavigationPublicPluginStart } from '../../../../../src/plugins/navigation/public';
import type { LensAttributeService } from '../lens_attribute_service';
Expand Down Expand Up @@ -105,7 +104,7 @@ export interface LensAppServices {
dashboard: DashboardStart;
fieldFormats: FieldFormatsStart;
data: DataPublicPluginStart;
inspector: InspectorStart;
inspector: LensInspector;
uiSettings: IUiSettingsClient;
application: ApplicationStart;
notifications: NotificationsStart;
Expand Down
13 changes: 12 additions & 1 deletion x-pack/plugins/lens/public/lens_inspector_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,27 @@
import type {
Adapters,
InspectorOptions,
InspectorSession,
Start as InspectorStartContract,
} from '../../../../src/plugins/inspector/public';

import { createDefaultInspectorAdapters } from '../../../../src/plugins/expressions/public';

export const getLensInspectorService = (inspector: InspectorStartContract) => {
const adapters: Adapters = createDefaultInspectorAdapters();
let overlayRef: InspectorSession | undefined;
return {
adapters,
inspect: (options?: InspectorOptions) => inspector.open(adapters, options),
inspect: (options?: InspectorOptions) => {
overlayRef = inspector.open(adapters, options);
overlayRef.onClose.then(() => {
if (overlayRef) {
overlayRef = undefined;
}
});
return overlayRef;
},
close: () => overlayRef?.close(),
};
};

Expand Down
7 changes: 6 additions & 1 deletion x-pack/plugins/lens/public/mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
DatasourceMap,
VisualizationMap,
} from './types';
import { getLensInspectorService } from './lens_inspector_service';

export function mockDatasourceStates() {
return {
Expand Down Expand Up @@ -417,7 +418,11 @@ export function makeDefaultServices(
navigation: navigationStartMock,
notifications: core.notifications,
attributeService: makeAttributeService(),
inspector: inspectorPluginMock.createStartContract(),
inspector: {
adapters: getLensInspectorService(inspectorPluginMock.createStartContract()).adapters,
inspect: jest.fn(),
close: jest.fn(),
},
dashboard: dashboardPluginMock.createStartContract(),
presentationUtil: presentationUtilPluginMock.createStartContract(core),
savedObjectsClient: core.savedObjects.client,
Expand Down
6 changes: 6 additions & 0 deletions x-pack/test/functional/apps/lens/inspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const PageObjects = getPageObjects(['visualize', 'lens', 'common', 'header']);
const elasticChart = getService('elasticChart');
const inspector = getService('inspector');
const testSubjects = getService('testSubjects');

describe('lens inspector', () => {
before(async () => {
Expand Down Expand Up @@ -55,5 +56,10 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await inspector.openInspectorRequestsView();
expect(await inspector.getRequestNames()).to.be('Data,Other bucket');
});

it('should close the inspector when navigating away from Lens', async () => {
await PageObjects.visualize.navigateToNewVisualization();
expect(await testSubjects.exists('inspectorPanel')).to.be(false);
});
});
}