catalog: remove EntityLoaderProvider and deprecate Router

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-09-11 14:14:50 +02:00
parent ea81a1f19c
commit e95b379d5f
6 changed files with 27 additions and 59 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog': patch
---
Deprecated `Router` in favor of using the plugin extensions.
+1 -1
View File
@@ -401,7 +401,7 @@ export const isOrphan: (entity: Entity) => boolean;
// Warning: (ae-missing-release-tag) "Router" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
// @public @deprecated (undocumented)
export const Router: ({
EntityPage,
}: {
@@ -16,12 +16,13 @@
import React from 'react';
import { Outlet } from 'react-router';
import { EntityLoaderProvider } from '../EntityLoaderProvider';
import {
useEntityFromUrl,
AsyncEntityProvider,
} from '@backstage/plugin-catalog-react';
export const CatalogEntityPage = () => {
return (
<EntityLoaderProvider>
<Outlet />
</EntityLoaderProvider>
);
};
export const CatalogEntityPage = () => (
<AsyncEntityProvider {...useEntityFromUrl()}>
<Outlet />
</AsyncEntityProvider>
);
@@ -1,30 +0,0 @@
/*
* Copyright 2020 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
EntityContext,
useEntityFromUrl,
} from '@backstage/plugin-catalog-react';
import React, { ReactNode } from 'react';
export const EntityLoaderProvider = ({ children }: { children: ReactNode }) => {
const { entity, loading, error, refresh } = useEntityFromUrl();
return (
<EntityContext.Provider value={{ entity, loading, error, refresh }}>
{children}
</EntityContext.Provider>
);
};
@@ -1,16 +0,0 @@
/*
* Copyright 2020 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { EntityLoaderProvider } from './EntityLoaderProvider';
+12 -4
View File
@@ -15,15 +15,16 @@
*/
import { ENTITY_DEFAULT_NAMESPACE } from '@backstage/catalog-model';
import {
AsyncEntityProvider,
entityRoute,
rootRoute,
useEntity,
useEntityFromUrl,
} from '@backstage/plugin-catalog-react';
import { Link, Typography } from '@material-ui/core';
import React, { ComponentType } from 'react';
import React, { ComponentType, ReactNode } from 'react';
import { Navigate, Route, Routes, useParams } from 'react-router';
import { CatalogPage } from './CatalogPage';
import { EntityLoaderProvider } from './EntityLoaderProvider';
import { EntityNotFound } from './EntityNotFound';
import { EntityPageLayout } from './EntityPageLayout';
import { Content } from '@backstage/core-components';
@@ -73,6 +74,13 @@ const OldEntityRouteRedirect = () => {
);
};
export const EntityLoader = (props: { children: ReactNode }) => (
<AsyncEntityProvider {...useEntityFromUrl()} {...props} />
);
/**
* @deprecated Use plugin extensions instead
* */
export const Router = ({
EntityPage = DefaultEntityPage,
}: {
@@ -83,9 +91,9 @@ export const Router = ({
<Route
path={`${entityRoute.path}`}
element={
<EntityLoaderProvider>
<EntityLoader>
<EntityPageSwitch EntityPage={EntityPage} />
</EntityLoaderProvider>
</EntityLoader>
}
/>
<Route