Skip to content

Commit

Permalink
add useOwnedEntites to catalog-react
Browse files Browse the repository at this point in the history
Signed-off-by: mufaddal motiwala <mufaddalmm.52@gmail.com>
  • Loading branch information
mufaddal7 committed Dec 14, 2021
1 parent 4775a42 commit 3491a36
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-baboons-sparkle.md
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-react': minor
---

added useOwnedEntities hook to get the list of entities of the logged-in user
7 changes: 7 additions & 0 deletions plugins/catalog-react/api-report.md
Expand Up @@ -9,6 +9,7 @@ import { ApiRef } from '@backstage/core-plugin-api';
import { AsyncState } from 'react-use/lib/useAsync';
import { CATALOG_FILTER_EXISTS } from '@backstage/catalog-client';
import { CatalogApi } from '@backstage/catalog-client';
import { CatalogListResponse } from '@backstage/catalog-client';
import { ComponentEntity } from '@backstage/catalog-model';
import { ComponentProps } from 'react';
import { Context } from 'react';
Expand Down Expand Up @@ -847,6 +848,12 @@ export function useEntityOwnership(): {
// @public
export function useEntityTypeFilter(): EntityTypeReturn;

// @public
export function useOwnedEntities(allowedKinds?: string[]): {
loading: boolean;
ownedEntities: CatalogListResponse<Entity> | undefined;
};

// Warning: (ae-missing-release-tag) "useOwnUser" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
Expand Down
1 change: 1 addition & 0 deletions plugins/catalog-react/src/hooks/index.ts
Expand Up @@ -42,3 +42,4 @@ export {
useEntityOwnership,
loadIdentityOwnerRefs,
} from './useEntityOwnership';
export { useOwnedEntities } from './useOwnedEntities';
Expand Up @@ -13,17 +13,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { catalogApiRef } from './../api';
import {
catalogApiRef,
loadCatalogOwnerRefs,
loadIdentityOwnerRefs,
} from '@backstage/plugin-catalog-react';
} from './useEntityOwnership';
import { identityApiRef, useApi } from '@backstage/core-plugin-api';
import { Entity, RELATION_OWNED_BY } from '@backstage/catalog-model';
import { CatalogListResponse } from '@backstage/catalog-client';
import { useAsync } from 'react-use';
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
* @returns CatalogListResponse<Entity>
*/
export function useOwnedEntities(allowedKinds?: string[]): {
loading: boolean;
ownedEntities: CatalogListResponse<Entity> | undefined;
Expand Down Expand Up @@ -52,6 +62,7 @@ export function useOwnedEntities(allowedKinds?: string[]): {
);
return catalogs;
}, []);

const ownedEntities = useMemo(() => {
return refs;
}, [refs]);
Expand Down
Expand Up @@ -13,13 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { formatEntityRefTitle } from '@backstage/plugin-catalog-react';
import {
formatEntityRefTitle,
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 { FieldProps } from '@rjsf/core';
import React from 'react';
import { useOwnedEntities } from './useOwnedEntities';

export const OwnedEntityPicker = ({
onChange,
Expand Down

0 comments on commit 3491a36

Please sign in to comment.