added support for a custom component when entity not found

Signed-off-by: shahar.shmaram <shahar.shmaram@appsflyer.com>
This commit is contained in:
shahar.shmaram
2022-04-23 00:18:45 +03:00
parent 0cd4f041b7
commit ceca63d149
2 changed files with 34 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog': minor
---
Added the prop `NotFoundComponent` to `EntityLayout` which can be used to include a custom component when an entity is not found in the catalog
@@ -106,7 +106,7 @@ describe('EntityLayout', () => {
expect(rendered.getByText('tabbed-test-content')).toBeInTheDocument();
});
it('renders error message when entity is not found', async () => {
it('renders default error message when entity is not found', async () => {
const rendered = await renderInTestApp(
<ApiProvider apis={mockApis}>
<AsyncEntityProvider loading={false}>
@@ -130,6 +130,34 @@ describe('EntityLayout', () => {
expect(rendered.queryByText('tabbed-test-content')).not.toBeInTheDocument();
});
it('renders custom message when entity is not found', async () => {
const rendered = await renderInTestApp(
<ApiProvider apis={mockApis}>
<AsyncEntityProvider loading={false}>
<EntityLayout
NotFoundComponent={<div>Oppps.. Your entity was not found</div>}
>
<EntityLayout.Route path="/" title="tabbed-test-title">
<div>tabbed-test-content</div>
</EntityLayout.Route>
</EntityLayout>
</AsyncEntityProvider>
</ApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
},
);
expect(
rendered.getByText('Oppps.. Your entity was not found'),
).toBeInTheDocument();
expect(rendered.queryByText('my-entity')).not.toBeInTheDocument();
expect(rendered.queryByText('tabbed-test-title')).not.toBeInTheDocument();
expect(rendered.queryByText('tabbed-test-content')).not.toBeInTheDocument();
});
it('navigates when user clicks different tab', async () => {
const rendered = await renderInTestApp(
<Routes>