diff --git a/.changeset/four-days-sneeze.md b/.changeset/four-days-sneeze.md
new file mode 100644
index 0000000000..93517d3a73
--- /dev/null
+++ b/.changeset/four-days-sneeze.md
@@ -0,0 +1,6 @@
+---
+'@backstage/plugin-techdocs': patch
+'@backstage/plugin-techdocs-backend': patch
+---
+
+Display entity title (if defined) in titles of TechDocs search results
diff --git a/.changeset/twelve-candles-mix.md b/.changeset/twelve-candles-mix.md
new file mode 100644
index 0000000000..3218b2997c
--- /dev/null
+++ b/.changeset/twelve-candles-mix.md
@@ -0,0 +1,5 @@
+---
+'@backstage/plugin-catalog-backend': patch
+---
+
+Use entity title (if defined) as title of documents indexed by `DefaultCatalogCollator`
diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollator.test.ts b/plugins/catalog-backend/src/search/DefaultCatalogCollator.test.ts
index bb556fc49f..20e141b921 100644
--- a/plugins/catalog-backend/src/search/DefaultCatalogCollator.test.ts
+++ b/plugins/catalog-backend/src/search/DefaultCatalogCollator.test.ts
@@ -37,6 +37,20 @@ const expectedEntities: Entity[] = [
owner: 'someone',
},
},
+ {
+ apiVersion: 'backstage.io/v1alpha1',
+ kind: 'Component',
+ metadata: {
+ title: 'Test Entity',
+ name: 'test-entity-2',
+ description: 'The expected description 2',
+ },
+ spec: {
+ type: 'some-type',
+ lifecycle: 'experimental',
+ owner: 'someone',
+ },
+ },
];
describe('DefaultCatalogCollator', () => {
@@ -89,6 +103,15 @@ describe('DefaultCatalogCollator', () => {
lifecycle: expectedEntities[0]!.spec!.lifecycle,
owner: expectedEntities[0]!.spec!.owner,
});
+ expect(documents[1]).toMatchObject({
+ title: expectedEntities[1].metadata.title,
+ location: '/catalog/default/component/test-entity-2',
+ text: expectedEntities[1].metadata.description,
+ namespace: 'default',
+ componentType: expectedEntities[1]!.spec!.type,
+ lifecycle: expectedEntities[1]!.spec!.lifecycle,
+ owner: expectedEntities[1]!.spec!.owner,
+ });
});
it('maps a returned entity with a custom locationTemplate', async () => {
diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts
index 6292b2a833..a28a7645c4 100644
--- a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts
+++ b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts
@@ -87,7 +87,7 @@ export class DefaultCatalogCollator implements DocumentCollator {
});
return response.items.map((entity: Entity): CatalogEntityDocument => {
return {
- title: entity.metadata.name,
+ title: entity.metadata.title ?? entity.metadata.name,
location: this.applyArgsToFormat(this.locationTemplate, {
namespace: entity.metadata.namespace || 'default',
kind: entity.kind,
diff --git a/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.test.ts b/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.test.ts
index 0df22bee53..006cfdd073 100644
--- a/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.test.ts
+++ b/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.test.ts
@@ -58,6 +58,7 @@ const expectedEntities: Entity[] = [
apiVersion: 'backstage.io/v1alpha1',
kind: 'Component',
metadata: {
+ title: 'Test Entity with Docs!',
name: 'test-entity-with-docs',
description: 'Documented description',
annotations: {
@@ -133,6 +134,7 @@ describe('DefaultTechDocsCollator with legacyPathCasing configuration', () => {
location: `/docs/default/Component/${entity.metadata.name}/${mockSearchDocIndex.docs[idx].location}`,
text: mockSearchDocIndex.docs[idx].text,
namespace: 'default',
+ entityTitle: entity!.metadata.title,
componentType: entity!.spec!.type,
lifecycle: entity!.spec!.lifecycle,
owner: '',
@@ -177,6 +179,7 @@ describe('DefaultTechDocsCollator', () => {
location: `/docs/default/component/${entity.metadata.name}/${mockSearchDocIndex.docs[idx].location}`,
text: mockSearchDocIndex.docs[idx].text,
namespace: 'default',
+ entityTitle: entity!.metadata.title,
componentType: entity!.spec!.type,
lifecycle: entity!.spec!.lifecycle,
owner: '',
diff --git a/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.ts b/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.ts
index cb7d40206b..c0a96b7862 100644
--- a/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.ts
+++ b/plugins/techdocs-backend/src/search/DefaultTechDocsCollator.ts
@@ -93,6 +93,7 @@ export class DefaultTechDocsCollator implements DocumentCollator {
'namespace',
'metadata.annotations',
'metadata.name',
+ 'metadata.title',
'metadata.namespace',
'spec.type',
'spec.lifecycle',
@@ -130,6 +131,7 @@ export class DefaultTechDocsCollator implements DocumentCollator {
}),
path: doc.location,
...entityInfo,
+ entityTitle: entity.metadata.title,
componentType: entity.spec?.type?.toString() || 'other',
lifecycle: (entity.spec?.lifecycle as string) || '',
owner:
diff --git a/plugins/techdocs/src/components/DocsResultListItem/DocsResultListItem.test.tsx b/plugins/techdocs/src/components/DocsResultListItem/DocsResultListItem.test.tsx
index 22dc86f440..807914c5ad 100644
--- a/plugins/techdocs/src/components/DocsResultListItem/DocsResultListItem.test.tsx
+++ b/plugins/techdocs/src/components/DocsResultListItem/DocsResultListItem.test.tsx
@@ -33,6 +33,17 @@ const validResult = {
lifecycle: 'production',
};
+const validResultWithTitle = {
+ location: 'https://backstage.io/docs',
+ title: 'Documentation',
+ text: 'Backstage is an open-source developer portal that puts the developer experience first.',
+ kind: 'library',
+ namespace: '',
+ name: 'Backstage',
+ entityTitle: 'Backstage App',
+ lifecycle: 'production',
+};
+
describe('DocsResultListItem test', () => {
it('should render search doc passed in', async () => {
const { findByText } = render();
@@ -59,4 +70,14 @@ describe('DocsResultListItem test', () => {
),
).toBeInTheDocument();
});
+
+ it('should use entity title if defined', async () => {
+ const { findByText } = render(
+ ,
+ );
+
+ expect(
+ await findByText('Documentation | Backstage App docs'),
+ ).toBeInTheDocument();
+ });
});
diff --git a/plugins/techdocs/src/components/DocsResultListItem/DocsResultListItem.tsx b/plugins/techdocs/src/components/DocsResultListItem/DocsResultListItem.tsx
index 54e6110b88..03cf011c32 100644
--- a/plugins/techdocs/src/components/DocsResultListItem/DocsResultListItem.tsx
+++ b/plugins/techdocs/src/components/DocsResultListItem/DocsResultListItem.tsx
@@ -47,7 +47,11 @@ export const DocsResultListItem = ({