From 16a40ac4c058e774981dc7866491f589f1d1d5c6 Mon Sep 17 00:00:00 2001 From: djamaile Date: Wed, 13 Apr 2022 16:51:36 +0200 Subject: [PATCH 1/2] chore: update getDocumentText function to also return the displayName if the entity is of type group Signed-off-by: djamaile --- .changeset/chatty-pears-nail.md | 5 +++++ .../catalog-backend/src/search/DefaultCatalogCollator.ts | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changeset/chatty-pears-nail.md diff --git a/.changeset/chatty-pears-nail.md b/.changeset/chatty-pears-nail.md new file mode 100644 index 0000000000..548e89ec1a --- /dev/null +++ b/.changeset/chatty-pears-nail.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend': patch +--- + +When retrieving the text of a document also check if the entity is of type group. The function will then also return the display name and the description and not only the description. diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts index bb44670443..ef3886aea6 100644 --- a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts +++ b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts @@ -22,6 +22,7 @@ import { Entity, stringifyEntityRef, UserEntity, + GroupEntity, } from '@backstage/catalog-model'; import { Config } from '@backstage/config'; import { @@ -97,9 +98,13 @@ export class DefaultCatalogCollator { return entity.kind.toLocaleUpperCase('en-US') === 'USER'; } + private isGroupEntity(entity: Entity): entity is GroupEntity { + return entity.kind.toLocaleUpperCase('en-US') === 'GROUP'; + } + private getDocumentText(entity: Entity): string { let documentText = entity.metadata.description || ''; - if (this.isUserEntity(entity)) { + if (this.isUserEntity(entity) || this.isGroupEntity(entity)) { if (entity.spec?.profile?.displayName && documentText) { // combine displayName and description const displayName = entity.spec?.profile?.displayName; From ddfc49bcd29c1994c7c0cae914cbf3ff99ec55ef Mon Sep 17 00:00:00 2001 From: djamaile Date: Thu, 14 Apr 2022 10:15:12 +0200 Subject: [PATCH 2/2] chore: move code because DefaultCatalogCollator is deprecated Signed-off-by: djamaile --- .changeset/chatty-pears-nail.md | 2 +- .../catalog-backend/src/search/DefaultCatalogCollator.ts | 7 +------ plugins/catalog-backend/src/search/util.ts | 4 ++-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.changeset/chatty-pears-nail.md b/.changeset/chatty-pears-nail.md index 548e89ec1a..646841fb58 100644 --- a/.changeset/chatty-pears-nail.md +++ b/.changeset/chatty-pears-nail.md @@ -2,4 +2,4 @@ '@backstage/plugin-catalog-backend': patch --- -When retrieving the text of a document also check if the entity is of type group. The function will then also return the display name and the description and not only the description. +Fix wrong return type of the `isGroupEntity` function. diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts index ef3886aea6..bb44670443 100644 --- a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts +++ b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts @@ -22,7 +22,6 @@ import { Entity, stringifyEntityRef, UserEntity, - GroupEntity, } from '@backstage/catalog-model'; import { Config } from '@backstage/config'; import { @@ -98,13 +97,9 @@ export class DefaultCatalogCollator { return entity.kind.toLocaleUpperCase('en-US') === 'USER'; } - private isGroupEntity(entity: Entity): entity is GroupEntity { - return entity.kind.toLocaleUpperCase('en-US') === 'GROUP'; - } - private getDocumentText(entity: Entity): string { let documentText = entity.metadata.description || ''; - if (this.isUserEntity(entity) || this.isGroupEntity(entity)) { + if (this.isUserEntity(entity)) { if (entity.spec?.profile?.displayName && documentText) { // combine displayName and description const displayName = entity.spec?.profile?.displayName; diff --git a/plugins/catalog-backend/src/search/util.ts b/plugins/catalog-backend/src/search/util.ts index 7e7ce7064e..b5df2a28a7 100644 --- a/plugins/catalog-backend/src/search/util.ts +++ b/plugins/catalog-backend/src/search/util.ts @@ -14,13 +14,13 @@ * limitations under the License. */ -import { Entity, UserEntity } from '@backstage/catalog-model'; +import { Entity, UserEntity, GroupEntity } from '@backstage/catalog-model'; function isUserEntity(entity: Entity): entity is UserEntity { return entity.kind.toLocaleUpperCase('en-US') === 'USER'; } -function isGroupEntity(entity: Entity): entity is UserEntity { +function isGroupEntity(entity: Entity): entity is GroupEntity { return entity.kind.toLocaleUpperCase('en-US') === 'GROUP'; }