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 30, 2024
1 parent 29cbbb8 commit 5a92f2b
Show file tree
Hide file tree
Showing 23 changed files with 1,089 additions and 815 deletions.
2 changes: 2 additions & 0 deletions .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# comma delimited path of files to exclude from copy/paste duplicate checking
sonar.cpd.exclusions=packages/app/src/components/catalog/EntityPage/defaultTabs.tsx
5 changes: 5 additions & 0 deletions packages/app/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ export interface Config {
};
}[];
};
entityTabs?: {
path: string;
title: string;
mountPoint: string;
}[];
mountPoints?: {
mountPoint: string;
module?: string;
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, entityTabOverrides } =
useContext(DynamicRootContext);
return (
<AppProvider>
Expand All @@ -41,7 +41,7 @@ const AppBase = () => {
path="/catalog/:namespace/:kind/:name"
element={<CatalogEntityPage />}
>
{entityPage}
{entityPage(entityTabOverrides)}
</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 5a92f2b

Please sign in to comment.