Move name calculation to the EntityCountTile itself
Signed-off-by: Pascal Lukanek <pascal.lukanek@live.de>
This commit is contained in:
@@ -57,16 +57,16 @@ const EntityCountTile = ({
|
||||
counter,
|
||||
type,
|
||||
kind,
|
||||
name,
|
||||
url,
|
||||
}: {
|
||||
counter: number;
|
||||
type: string;
|
||||
type?: string;
|
||||
kind: string;
|
||||
name: string;
|
||||
url: string;
|
||||
}) => {
|
||||
const classes = useStyles({ type });
|
||||
const classes = useStyles({ type: type ?? kind });
|
||||
|
||||
const rawTitle = type ?? kind;
|
||||
|
||||
return (
|
||||
<Link to={url} variant="body2">
|
||||
@@ -80,9 +80,9 @@ const EntityCountTile = ({
|
||||
{counter}
|
||||
</Typography>
|
||||
<Typography className={classes.bold} variant="h6">
|
||||
{pluralize(name, counter)}
|
||||
{pluralize(rawTitle.toLocaleUpperCase('en-US'), counter)}
|
||||
</Typography>
|
||||
{kind !== type && <Typography variant="subtitle1">{kind}</Typography>}
|
||||
{type && <Typography variant="subtitle1">{kind}</Typography>}
|
||||
</Box>
|
||||
</Link>
|
||||
);
|
||||
@@ -116,12 +116,11 @@ export const ComponentsGrid = ({
|
||||
return (
|
||||
<Grid container>
|
||||
{componentsWithCounters?.map(c => (
|
||||
<Grid item xs={6} md={6} lg={4} key={c.name}>
|
||||
<Grid item xs={6} md={6} lg={4} key={c.type ?? c.kind}>
|
||||
<EntityCountTile
|
||||
counter={c.counter}
|
||||
kind={c.kind}
|
||||
type={c.type}
|
||||
name={c.name}
|
||||
url={`${catalogLink()}/?${c.queryParams}`}
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
@@ -136,7 +136,6 @@ export function useGetEntities(
|
||||
counter: number;
|
||||
type: string;
|
||||
kind: string;
|
||||
name: string;
|
||||
queryParams: string;
|
||||
}[]
|
||||
| undefined;
|
||||
@@ -174,16 +173,14 @@ export function useGetEntities(
|
||||
const counts = ownedEntitiesList.items.reduce(
|
||||
(acc: EntityTypeProps[], ownedEntity) => {
|
||||
const match = acc.find(
|
||||
x =>
|
||||
x.kind === ownedEntity.kind &&
|
||||
x.type === (ownedEntity.spec?.type ?? ownedEntity.kind),
|
||||
x => x.kind === ownedEntity.kind && x.type === ownedEntity.spec?.type,
|
||||
);
|
||||
if (match) {
|
||||
match.count += 1;
|
||||
} else {
|
||||
acc.push({
|
||||
kind: ownedEntity.kind,
|
||||
type: ownedEntity.spec?.type?.toString() ?? ownedEntity.kind,
|
||||
type: ownedEntity.spec?.type?.toString(),
|
||||
count: 1,
|
||||
});
|
||||
}
|
||||
@@ -199,13 +196,11 @@ export function useGetEntities(
|
||||
counter: topOwnedEntity.count,
|
||||
type: topOwnedEntity.type,
|
||||
kind: topOwnedEntity.kind,
|
||||
name: topOwnedEntity.type.toLocaleUpperCase('en-US'),
|
||||
queryParams: getQueryParams(owners, topOwnedEntity),
|
||||
})) as Array<{
|
||||
counter: number;
|
||||
type: string;
|
||||
kind: string;
|
||||
name: string;
|
||||
queryParams: string;
|
||||
}>;
|
||||
}, [catalogApi, entity, relationsType]);
|
||||
|
||||
Reference in New Issue
Block a user