From 36a0f6e0a6bafb3bc717815fe8dbfd516ced7f90 Mon Sep 17 00:00:00 2001 From: Chris Langhout Date: Tue, 25 Apr 2023 10:49:06 +0200 Subject: [PATCH 1/5] feat: allow custom title for DomainCard Signed-off-by: Chris Langhout --- .../components/DomainCard/DomainCard.test.tsx | 27 +++++++++++++++++++ .../src/components/DomainCard/DomainCard.tsx | 7 +++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/plugins/explore/src/components/DomainCard/DomainCard.test.tsx b/plugins/explore/src/components/DomainCard/DomainCard.test.tsx index df9b84820a..cb0fd8b473 100644 --- a/plugins/explore/src/components/DomainCard/DomainCard.test.tsx +++ b/plugins/explore/src/components/DomainCard/DomainCard.test.tsx @@ -51,4 +51,31 @@ describe('', () => { '/catalog/default/domain/artists', ); }); + + it('renders a domain card with custom title', async () => { + const entity: DomainEntity = { + apiVersion: 'backstage.io/v1alpha1', + kind: 'Domain', + metadata: { + name: 'artists', + }, + spec: { + owner: 'guest', + }, + }; + const { getByText } = await renderInTestApp( + , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, + ); + + expect(getByText('Explore').parentElement).toHaveAttribute( + 'href', + '/catalog/default/domain/artists', + ); + expect(getByText('my Custom Title')).toBeInTheDocument(); + }); }); diff --git a/plugins/explore/src/components/DomainCard/DomainCard.tsx b/plugins/explore/src/components/DomainCard/DomainCard.tsx index 0d37e3e273..f5327ea4e0 100644 --- a/plugins/explore/src/components/DomainCard/DomainCard.tsx +++ b/plugins/explore/src/components/DomainCard/DomainCard.tsx @@ -35,7 +35,7 @@ import { LinkButton, ItemCardHeader } from '@backstage/core-components'; import { useRouteRef } from '@backstage/core-plugin-api'; /** @public */ -export const DomainCard = (props: { entity: DomainEntity }) => { +export const DomainCard = (props: { entity: DomainEntity; title?: string }) => { const { entity } = props; const catalogEntityRoute = useRouteRef(entityRouteRef); @@ -53,7 +53,10 @@ export const DomainCard = (props: { entity: DomainEntity }) => { return ( - + {entity.metadata.tags?.length ? ( From 0f5d997d350514865c90d0133dfabf6f6f416c09 Mon Sep 17 00:00:00 2001 From: Chris Langhout Date: Tue, 25 Apr 2023 15:08:58 +0200 Subject: [PATCH 2/5] chore: fix tests Signed-off-by: Chris Langhout --- .../examples/domains/artists-domain.yaml | 1 + .../components/DomainCard/DomainCard.test.tsx | 5 +++- .../src/components/DomainCard/DomainCard.tsx | 4 +-- .../components/EntityCard/EntityCard.test.tsx | 26 +++++++++++++++++++ .../src/components/EntityCard/EntityCard.tsx | 5 +++- 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/packages/catalog-model/examples/domains/artists-domain.yaml b/packages/catalog-model/examples/domains/artists-domain.yaml index 2a74425791..0dc1b91cb5 100644 --- a/packages/catalog-model/examples/domains/artists-domain.yaml +++ b/packages/catalog-model/examples/domains/artists-domain.yaml @@ -3,6 +3,7 @@ kind: Domain metadata: name: artists description: Everything related to artists + title: Artists links: - url: http://example.com/domain/artists/ title: Domain Readme diff --git a/plugins/explore/src/components/DomainCard/DomainCard.test.tsx b/plugins/explore/src/components/DomainCard/DomainCard.test.tsx index cb0fd8b473..b66e30c652 100644 --- a/plugins/explore/src/components/DomainCard/DomainCard.test.tsx +++ b/plugins/explore/src/components/DomainCard/DomainCard.test.tsx @@ -17,6 +17,7 @@ import { DomainEntity } from '@backstage/catalog-model'; import { entityRouteRef } from '@backstage/plugin-catalog-react'; import { renderInTestApp } from '@backstage/test-utils'; +import { screen } from '@testing-library/react'; import React from 'react'; import { DomainCard } from './DomainCard'; @@ -58,13 +59,14 @@ describe('', () => { kind: 'Domain', metadata: { name: 'artists', + title: 'my Custom Title', }, spec: { owner: 'guest', }, }; const { getByText } = await renderInTestApp( - , + , { mountedRoutes: { '/catalog/:namespace/:kind/:name': entityRouteRef, @@ -77,5 +79,6 @@ describe('', () => { '/catalog/default/domain/artists', ); expect(getByText('my Custom Title')).toBeInTheDocument(); + expect(screen.queryByText('artists')).not.toBeInTheDocument(); }); }); diff --git a/plugins/explore/src/components/DomainCard/DomainCard.tsx b/plugins/explore/src/components/DomainCard/DomainCard.tsx index f5327ea4e0..c70df46b1a 100644 --- a/plugins/explore/src/components/DomainCard/DomainCard.tsx +++ b/plugins/explore/src/components/DomainCard/DomainCard.tsx @@ -35,7 +35,7 @@ import { LinkButton, ItemCardHeader } from '@backstage/core-components'; import { useRouteRef } from '@backstage/core-plugin-api'; /** @public */ -export const DomainCard = (props: { entity: DomainEntity; title?: string }) => { +export const DomainCard = (props: { entity: DomainEntity }) => { const { entity } = props; const catalogEntityRoute = useRouteRef(entityRouteRef); @@ -54,7 +54,7 @@ export const DomainCard = (props: { entity: DomainEntity; title?: string }) => { diff --git a/plugins/explore/src/components/EntityCard/EntityCard.test.tsx b/plugins/explore/src/components/EntityCard/EntityCard.test.tsx index 4b006e347f..cebd5af3d6 100644 --- a/plugins/explore/src/components/EntityCard/EntityCard.test.tsx +++ b/plugins/explore/src/components/EntityCard/EntityCard.test.tsx @@ -18,6 +18,7 @@ import { Entity } from '@backstage/catalog-model'; import { entityRouteRef } from '@backstage/plugin-catalog-react'; import { renderInTestApp } from '@backstage/test-utils'; import React from 'react'; +import { screen } from '@testing-library/react'; import { EntityCard } from './EntityCard'; describe('', () => { @@ -51,4 +52,29 @@ describe('', () => { '/catalog/default/domain/artists', ); }); + + it('renders an entity card with display title', async () => { + const entity: Entity = { + apiVersion: 'backstage.io/v1alpha1', + kind: 'Domain', + metadata: { + name: 'artists', + title: 'New Title', + }, + spec: { + owner: 'guest', + }, + }; + const { getByText } = await renderInTestApp( + , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, + ); + + expect(getByText('New Title')).toBeInTheDocument(); + expect(screen.queryByText('artists')).not.toBeInTheDocument(); + }); }); diff --git a/plugins/explore/src/components/EntityCard/EntityCard.tsx b/plugins/explore/src/components/EntityCard/EntityCard.tsx index 0a5908df38..9589d4721e 100644 --- a/plugins/explore/src/components/EntityCard/EntityCard.tsx +++ b/plugins/explore/src/components/EntityCard/EntityCard.tsx @@ -53,7 +53,10 @@ export const EntityCard = (props: { entity: Entity }) => { return ( - + {entity.metadata.tags?.length ? ( From 4851581deb6e91b721dcc8980245b485671cb441 Mon Sep 17 00:00:00 2001 From: Chris Langhout Date: Tue, 25 Apr 2023 17:52:19 +0200 Subject: [PATCH 3/5] chore: add changeset Signed-off-by: Chris Langhout --- .changeset/khaki-brooms-kiss.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/khaki-brooms-kiss.md diff --git a/.changeset/khaki-brooms-kiss.md b/.changeset/khaki-brooms-kiss.md new file mode 100644 index 0000000000..76d4ff2cd2 --- /dev/null +++ b/.changeset/khaki-brooms-kiss.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-explore': patch +--- + +Display the title of the entity on the explore card if present, otherwise stick to the name From d859a9304937364a763d048d967921a563ee5f2b Mon Sep 17 00:00:00 2001 From: Chris Langhout Date: Tue, 25 Apr 2023 18:22:50 +0200 Subject: [PATCH 4/5] chore: add changeset for catalog Signed-off-by: Chris Langhout --- .changeset/early-spiders-play.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/early-spiders-play.md diff --git a/.changeset/early-spiders-play.md b/.changeset/early-spiders-play.md new file mode 100644 index 0000000000..9ca77e541e --- /dev/null +++ b/.changeset/early-spiders-play.md @@ -0,0 +1,5 @@ +--- +'@backstage/catalog-model': patch +--- + +Add a entity.metadata.title to an example entity for testing purposes From 931504061a26ff0329293a9bce72fca54dc710a8 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 4 May 2023 15:02:55 +0200 Subject: [PATCH 5/5] Delete early-spiders-play.md Signed-off-by: Patrik Oldsberg --- .changeset/early-spiders-play.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .changeset/early-spiders-play.md diff --git a/.changeset/early-spiders-play.md b/.changeset/early-spiders-play.md deleted file mode 100644 index 9ca77e541e..0000000000 --- a/.changeset/early-spiders-play.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@backstage/catalog-model': patch ---- - -Add a entity.metadata.title to an example entity for testing purposes