From 9772e65992dda0642471df24c052b0fd6793d2d9 Mon Sep 17 00:00:00 2001 From: Nick Peihl Date: Thu, 2 Nov 2023 12:17:11 -0400 Subject: [PATCH] Add Spaces column to Dashboard listing --- .../public/dashboard_app/dashboard_router.tsx | 36 ++++++++++++------- .../use_dashboard_outcome_validation.tsx | 13 ++++--- .../dashboard_listing/dashboard_listing.tsx | 2 ++ .../hooks/use_dashboard_listing_table.tsx | 1 + .../public/services/spaces/spaces.stub.ts | 4 +-- .../public/services/spaces/spaces_service.ts | 16 ++------- .../dashboard/public/services/spaces/types.ts | 8 ++--- 7 files changed, 39 insertions(+), 41 deletions(-) diff --git a/src/plugins/dashboard/public/dashboard_app/dashboard_router.tsx b/src/plugins/dashboard/public/dashboard_app/dashboard_router.tsx index 2d479a8d9bf15..ccd2ca0eea0ca 100644 --- a/src/plugins/dashboard/public/dashboard_app/dashboard_router.tsx +++ b/src/plugins/dashboard/public/dashboard_app/dashboard_router.tsx @@ -15,6 +15,7 @@ import { HashRouter, RouteComponentProps, Redirect } from 'react-router-dom'; import { Routes, Route } from '@kbn/shared-ux-router'; import { I18nProvider } from '@kbn/i18n-react'; import { ViewMode } from '@kbn/embeddable-plugin/public'; +import { SpacesContextProps } from '@kbn/spaces-plugin/public'; import { AppMountParameters, CoreSetup } from '@kbn/core/public'; import { KibanaThemeProvider } from '@kbn/kibana-react-plugin/public'; import { createKbnUrlStateStorage, withNotifyOnErrors } from '@kbn/kibana-utils-plugin/public'; @@ -44,6 +45,8 @@ export const dashboardUrlParams = { hideFilterBar: 'hide-filter-bar', }; +const getEmptyFunctionComponent: React.FC = ({ children }) => <>{children}; + export interface DashboardMountProps { appUnMounted: () => void; element: AppMountParameters['element']; @@ -61,6 +64,7 @@ export async function mountApp({ core, element, appUnMounted, mountContext }: Da data: dataStart, notifications, embeddable, + spaces: { spacesApi }, } = pluginServices.getServices(); let globalEmbedSettings: DashboardEmbedSettings | undefined; @@ -144,23 +148,29 @@ export async function mountApp({ core, element, appUnMounted, mountContext }: Da window.dispatchEvent(new HashChangeEvent('hashchange')); }); + const SpacesContextWrapper = spacesApi + ? spacesApi.ui.components.getSpacesContextProvider + : getEmptyFunctionComponent; + const app = ( - - - - - - - - - - + + + + + + + + + + + + diff --git a/src/plugins/dashboard/public/dashboard_app/hooks/use_dashboard_outcome_validation.tsx b/src/plugins/dashboard/public/dashboard_app/hooks/use_dashboard_outcome_validation.tsx index 9d7017845d41e..e9219eb74f2eb 100644 --- a/src/plugins/dashboard/public/dashboard_app/hooks/use_dashboard_outcome_validation.tsx +++ b/src/plugins/dashboard/public/dashboard_app/hooks/use_dashboard_outcome_validation.tsx @@ -25,7 +25,10 @@ export const useDashboardOutcomeValidation = () => { /** * Unpack dashboard services */ - const { screenshotMode, spaces } = pluginServices.getServices(); + const { + screenshotMode, + spaces: { spacesApi }, + } = pluginServices.getServices(); const validateOutcome: DashboardCreationOptions['validateLoadedSavedObject'] = useCallback( ({ dashboardFound, resolveMeta, dashboardId }: LoadDashboardReturn) => { @@ -43,7 +46,7 @@ export const useDashboardOutcomeValidation = () => { if (screenshotMode.isScreenshotMode()) { scopedHistory.replace(path); // redirect without the toast when in screenshot mode. } else { - spaces.redirectLegacyUrl?.({ path, aliasPurpose }); + spacesApi?.ui.redirectLegacyUrl?.({ path, aliasPurpose }); } return 'redirected'; // redirected. Stop loading dashboard. } @@ -53,20 +56,20 @@ export const useDashboardOutcomeValidation = () => { } return 'valid'; }, - [scopedHistory, screenshotMode, spaces] + [scopedHistory, screenshotMode, spacesApi] ); const getLegacyConflictWarning = useMemo(() => { if (savedObjectId && outcome === 'conflict' && aliasId) { return () => - spaces.getLegacyUrlConflict?.({ + spacesApi?.ui.components?.getLegacyUrlConflict?.({ currentObjectId: savedObjectId, otherObjectId: aliasId, otherObjectPath: `#${createDashboardEditUrl(aliasId)}${scopedHistory.location.search}`, }); } return null; - }, [aliasId, outcome, savedObjectId, scopedHistory, spaces]); + }, [aliasId, outcome, savedObjectId, scopedHistory, spacesApi]); return { validateOutcome, getLegacyConflictWarning }; }; diff --git a/src/plugins/dashboard/public/dashboard_listing/dashboard_listing.tsx b/src/plugins/dashboard/public/dashboard_listing/dashboard_listing.tsx index 6d328fdc18e20..886a4979e5a45 100644 --- a/src/plugins/dashboard/public/dashboard_listing/dashboard_listing.tsx +++ b/src/plugins/dashboard/public/dashboard_listing/dashboard_listing.tsx @@ -42,6 +42,7 @@ export const DashboardListing = ({ chrome: { theme }, savedObjectsTagging, coreContext: { executionContext }, + spaces: { spacesApi }, } = pluginServices.getServices(); useExecutionContext(executionContext, { @@ -78,6 +79,7 @@ export const DashboardListing = ({ }, toMountPoint, savedObjectsTagging: savedObjectsTaggingFakePlugin, + spacesApi, FormattedRelative, }} > diff --git a/src/plugins/dashboard/public/dashboard_listing/hooks/use_dashboard_listing_table.tsx b/src/plugins/dashboard/public/dashboard_listing/hooks/use_dashboard_listing_table.tsx index 80b39ff0e9d62..7b7ad32e02add 100644 --- a/src/plugins/dashboard/public/dashboard_listing/hooks/use_dashboard_listing_table.tsx +++ b/src/plugins/dashboard/public/dashboard_listing/hooks/use_dashboard_listing_table.tsx @@ -44,6 +44,7 @@ const toTableListViewSavedObject = (hit: DashboardItem): DashboardSavedObjectUse updatedAt: hit.updatedAt!, references: hit.references, managed: hit.managed, + namespaces: hit.namespaces!, attributes: { title, description, diff --git a/src/plugins/dashboard/public/services/spaces/spaces.stub.ts b/src/plugins/dashboard/public/services/spaces/spaces.stub.ts index d89d5ea6b8356..a50fa503442f0 100644 --- a/src/plugins/dashboard/public/services/spaces/spaces.stub.ts +++ b/src/plugins/dashboard/public/services/spaces/spaces.stub.ts @@ -16,8 +16,6 @@ export const spacesServiceFactory: SpacesServiceFactory = () => { const pluginMock = spacesPluginMock.createStartContract(); return { - getActiveSpace$: pluginMock.getActiveSpace$, - getLegacyUrlConflict: pluginMock.ui.components.getLegacyUrlConflict, - redirectLegacyUrl: pluginMock.ui.redirectLegacyUrl, + spacesApi: pluginMock, }; }; diff --git a/src/plugins/dashboard/public/services/spaces/spaces_service.ts b/src/plugins/dashboard/public/services/spaces/spaces_service.ts index 1146ab0434373..f25f0c42e046f 100644 --- a/src/plugins/dashboard/public/services/spaces/spaces_service.ts +++ b/src/plugins/dashboard/public/services/spaces/spaces_service.ts @@ -16,21 +16,9 @@ export type SpacesServiceFactory = KibanaPluginServiceFactory< >; export const spacesServiceFactory: SpacesServiceFactory = ({ startPlugins }) => { const { spaces } = startPlugins; - if (!spaces || !spaces.ui) return {}; + if (!spaces) return {}; - const { - getActiveSpace$, - ui: { - components: { getLegacyUrlConflict, getSpacesContextProvider }, - redirectLegacyUrl, - useSpaces, - }, - } = spaces; return { - getActiveSpace$, - getLegacyUrlConflict, - getSpacesContextProvider, - redirectLegacyUrl, - useSpaces, + spacesApi: spaces, }; }; diff --git a/src/plugins/dashboard/public/services/spaces/types.ts b/src/plugins/dashboard/public/services/spaces/types.ts index fd324bb9f4773..3583304e5d13a 100644 --- a/src/plugins/dashboard/public/services/spaces/types.ts +++ b/src/plugins/dashboard/public/services/spaces/types.ts @@ -6,12 +6,8 @@ * Side Public License, v 1. */ -import type { SpacesPluginStart } from '@kbn/spaces-plugin/public'; +import type { SpacesApi } from '@kbn/spaces-plugin/public'; export interface DashboardSpacesService { - getActiveSpace$?: SpacesPluginStart['getActiveSpace$']; - getLegacyUrlConflict?: SpacesPluginStart['ui']['components']['getLegacyUrlConflict']; - getSpacesContextProvider?: SpacesPluginStart['ui']['components']['getSpacesContextProvider']; - redirectLegacyUrl?: SpacesPluginStart['ui']['redirectLegacyUrl']; - useSpaces?: SpacesPluginStart['ui']['useSpaces']; + spacesApi?: SpacesApi; }