Skip to content

Commit

Permalink
feat(app): Support extensible entity tabs
Browse files Browse the repository at this point in the history
This commit adds the ability to customize and extend the default set of
tabs available for catalog entity items.  The default set of tabs is
hard-coded in the entity page but can be reconfigured and extended per
plugin using the `entityTabs` property.  If multiple plugins target the
same entity route, only the first one will be used and a warning will be
raised.

Signed-off-by: Stan Lewis <[email protected]>
  • Loading branch information
gashcrumb committed Apr 16, 2024
1 parent f1395a9 commit 37c1859
Show file tree
Hide file tree
Showing 22 changed files with 1,078 additions and 820 deletions.
5 changes: 5 additions & 0 deletions packages/app/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export interface Config {
};
}[];
};
entityTabs?: {
path: string;
title: string;
mountPoint: string;
}[];
mountPoints?: {
mountPoint: string;
module?: string;
Expand Down
10 changes: 5 additions & 5 deletions packages/app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ import React from 'react';
import { apis } from './apis';
import DynamicRoot from './components/DynamicRoot';

// Statically integrated frontend plugins
const { dynamicPluginsInfoPlugin, ...dynamicPluginsInfoPluginModule } =
await import('@internal/plugin-dynamic-plugins-info');

// The base UI configuration, these values can be overridden by values
// specified in external configuration files
const baseFrontendConfig = {
export const baseFrontendConfig = {
context: 'frontend',
data: {
dynamicPlugins: {
Expand All @@ -35,6 +31,10 @@ const baseFrontendConfig = {
},
};

// Statically integrated frontend plugins
const { dynamicPluginsInfoPlugin, ...dynamicPluginsInfoPluginModule } =
await import('@internal/plugin-dynamic-plugins-info');

// The map of static plugins by package name
const staticPluginMap = {
'@internal/plugin-dynamic-plugins-info': {
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/components/AppBase/AppBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { LearningPaths } from '../learningPaths/LearningPathsPage';
import { SearchPage } from '../search/SearchPage';

const AppBase = () => {
const { AppProvider, AppRouter, dynamicRoutes } =
const { AppProvider, AppRouter, dynamicRoutes, entityTabs } =
useContext(DynamicRootContext);
return (
<AppProvider>
Expand All @@ -41,7 +41,7 @@ const AppBase = () => {
path="/catalog/:namespace/:kind/:name"
element={<CatalogEntityPage />}
>
{entityPage}
{entityPage(entityTabs)}
</Route>
<Route
path="/create"
Expand Down
91 changes: 63 additions & 28 deletions packages/app/src/components/DynamicRoot/DynamicRoot.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
} from '@backstage/core-plugin-api';
import { Entity } from '@backstage/catalog-model';
import * as appDefaults from '@backstage/app-defaults';
import { AppRouteBinder } from '@backstage/core-app-api';
import { AppRouteBinder, defaultConfigLoader } from '@backstage/core-app-api';
import { AppConfig } from '@backstage/config';

const DynamicRoot = React.lazy(() => import('./DynamicRoot'));

Expand Down Expand Up @@ -67,7 +68,9 @@ const MockPage = () => {
);
};

const MockApp = () => (
const loadAppConfig = async () => await defaultConfigLoader();

const MockApp = ({ appConfig }: { appConfig: AppConfig[] }) => (
<React.Suspense fallback={null}>
<DynamicRoot
apis={[]}
Expand All @@ -78,6 +81,12 @@ const MockApp = () => (
},
})
}
appConfig={appConfig}
baseFrontendConfig={{
context: '',
data: {},
}}
scalprumConfig={{}}
/>
</React.Suspense>
);
Expand Down Expand Up @@ -184,7 +193,8 @@ describe('DynamicRoot', () => {
process.env = mockProcessEnv({
'foo.bar': { dynamicRoutes: [{ path: '/foo' }] },
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -198,7 +208,8 @@ describe('DynamicRoot', () => {
process.env = mockProcessEnv({
'foo.bar': { dynamicRoutes: [{ path: '/foo' }, { path: '/bar' }] },
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -212,7 +223,8 @@ describe('DynamicRoot', () => {
process.env = mockProcessEnv({
'doesnt.exist': { dynamicRoutes: [{ path: '/foo' }] },
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -231,7 +243,8 @@ describe('DynamicRoot', () => {
dynamicRoutes: [{ path: '/foo', importName: 'BarComponent' }],
},
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -248,7 +261,8 @@ describe('DynamicRoot', () => {
process.env = mockProcessEnv({
'foo.bar': { dynamicRoutes: [{ path: '/foo', module: 'BarPlugin' }] },
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -269,7 +283,8 @@ describe('DynamicRoot', () => {
],
},
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -285,7 +300,8 @@ describe('DynamicRoot', () => {
process.env = mockProcessEnv({
'foo.bar': { mountPoints: [{ mountPoint: 'a.b.c/cards' }] },
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -304,7 +320,8 @@ describe('DynamicRoot', () => {
],
},
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -323,7 +340,8 @@ describe('DynamicRoot', () => {
],
},
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -347,7 +365,8 @@ describe('DynamicRoot', () => {
],
},
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -370,7 +389,8 @@ describe('DynamicRoot', () => {
],
},
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -393,7 +413,8 @@ describe('DynamicRoot', () => {
],
},
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -414,7 +435,8 @@ describe('DynamicRoot', () => {
],
},
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -430,7 +452,8 @@ describe('DynamicRoot', () => {
process.env = mockProcessEnv({
'doesnt.exist': { mountPoints: [{ mountPoint: 'a.b.c/cards' }] },
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -451,7 +474,8 @@ describe('DynamicRoot', () => {
],
},
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -470,7 +494,8 @@ describe('DynamicRoot', () => {
mountPoints: [{ mountPoint: 'a.b.c/cards', module: 'BarPlugin' }],
},
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -494,7 +519,8 @@ describe('DynamicRoot', () => {
],
},
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -510,7 +536,8 @@ describe('DynamicRoot', () => {
process.env = mockProcessEnv({
'foo.bar': { appIcons: [{ name: 'fooIcon' }] },
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -524,7 +551,8 @@ describe('DynamicRoot', () => {
process.env = mockProcessEnv({
'foo.bar': { appIcons: [{ name: 'fooIcon' }, { name: 'foo2Icon' }] },
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -541,7 +569,8 @@ describe('DynamicRoot', () => {
process.env = mockProcessEnv({
'doesnt.exist': { appIcons: [{ name: 'fooIcon' }] },
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand Down Expand Up @@ -572,7 +601,8 @@ describe('DynamicRoot', () => {
},
},
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand Down Expand Up @@ -612,7 +642,8 @@ describe('DynamicRoot', () => {
},
},
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand Down Expand Up @@ -650,7 +681,8 @@ describe('DynamicRoot', () => {
},
},
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -667,7 +699,8 @@ describe('DynamicRoot', () => {
apiFactories: [{ importName: 'fooPluginApi' }],
},
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -687,7 +720,8 @@ describe('DynamicRoot', () => {
apiFactories: [{ importName: 'barPluginApi' }],
},
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand All @@ -706,7 +740,8 @@ describe('DynamicRoot', () => {
apiFactories: [{ importName: 'fooPluginApi', module: 'BarPlugin' }],
},
});
const rendered = await renderWithEffects(<MockApp />);
const appConfig = await loadAppConfig();
const rendered = await renderWithEffects(<MockApp appConfig={appConfig} />);
await waitFor(async () => {
expect(rendered.baseElement).toBeInTheDocument();
expect(rendered.getByTestId('isLoadingFinished')).toBeInTheDocument();
Expand Down
Loading

0 comments on commit 37c1859

Please sign in to comment.