diff --git a/.changeset/weak-news-jam.md b/.changeset/weak-news-jam.md
new file mode 100644
index 0000000000..a1f44082da
--- /dev/null
+++ b/.changeset/weak-news-jam.md
@@ -0,0 +1,5 @@
+---
+'@backstage/plugin-scaffolder-react': patch
+---
+
+Fix bug that erroneously caused a separator or a 0 to render in the TemplateCard for Templates with empty links
diff --git a/plugins/scaffolder-react/src/next/components/TemplateCard/TemplateCard.test.tsx b/plugins/scaffolder-react/src/next/components/TemplateCard/TemplateCard.test.tsx
index 5c373411fa..2e2a147ad1 100644
--- a/plugins/scaffolder-react/src/next/components/TemplateCard/TemplateCard.test.tsx
+++ b/plugins/scaffolder-react/src/next/components/TemplateCard/TemplateCard.test.tsx
@@ -149,6 +149,88 @@ describe('TemplateCard', () => {
}
});
+ it('should not render links section when empty links are defined', async () => {
+ const mockTemplate: TemplateEntityV1beta3 = {
+ apiVersion: 'scaffolder.backstage.io/v1beta3',
+ kind: 'Template',
+ metadata: { name: 'bob', tags: [], links: [] },
+ spec: {
+ steps: [],
+ type: 'service',
+ },
+ relations: [
+ {
+ targetRef: 'group:default/my-test-user',
+ type: RELATION_OWNED_BY,
+ },
+ ],
+ };
+
+ const { queryByRole, queryByText } = await renderInTestApp(
+
+
+ ,
+ {
+ mountedRoutes: {
+ '/catalog/:kind/:namespace/:name': entityRouteRef,
+ },
+ },
+ );
+
+ expect(queryByRole('separator')).not.toBeInTheDocument();
+ expect(queryByText('0')).not.toBeInTheDocument();
+ });
+
+ it('should not render links section when empty additional links are defined', async () => {
+ const mockTemplate: TemplateEntityV1beta3 = {
+ apiVersion: 'scaffolder.backstage.io/v1beta3',
+ kind: 'Template',
+ metadata: { name: 'bob', tags: [], links: [] },
+ spec: {
+ steps: [],
+ type: 'service',
+ },
+ relations: [
+ {
+ targetRef: 'group:default/my-test-user',
+ type: RELATION_OWNED_BY,
+ },
+ ],
+ };
+
+ const { queryByRole, queryByText } = await renderInTestApp(
+
+
+ ,
+ {
+ mountedRoutes: {
+ '/catalog/:kind/:namespace/:name': entityRouteRef,
+ },
+ },
+ );
+
+ expect(queryByRole('separator')).not.toBeInTheDocument();
+ expect(queryByText('0')).not.toBeInTheDocument();
+ });
+
it('should render a link to the owner', async () => {
const mockTemplate: TemplateEntityV1beta3 = {
apiVersion: 'scaffolder.backstage.io/v1beta3',
diff --git a/plugins/scaffolder-react/src/next/components/TemplateCard/TemplateCard.tsx b/plugins/scaffolder-react/src/next/components/TemplateCard/TemplateCard.tsx
index 7850137945..6bcff0b0ce 100644
--- a/plugins/scaffolder-react/src/next/components/TemplateCard/TemplateCard.tsx
+++ b/plugins/scaffolder-react/src/next/components/TemplateCard/TemplateCard.tsx
@@ -136,7 +136,8 @@ export const TemplateCard = (props: TemplateCardProps) => {
>
)}
- {(props.additionalLinks || template.metadata.links?.length) && (
+ {(!!props.additionalLinks?.length ||
+ !!template.metadata.links?.length) && (
<>