catalog-react: Deprecate useOwnedEntities & useOwnUser
Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-techdocs': patch
|
||||
---
|
||||
|
||||
Removed import of deprecated hook.
|
||||
@@ -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.
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user