From a92e483f925db4588fec8466ade962371241bef9 Mon Sep 17 00:00:00 2001 From: Ashwin P Chandran Date: Thu, 24 Aug 2023 11:11:21 +0000 Subject: [PATCH] PR comment fixes Signed-off-by: Ashwin P Chandran --- .../__snapshots__/app_container.test.tsx.snap | 13 ++++++ .../public/components/app_container.test.tsx | 40 +++++++++---------- .../public/components/no_view.tsx | 12 +++++- src/plugins/data_explorer/public/plugin.ts | 9 ----- .../services/view_service/view_service.ts | 6 +-- .../public/utils/state_management/preload.ts | 23 ++++++----- src/plugins/discover/public/plugin.ts | 9 ----- 7 files changed, 59 insertions(+), 53 deletions(-) create mode 100644 src/plugins/data_explorer/public/components/__snapshots__/app_container.test.tsx.snap diff --git a/src/plugins/data_explorer/public/components/__snapshots__/app_container.test.tsx.snap b/src/plugins/data_explorer/public/components/__snapshots__/app_container.test.tsx.snap new file mode 100644 index 000000000000..29b8e5ab54e9 --- /dev/null +++ b/src/plugins/data_explorer/public/components/__snapshots__/app_container.test.tsx.snap @@ -0,0 +1,13 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`DataExplorerApp should render the canvas and panel when selected 1`] = ` +
+
+
+ Context +
+
+
+`; diff --git a/src/plugins/data_explorer/public/components/app_container.test.tsx b/src/plugins/data_explorer/public/components/app_container.test.tsx index d4215f24e795..14175369490c 100644 --- a/src/plugins/data_explorer/public/components/app_container.test.tsx +++ b/src/plugins/data_explorer/public/components/app_container.test.tsx @@ -5,9 +5,9 @@ import React from 'react'; import { AppContainer } from './app_container'; -import { render } from '@testing-library/react'; import { View } from '../services/view_service/view'; -import { ViewMountParameters } from '../services/view_service'; +import { AppMountParameters } from '../../../../core/public'; +import { render } from 'test_utils/testing_lib_helpers'; describe('DataExplorerApp', () => { const createView = () => { @@ -16,32 +16,30 @@ describe('DataExplorerApp', () => { title: 'Test View', defaultPath: '/test-path', appExtentions: {} as any, - mount: async ({ canvasElement, panelElement }: ViewMountParameters) => { - const canvasContent = document.createElement('div'); - const panelContent = document.createElement('div'); - canvasContent.innerHTML = 'canvas-content'; - panelContent.innerHTML = 'panel-content'; - canvasElement.appendChild(canvasContent); - panelElement.appendChild(panelContent); - return () => { - canvasContent.remove(); - panelContent.remove(); - }; - }, + Canvas: (() =>
canvas
) as any, + Panel: (() =>
panel
) as any, + Context: (() =>
Context
) as any, }); }; + const params: AppMountParameters = { + element: document.createElement('div'), + history: {} as any, + onAppLeave: jest.fn(), + setHeaderActionMenu: jest.fn(), + appBasePath: '', + }; + it('should render NoView when a non existent view is selected', () => { - const { container } = render(); + const { container } = render(); expect(container).toContainHTML('View not found'); }); - // TODO: Complete once state management is in place - // it('should render the canvas and panel when selected', () => { - // const view = createView(); - // const { container } = render(); + it('should render the canvas and panel when selected', () => { + const view = createView(); + const { container } = render(); - // expect(container).toMatchSnapshot(); - // }); + expect(container).toMatchSnapshot(); + }); }); diff --git a/src/plugins/data_explorer/public/components/no_view.tsx b/src/plugins/data_explorer/public/components/no_view.tsx index 4cf7e84d9735..a341e9d0564e 100644 --- a/src/plugins/data_explorer/public/components/no_view.tsx +++ b/src/plugins/data_explorer/public/components/no_view.tsx @@ -5,6 +5,7 @@ import React from 'react'; import { EuiPageTemplate, EuiEmptyPrompt } from '@elastic/eui'; +import { FormattedMessage } from '@osd/i18n/react'; export const NoView = () => { return ( @@ -20,10 +21,17 @@ export const NoView = () => { View not found} + title={ +

+ +

+ } body={

- The view you are trying to access does not exist. Please check the URL and try again. +

} /> diff --git a/src/plugins/data_explorer/public/plugin.ts b/src/plugins/data_explorer/public/plugin.ts index 5935ceb44d80..3b953567fbe8 100644 --- a/src/plugins/data_explorer/public/plugin.ts +++ b/src/plugins/data_explorer/public/plugin.ts @@ -49,9 +49,6 @@ export class DataExplorerPlugin { data }: DataExplorerPluginSetupDependencies ): DataExplorerPluginSetup { const viewService = this.viewService; - // TODO: Remove this before merge to main - // eslint-disable-next-line no-console - console.log('data_explorer: Setup'); const { appMounted, appUnMounted, stop: stopUrlTracker } = createOsdUrlTracker({ baseUrl: core.http.basePath.prepend(`/app/${PLUGIN_ID}`), @@ -87,9 +84,6 @@ export class DataExplorerPlugin title: PLUGIN_NAME, navLinkStatus: AppNavLinkStatus.hidden, mount: async (params: AppMountParameters) => { - // TODO: Remove this before merge to main - // eslint-disable-next-line no-console - console.log('data_explorer: Mounted'); // Load application bundle const { renderApp } = await import('./application'); @@ -135,9 +129,6 @@ export class DataExplorerPlugin } public start(core: CoreStart): DataExplorerPluginStart { - // TODO: Remove this before merge to main - // eslint-disable-next-line no-console - console.log('data_explorer: Started'); return {}; } diff --git a/src/plugins/data_explorer/public/services/view_service/view_service.ts b/src/plugins/data_explorer/public/services/view_service/view_service.ts index 02d30d838e42..0ee131df0665 100644 --- a/src/plugins/data_explorer/public/services/view_service/view_service.ts +++ b/src/plugins/data_explorer/public/services/view_service/view_service.ts @@ -41,8 +41,8 @@ export class ViewService implements CoreService = {}; private registerView(view: View) { - if (this.views[view.id]) { - throw new Error(`A view with this the id ${view.id} already exists!`); + if (view.id in this.views) { + throw new Error(`A view with the id ${view.id} already exists!`); } this.views[view.id] = view; } @@ -73,7 +73,7 @@ export class ViewService implements CoreService { - return [...Object.values(this.views)]; + return Object.values(this.views); }, }; } diff --git a/src/plugins/data_explorer/public/utils/state_management/preload.ts b/src/plugins/data_explorer/public/utils/state_management/preload.ts index 3dd179ed6432..fe5c23bd366c 100644 --- a/src/plugins/data_explorer/public/utils/state_management/preload.ts +++ b/src/plugins/data_explorer/public/utils/state_management/preload.ts @@ -24,16 +24,21 @@ export const getPreloadedState = async ( const { defaults } = view.ui; - // defaults can be a function or an object - const preloadedState = typeof defaults === 'function' ? await defaults() : defaults; - rootState[view.id] = preloadedState.state; + try { + // defaults can be a function or an object + const preloadedState = typeof defaults === 'function' ? await defaults() : defaults; + rootState[view.id] = preloadedState.state; - // if the view wants to override the root state, we do that here - if (preloadedState.root) { - rootState = { - ...rootState, - ...preloadedState.root, - }; + // if the view wants to override the root state, we do that here + if (preloadedState.root) { + rootState = { + ...rootState, + ...preloadedState.root, + }; + } + } catch (e) { + // eslint-disable-next-line no-console + console.error(`Error initializing view ${view.id}: ${e}`); } }); await Promise.all(promises); diff --git a/src/plugins/discover/public/plugin.ts b/src/plugins/discover/public/plugin.ts index 8a581a3d246f..16774500d00c 100644 --- a/src/plugins/discover/public/plugin.ts +++ b/src/plugins/discover/public/plugin.ts @@ -162,9 +162,6 @@ export class DiscoverPlugin private initializeServices?: () => { core: CoreStart; plugins: DiscoverStartPlugins }; setup(core: CoreSetup, plugins: DiscoverSetupPlugins) { - // TODO: Remove this before merge to main - // eslint-disable-next-line no-console - console.log('DiscoverPlugin.setup()'); const baseUrl = core.http.basePath.prepend('/app/discover'); if (plugins.share) { @@ -249,9 +246,6 @@ export class DiscoverPlugin defaultPath: '#/', category: DEFAULT_APP_CATEGORIES.opensearchDashboards, mount: async (params: AppMountParameters) => { - // TODO: Remove this before merge to main - // eslint-disable-next-line no-console - console.log('DiscoverPlugin.mount()'); if (!this.initializeServices) { throw Error('Discover plugin method initializeServices is undefined'); } @@ -352,9 +346,6 @@ export class DiscoverPlugin } start(core: CoreStart, plugins: DiscoverStartPlugins) { - // TODO: Remove this before merge to main - // eslint-disable-next-line no-console - console.log('DiscoverPlugin.start()'); setUiActions(plugins.uiActions); this.initializeServices = () => {