From 18f40d62e63a8f74a4730601d7a9e182eea6114b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Erik=20Bergstr=C3=B6m?= Date: Fri, 18 Aug 2023 14:45:57 +0200 Subject: [PATCH] chore: clarify entity aggregation type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carl-Erik Bergström --- plugins/org/api-report.md | 17 +++++------------ .../Cards/OwnershipCard/ComponentsGrid.tsx | 4 ++-- .../Cards/OwnershipCard/OwnershipCard.tsx | 6 +++--- .../src/components/Cards/OwnershipCard/types.ts | 9 +-------- .../Cards/OwnershipCard/useGetEntities.ts | 12 ++++++------ 5 files changed, 17 insertions(+), 31 deletions(-) diff --git a/plugins/org/api-report.md b/plugins/org/api-report.md index a55e069dac..4b6864ab77 100644 --- a/plugins/org/api-report.md +++ b/plugins/org/api-report.md @@ -10,12 +10,6 @@ import { ExternalRouteRef } from '@backstage/core-plugin-api'; import { IconComponent } from '@backstage/core-plugin-api'; import { InfoCardVariants } from '@backstage/core-components'; -// @public (undocumented) -export const DefaultRelationType: { - readonly Direct: 'direct'; - readonly Aggregated: 'aggregated'; -}; - // @public (undocumented) export const EntityGroupProfileCard: (props: { variant?: InfoCardVariants | undefined; @@ -34,10 +28,13 @@ export const EntityOwnershipCard: (props: { variant?: InfoCardVariants | undefined; entityFilterKind?: string[] | undefined; hideRelationsToggle?: boolean | undefined; - relationsType?: RelationType | undefined; + relationsType?: EntityRelationAggregation | undefined; entityLimit?: number | undefined; }) => JSX.Element; +// @public (undocumented) +export type EntityRelationAggregation = 'direct' | 'aggregated'; + // @public (undocumented) export const EntityUserProfileCard: (props: { variant?: InfoCardVariants | undefined; @@ -81,14 +78,10 @@ export const OwnershipCard: (props: { variant?: InfoCardVariants; entityFilterKind?: string[]; hideRelationsToggle?: boolean; - relationsType?: RelationType; + relationsType?: EntityRelationAggregation; entityLimit?: number; }) => JSX.Element; -// @public (undocumented) -export type RelationType = - (typeof DefaultRelationType)[keyof typeof DefaultRelationType]; - // @public (undocumented) export const UserProfileCard: (props: { variant?: InfoCardVariants; diff --git a/plugins/org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx b/plugins/org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx index c4869c849c..2725991d0d 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx +++ b/plugins/org/src/components/Cards/OwnershipCard/ComponentsGrid.tsx @@ -34,7 +34,7 @@ import React from 'react'; import pluralize from 'pluralize'; import { catalogIndexRouteRef } from '../../../routes'; import { useGetEntities } from './useGetEntities'; -import { RelationType } from './types'; +import { EntityRelationAggregation } from './types'; const useStyles = makeStyles((theme: BackstageTheme) => createStyles({ @@ -114,7 +114,7 @@ export const ComponentsGrid = ({ entityLimit = 6, }: { entity: Entity; - relationsType: RelationType; + relationsType: EntityRelationAggregation; entityFilterKind?: string[]; entityLimit?: number; }) => { diff --git a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.tsx b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.tsx index 4de423575e..2fb7826e52 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.tsx +++ b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.tsx @@ -27,7 +27,7 @@ import { } from '@material-ui/core'; import React, { useState } from 'react'; import { ComponentsGrid } from './ComponentsGrid'; -import { DefaultRelationType, RelationType } from './types'; +import { EntityRelationAggregation } from './types'; const useStyles = makeStyles(theme => ({ list: { @@ -57,7 +57,7 @@ export const OwnershipCard = (props: { variant?: InfoCardVariants; entityFilterKind?: string[]; hideRelationsToggle?: boolean; - relationsType?: RelationType; + relationsType?: EntityRelationAggregation; entityLimit?: number; }) => { const { @@ -72,7 +72,7 @@ export const OwnershipCard = (props: { const classes = useStyles(); const { entity } = useEntity(); const [getRelationsType, setRelationsType] = useState( - relationsType || DefaultRelationType.Direct, + relationsType || 'direct', ); return ( diff --git a/plugins/org/src/components/Cards/OwnershipCard/types.ts b/plugins/org/src/components/Cards/OwnershipCard/types.ts index 09095346f5..c1e95ee94e 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/types.ts +++ b/plugins/org/src/components/Cards/OwnershipCard/types.ts @@ -15,11 +15,4 @@ */ /** @public */ -export const DefaultRelationType = { - Direct: 'direct', - Aggregated: 'aggregated', -} as const; - -/** @public */ -export type RelationType = - (typeof DefaultRelationType)[keyof typeof DefaultRelationType]; +export type EntityRelationAggregation = 'direct' | 'aggregated'; diff --git a/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts b/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts index 361294ea1e..cf2b2a85c0 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts +++ b/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts @@ -31,7 +31,7 @@ import limiterFactory from 'p-limit'; import { useApi } from '@backstage/core-plugin-api'; import useAsync from 'react-use/lib/useAsync'; import qs from 'qs'; -import { RelationType } from './types'; +import { EntityRelationAggregation as EntityRelationsAggregation } from './types'; const limiter = limiterFactory(10); @@ -124,11 +124,11 @@ const getChildOwnershipEntityRefs = async ( const getOwners = async ( entity: Entity, - relationsType: RelationType, + relations: EntityRelationsAggregation, catalogApi: CatalogApi, ): Promise => { const isGroup = entity.kind === 'Group'; - const isAggregated = relationsType === 'aggregated'; + const isAggregated = relations === 'aggregated'; const isUserEntity = entity.kind === 'User'; const owners: string[] = []; @@ -173,7 +173,7 @@ const getOwnedEntitiesByOwners = ( export function useGetEntities( entity: Entity, - relationsType: RelationType, + relations: EntityRelationsAggregation, entityFilterKind?: string[], entityLimit = 6, ): { @@ -196,7 +196,7 @@ export function useGetEntities( error, value: componentsWithCounters, } = useAsync(async () => { - const owners = await getOwners(entity, relationsType, catalogApi); + const owners = await getOwners(entity, relations, catalogApi); const ownedEntitiesList = await getOwnedEntitiesByOwners( owners, @@ -237,7 +237,7 @@ export function useGetEntities( kind: string; queryParams: string; }>; - }, [catalogApi, entity, relationsType]); + }, [catalogApi, entity, relations]); return { componentsWithCounters,