Skip to content

Commit

Permalink
Add Spaces column to Dashboard listing
Browse files Browse the repository at this point in the history
  • Loading branch information
nickpeihl committed Nov 2, 2023
1 parent 40cbf70 commit 9772e65
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 41 deletions.
36 changes: 23 additions & 13 deletions src/plugins/dashboard/public/dashboard_app/dashboard_router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -44,6 +45,8 @@ export const dashboardUrlParams = {
hideFilterBar: 'hide-filter-bar',
};

const getEmptyFunctionComponent: React.FC<SpacesContextProps> = ({ children }) => <>{children}</>;

export interface DashboardMountProps {
appUnMounted: () => void;
element: AppMountParameters['element'];
Expand All @@ -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;
Expand Down Expand Up @@ -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 = (
<I18nProvider>
<DashboardMountContext.Provider value={mountContext}>
<KibanaThemeProvider theme$={core.theme.theme$}>
<HashRouter>
<Routes>
<Route
path={[CREATE_NEW_DASHBOARD_URL, `${VIEW_DASHBOARD_URL}/:id`]}
render={renderDashboard}
/>
<Route exact path={LANDING_PAGE_PATH} render={renderListingPage} />
<Route exact path="/">
<Redirect to={LANDING_PAGE_PATH} />
</Route>
<Route render={renderNoMatch} />
</Routes>
</HashRouter>
<SpacesContextWrapper feature={DASHBOARD_APP_ID}>
<HashRouter>
<Routes>
<Route
path={[CREATE_NEW_DASHBOARD_URL, `${VIEW_DASHBOARD_URL}/:id`]}
render={renderDashboard}
/>
<Route exact path={LANDING_PAGE_PATH} render={renderListingPage} />
<Route exact path="/">
<Redirect to={LANDING_PAGE_PATH} />
</Route>
<Route render={renderNoMatch} />
</Routes>
</HashRouter>
</SpacesContextWrapper>
</KibanaThemeProvider>
</DashboardMountContext.Provider>
</I18nProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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.
}
Expand All @@ -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 };
};
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const DashboardListing = ({
chrome: { theme },
savedObjectsTagging,
coreContext: { executionContext },
spaces: { spacesApi },
} = pluginServices.getServices();

useExecutionContext(executionContext, {
Expand Down Expand Up @@ -78,6 +79,7 @@ export const DashboardListing = ({
},
toMountPoint,
savedObjectsTagging: savedObjectsTaggingFakePlugin,
spacesApi,
FormattedRelative,
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const toTableListViewSavedObject = (hit: DashboardItem): DashboardSavedObjectUse
updatedAt: hit.updatedAt!,
references: hit.references,
managed: hit.managed,
namespaces: hit.namespaces!,
attributes: {
title,
description,
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/dashboard/public/services/spaces/spaces.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};
16 changes: 2 additions & 14 deletions src/plugins/dashboard/public/services/spaces/spaces_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};
8 changes: 2 additions & 6 deletions src/plugins/dashboard/public/services/spaces/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 9772e65

Please sign in to comment.