diff --git a/.changeset/slow-cows-worry.md b/.changeset/slow-cows-worry.md new file mode 100644 index 0000000000..2dc57e97b2 --- /dev/null +++ b/.changeset/slow-cows-worry.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog': patch +--- + +Fixed sorting of columns created with `CatalogTable.columns.createLabelColumn`. diff --git a/plugins/catalog/src/components/CatalogTable/columns.tsx b/plugins/catalog/src/components/CatalogTable/columns.tsx index 86e8ced86a..d5362badda 100644 --- a/plugins/catalog/src/components/CatalogTable/columns.tsx +++ b/plugins/catalog/src/components/CatalogTable/columns.tsx @@ -184,12 +184,23 @@ export const columnFactories = Object.freeze({ key: string, options?: { title?: string; defaultValue?: string }, ): TableColumn { + function formatContent(keyLabel: string, entity: Entity): string { + const labels: Record | undefined = + entity.metadata?.labels; + return (labels && labels[keyLabel]) || ''; + } + return { title: options?.title || 'Label', field: 'entity.metadata.labels', cellStyle: { padding: '0px 16px 0px 20px', }, + customSort({ entity: entity1 }, { entity: entity2 }) { + return formatContent(key, entity1).localeCompare( + formatContent(key, entity2), + ); + }, render: ({ entity }: { entity: Entity }) => { const labels: Record | undefined = entity.metadata?.labels;