catalog-react: Remove EntityContext

Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
Johan Haals
2022-02-22 10:22:38 +01:00
parent 416032660b
commit 3334ad47d4
7 changed files with 18 additions and 87 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-react': minor
---
Removed the deprecated `EntityContext` which have been replaced by `useEntity`, `EntityProvider` and `AsyncEntityProvider`.
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog': patch
---
Removed usage of `EntityContext`.
-4
View File
@@ -11,7 +11,6 @@ import { CATALOG_FILTER_EXISTS } from '@backstage/catalog-client';
import { CatalogApi } from '@backstage/catalog-client';
import { ComponentEntity } from '@backstage/catalog-model';
import { ComponentProps } from 'react';
import { Context } from 'react';
import { Entity } from '@backstage/catalog-model';
import { EntityName } from '@backstage/catalog-model';
import { GetEntitiesResponse } from '@backstage/catalog-client';
@@ -151,9 +150,6 @@ export class DefaultStarredEntitiesApi implements StarredEntitiesApi {
toggleStarred(entityRef: string): Promise<void>;
}
// @public @deprecated (undocumented)
export const EntityContext: Context<EntityLoadingStatus>;
// @public (undocumented)
export type EntityFilter = {
getCatalogFilters?: () => Record<
-1
View File
@@ -14,7 +14,6 @@
* limitations under the License.
*/
export {
EntityContext,
useEntity,
useEntityFromUrl,
EntityProvider,
@@ -16,12 +16,7 @@
import React from 'react';
import { renderHook } from '@testing-library/react-hooks';
import {
useEntity,
EntityProvider,
AsyncEntityProvider,
EntityContext,
} from './useEntity';
import { useEntity, EntityProvider, AsyncEntityProvider } from './useEntity';
import { Entity } from '@backstage/catalog-model';
describe('EntityProvider', () => {
@@ -103,38 +98,3 @@ describe('AsyncEntityProvider', () => {
expect(result.current.refresh).toBe(undefined);
});
});
describe('EntityContext.Provider', () => {
it('should provide no entity', async () => {
const { result } = renderHook(() => useEntity(), {
wrapper: ({ children }) => (
<EntityContext.Provider
value={{ loading: false }}
children={children}
/>
),
});
expect(result.current.entity).toBe(undefined);
expect(result.current.loading).toBe(false);
expect(result.current.error).toBe(undefined);
expect(result.current.refresh).toBe(undefined);
});
it('should provide an entity', async () => {
const entity = { kind: 'MyEntity' } as Entity;
const { result } = renderHook(() => useEntity(), {
wrapper: ({ children }) => (
<EntityContext.Provider
value={{ entity, loading: false }}
children={children}
/>
),
});
expect(result.current.entity).toBe(entity);
expect(result.current.loading).toBe(false);
expect(result.current.error).toBe(undefined);
expect(result.current.refresh).toBe(undefined);
});
});
+4 -38
View File
@@ -20,13 +20,7 @@ import {
createVersionedValueMap,
useVersionedContext,
} from '@backstage/version-bridge';
import React, {
ReactNode,
useEffect,
createContext,
Provider,
Context,
} from 'react';
import React, { ReactNode, useEffect } from 'react';
import { useNavigate } from 'react-router';
import useAsyncRetry from 'react-use/lib/useAsyncRetry';
import { catalogApiRef } from '../api';
@@ -40,20 +34,6 @@ export type EntityLoadingStatus = {
refresh?: VoidFunction;
};
/**
* @public
* @deprecated use `useEntity` and `EntityProvider` or `AsyncEntityProvider` instead.
*/
export const EntityContext: Context<EntityLoadingStatus> =
createContext<EntityLoadingStatus>({
entity: undefined,
loading: true,
error: undefined,
refresh: () => {},
});
// We grab this for use in the new provider, since we're overriding it later on
const OldEntityProvider = EntityContext.Provider;
// This context has support for multiple concurrent versions of this package.
// It is currently used in parallel with the old context in order to provide
// a smooth transition, but will eventually be the only context we use.
@@ -89,11 +69,9 @@ export const AsyncEntityProvider = ({
// We provide both the old and the new context, since
// consumers might be doing things like `useContext(EntityContext)`
return (
<OldEntityProvider value={value}>
<NewEntityContext.Provider value={createVersionedValueMap({ 1: value })}>
{children}
</NewEntityContext.Provider>
</OldEntityProvider>
<NewEntityContext.Provider value={createVersionedValueMap({ 1: value })}>
{children}
</NewEntityContext.Provider>
);
};
@@ -122,18 +100,6 @@ export const EntityProvider = ({ entity, children }: EntityProviderProps) => (
/>
);
// This is used for forwards compatibility with the new entity context
const CompatibilityProvider = ({
value,
children,
}: {
value: EntityLoadingStatus;
children: ReactNode;
}) => {
return <AsyncEntityProvider {...value} children={children} />;
};
EntityContext.Provider = CompatibilityProvider as Provider<EntityLoadingStatus>;
/** @public
* @deprecated will be deleted shortly due to low external usage, re-implement if needed.
*/
@@ -35,17 +35,17 @@ import {
useElementFilter,
} from '@backstage/core-plugin-api';
import {
EntityContext,
EntityRefLinks,
FavoriteEntity,
getEntityRelations,
InspectEntityDialog,
UnregisterEntityDialog,
useEntity,
useEntityCompoundName,
} from '@backstage/plugin-catalog-react';
import { Box, TabProps } from '@material-ui/core';
import { Alert } from '@material-ui/lab';
import React, { useContext, useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import { useLocation, useNavigate } from 'react-router';
import { EntityContextMenu } from '../EntityContextMenu/EntityContextMenu';
@@ -177,7 +177,7 @@ export const EntityLayout = (props: EntityLayoutProps) => {
children,
} = props;
const { kind, namespace, name } = useEntityCompoundName();
const { entity, loading, error } = useContext(EntityContext);
const { entity, loading, error } = useEntity();
const location = useLocation();
const routes = useElementFilter(
children,