Merge pull request #9998 from backstage/jhaals/rem-useOwnedEntities
catalog-react: Remove useOwnedEntities hook
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-react': minor
|
||||
---
|
||||
|
||||
**BREAKING**: Removed `useOwnedEntities` and moved its usage internally to the scaffolder-backend where it's used.
|
||||
|
||||
**BREAKING**: Removed `EntityTypeReturn` type which is now inlined.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-react': patch
|
||||
---
|
||||
|
||||
Internalized usage of `useOwnedEntities` hook.
|
||||
@@ -13,7 +13,6 @@ import { ComponentEntity } from '@backstage/catalog-model';
|
||||
import { ComponentProps } from 'react';
|
||||
import { CompoundEntityRef } from '@backstage/catalog-model';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { GetEntitiesResponse } from '@backstage/catalog-client';
|
||||
import { IconButton } from '@material-ui/core';
|
||||
import { LinkProps } from '@backstage/core-components';
|
||||
import { Observable } from '@backstage/types';
|
||||
@@ -388,15 +387,6 @@ export interface EntityTypePickerProps {
|
||||
initialFilter?: string;
|
||||
}
|
||||
|
||||
// @public @deprecated (undocumented)
|
||||
export type EntityTypeReturn = {
|
||||
loading: boolean;
|
||||
error?: Error;
|
||||
availableTypes: string[];
|
||||
selectedTypes: string[];
|
||||
setSelectedTypes: (types: string[]) => void;
|
||||
};
|
||||
|
||||
// @public
|
||||
export const FavoriteEntity: (props: FavoriteEntityProps) => JSX.Element;
|
||||
|
||||
@@ -546,12 +536,6 @@ export function useEntityTypeFilter(): {
|
||||
setSelectedTypes: (types: string[]) => void;
|
||||
};
|
||||
|
||||
// @public @deprecated
|
||||
export function useOwnedEntities(allowedKinds?: string[]): {
|
||||
loading: boolean;
|
||||
ownedEntities: GetEntitiesResponse | undefined;
|
||||
};
|
||||
|
||||
// @public @deprecated
|
||||
export function useOwnUser(): AsyncState<UserEntity | undefined>;
|
||||
|
||||
|
||||
@@ -34,12 +34,10 @@ export type {
|
||||
EntityListContextProps,
|
||||
} from './useEntityListProvider';
|
||||
export { useEntityTypeFilter } from './useEntityTypeFilter';
|
||||
export type { EntityTypeReturn } from './useEntityTypeFilter';
|
||||
export { useEntityKinds } from './useEntityKinds';
|
||||
export { useOwnUser } from './useOwnUser';
|
||||
export { useRelatedEntities } from './useRelatedEntities';
|
||||
export { useStarredEntities } from './useStarredEntities';
|
||||
export { useStarredEntity } from './useStarredEntity';
|
||||
export { loadCatalogOwnerRefs, useEntityOwnership } from './useEntityOwnership';
|
||||
export { useOwnedEntities } from './useOwnedEntities';
|
||||
export { useEntityPermission } from './useEntityPermission';
|
||||
|
||||
@@ -23,17 +23,6 @@ import { catalogApiRef } from '../api';
|
||||
import { useEntityList } from './useEntityListProvider';
|
||||
import { EntityTypeFilter } from '../filters';
|
||||
|
||||
/** @public
|
||||
* @deprecated type inlined with {@link useEntityTypeFilter}.
|
||||
*/
|
||||
export type EntityTypeReturn = {
|
||||
loading: boolean;
|
||||
error?: Error;
|
||||
availableTypes: string[];
|
||||
selectedTypes: string[];
|
||||
setSelectedTypes: (types: string[]) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* A hook built on top of `useEntityList` for enabling selection of valid `spec.type` values
|
||||
* based on the selected EntityKindFilter.
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Copyright 2021 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 { catalogApiRef } from './../api';
|
||||
import { loadCatalogOwnerRefs } from './useEntityOwnership';
|
||||
import { identityApiRef, useApi } from '@backstage/core-plugin-api';
|
||||
import { RELATION_OWNED_BY } from '@backstage/catalog-model';
|
||||
import { GetEntitiesResponse } from '@backstage/catalog-client';
|
||||
import useAsync from 'react-use/lib/useAsync';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
/**
|
||||
* Takes the relevant parts of the Backstage identity, and translates them into
|
||||
* a list of entities which are owned by the user. Takes an optional parameter
|
||||
* to filter the entities based on allowedKinds
|
||||
*
|
||||
* @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;
|
||||
ownedEntities: GetEntitiesResponse | undefined;
|
||||
} {
|
||||
const identityApi = useApi(identityApiRef);
|
||||
const catalogApi = useApi(catalogApiRef);
|
||||
|
||||
const { loading, value: refs } = useAsync(async () => {
|
||||
const identity = await identityApi.getBackstageIdentity();
|
||||
const identityRefs = identity.ownershipEntityRefs;
|
||||
const catalogRefs = await loadCatalogOwnerRefs(catalogApi, identityRefs);
|
||||
const catalogs = await catalogApi.getEntities(
|
||||
allowedKinds
|
||||
? {
|
||||
filter: {
|
||||
kind: allowedKinds,
|
||||
[`relations.${RELATION_OWNED_BY}`]:
|
||||
[...identityRefs, ...catalogRefs] || [],
|
||||
},
|
||||
}
|
||||
: {
|
||||
filter: {
|
||||
[`relations.${RELATION_OWNED_BY}`]:
|
||||
[...identityRefs, ...catalogRefs] || [],
|
||||
},
|
||||
},
|
||||
);
|
||||
return catalogs;
|
||||
}, []);
|
||||
|
||||
const ownedEntities = useMemo(() => {
|
||||
return refs;
|
||||
}, [refs]);
|
||||
|
||||
return useMemo(() => ({ loading, ownedEntities }), [loading, ownedEntities]);
|
||||
}
|
||||
@@ -13,14 +13,18 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { GetEntitiesResponse } from '@backstage/catalog-client';
|
||||
import { RELATION_OWNED_BY } from '@backstage/catalog-model';
|
||||
import { identityApiRef, useApi } from '@backstage/core-plugin-api';
|
||||
import {
|
||||
catalogApiRef,
|
||||
humanizeEntityRef,
|
||||
useOwnedEntities,
|
||||
} from '@backstage/plugin-catalog-react';
|
||||
import { TextField } from '@material-ui/core';
|
||||
import FormControl from '@material-ui/core/FormControl';
|
||||
import Autocomplete from '@material-ui/lab/Autocomplete';
|
||||
import React from 'react';
|
||||
import React, { useMemo } from 'react';
|
||||
import useAsync from 'react-use/lib/useAsync';
|
||||
|
||||
import { FieldExtensionComponentProps } from '../../../extensions';
|
||||
|
||||
@@ -86,3 +90,45 @@ export const OwnedEntityPicker = (
|
||||
</FormControl>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Takes the relevant parts of the Backstage identity, and translates them into
|
||||
* a list of entities which are owned by the user. Takes an optional parameter
|
||||
* to filter the entities based on allowedKinds
|
||||
*
|
||||
*
|
||||
* @param allowedKinds - Array of allowed kinds to filter the entities
|
||||
*/
|
||||
function useOwnedEntities(allowedKinds?: string[]): {
|
||||
loading: boolean;
|
||||
ownedEntities: GetEntitiesResponse | undefined;
|
||||
} {
|
||||
const identityApi = useApi(identityApiRef);
|
||||
const catalogApi = useApi(catalogApiRef);
|
||||
|
||||
const { loading, value: refs } = useAsync(async () => {
|
||||
const identity = await identityApi.getBackstageIdentity();
|
||||
const identityRefs = identity.ownershipEntityRefs;
|
||||
const catalogs = await catalogApi.getEntities(
|
||||
allowedKinds
|
||||
? {
|
||||
filter: {
|
||||
kind: allowedKinds,
|
||||
[`relations.${RELATION_OWNED_BY}`]: identityRefs || [],
|
||||
},
|
||||
}
|
||||
: {
|
||||
filter: {
|
||||
[`relations.${RELATION_OWNED_BY}`]: identityRefs || [],
|
||||
},
|
||||
},
|
||||
);
|
||||
return catalogs;
|
||||
}, []);
|
||||
|
||||
const ownedEntities = useMemo(() => {
|
||||
return refs;
|
||||
}, [refs]);
|
||||
|
||||
return useMemo(() => ({ loading, ownedEntities }), [loading, ownedEntities]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user