catalog-react: Deprecate useOwnedEntities & useOwnUser

Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
Johan Haals
2022-02-22 16:19:45 +01:00
parent b9436b2ca4
commit d4f67fa728
6 changed files with 38 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-techdocs': patch
---
Removed import of deprecated hook.
+6
View File
@@ -0,0 +1,6 @@
---
'@backstage/plugin-catalog-react': patch
---
Deprecated the `useOwnedEntities` hook which is replaced by the IdentityAPI.
Deprecated the `useOwnUser` hook due to low external value.
+2 -2
View File
@@ -584,13 +584,13 @@ export function useEntityPermission(permission: Permission): {
// @public
export function useEntityTypeFilter(): EntityTypeReturn;
// @public
// @public @deprecated
export function useOwnedEntities(allowedKinds?: string[]): {
loading: boolean;
ownedEntities: GetEntitiesResponse | undefined;
};
// @public
// @public @deprecated
export function useOwnUser(): AsyncState<UserEntity | undefined>;
// @public (undocumented)
@@ -26,6 +26,7 @@ import { identityApiRef, useApi } from '@backstage/core-plugin-api';
/**
* Get the catalog User entity (if any) that matches the logged-in user.
* @public
* @deprecated due to low external usage.
*/
export function useOwnUser(): AsyncState<UserEntity | undefined> {
const catalogApi = useApi(catalogApiRef);
@@ -32,6 +32,7 @@ import { useMemo } from 'react';
* @public
*
* @param allowedKinds - Array of allowed kinds to filter the entities
* @deprecated Use `ownershipEntityRefs` from `identityApi.getBackstageIdentity()` instead.
*/
export function useOwnedEntities(allowedKinds?: string[]): {
loading: boolean;
@@ -15,7 +15,7 @@
*/
import React, { useState } from 'react';
import useAsync from 'react-use/lib/useAsync';
import useAsync, { AsyncState } from 'react-use/lib/useAsync';
import { makeStyles } from '@material-ui/core';
import { CSSProperties } from '@material-ui/styles';
import {
@@ -23,9 +23,13 @@ import {
catalogApiRef,
CatalogApi,
isOwnerOf,
useOwnUser,
} from '@backstage/plugin-catalog-react';
import { Entity } from '@backstage/catalog-model';
import {
DEFAULT_NAMESPACE,
Entity,
parseEntityRef,
UserEntity,
} from '@backstage/catalog-model';
import { DocsTable } from './DocsTable';
import { DocsCardGrid } from './DocsCardGrid';
import { TechDocsPageWrapper } from './TechDocsPageWrapper';
@@ -40,7 +44,7 @@ import {
ContentHeader,
} from '@backstage/core-components';
import { useApi } from '@backstage/core-plugin-api';
import { identityApiRef, useApi } from '@backstage/core-plugin-api';
const panels = {
DocsTable: DocsTable,
@@ -195,3 +199,18 @@ export const TechDocsCustomHome = ({
</TechDocsPageWrapper>
);
};
function useOwnUser(): AsyncState<UserEntity | undefined> {
const catalogApi = useApi(catalogApiRef);
const identityApi = useApi(identityApiRef);
return useAsync(async () => {
const identity = await identityApi.getBackstageIdentity();
return catalogApi.getEntityByName(
parseEntityRef(identity.userEntityRef, {
defaultKind: 'User',
defaultNamespace: DEFAULT_NAMESPACE,
}),
) as Promise<UserEntity | undefined>;
}, [catalogApi, identityApi]);
}