Merge pull request #24078 from aureliosaraiva/master

feat(plugins/catalog): added custom sort on createLabelColumn
This commit is contained in:
Patrik Oldsberg
2024-04-15 16:02:44 +02:00
committed by GitHub
2 changed files with 16 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog': patch
---
Fixed sorting of columns created with `CatalogTable.columns.createLabelColumn`.
@@ -184,12 +184,23 @@ export const columnFactories = Object.freeze({
key: string,
options?: { title?: string; defaultValue?: string },
): TableColumn<CatalogTableRow> {
function formatContent(keyLabel: string, entity: Entity): string {
const labels: Record<string, string> | 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<string, string> | undefined =
entity.metadata?.labels;