Merge pull request #7519 from alexrybch/name-column-sort

sort and filter by `metadata.title` if present
This commit is contained in:
Fredrik Adelöw
2021-10-11 12:53:05 +02:00
committed by GitHub
3 changed files with 33 additions and 5 deletions
+6
View File
@@ -0,0 +1,6 @@
---
'@backstage/plugin-catalog': patch
'@backstage/plugin-catalog-react': patch
---
added sorting in entity `Name` column by `metadata.title` if present
@@ -20,6 +20,7 @@ import {
RELATION_OWNED_BY,
RELATION_PART_OF,
} from '@backstage/catalog-model';
import { OverflowTooltip, TableColumn } from '@backstage/core-components';
import React from 'react';
import { getEntityRelations } from '../../utils';
import {
@@ -27,7 +28,6 @@ import {
EntityRefLinks,
formatEntityRefTitle,
} from '../EntityRefLink';
import { OverflowTooltip, TableColumn } from '@backstage/core-components';
export function createEntityRefColumn<T extends Entity>({
defaultKind,
@@ -35,9 +35,12 @@ export function createEntityRefColumn<T extends Entity>({
defaultKind?: string;
}): TableColumn<T> {
function formatContent(entity: T): string {
return formatEntityRefTitle(entity, {
defaultKind,
});
return (
entity.metadata?.title ||
formatEntityRefTitle(entity, {
defaultKind,
})
);
}
return {
@@ -14,10 +14,15 @@
* limitations under the License.
*/
import React from 'react';
import { EntityRefLink, EntityRefLinks } from '@backstage/plugin-catalog-react';
import {
formatEntityRefTitle,
EntityRefLink,
EntityRefLinks,
} from '@backstage/plugin-catalog-react';
import { Chip } from '@material-ui/core';
import { EntityRow } from './types';
import { OverflowTooltip, TableColumn } from '@backstage/core-components';
import { Entity } from '@backstage/catalog-model';
type NameColumnProps = {
defaultKind?: string;
@@ -26,10 +31,24 @@ type NameColumnProps = {
export function createNameColumn(
props?: NameColumnProps,
): TableColumn<EntityRow> {
function formatContent(entity: Entity): string {
return (
entity.metadata?.title ||
formatEntityRefTitle(entity, {
defaultKind: props?.defaultKind,
})
);
}
return {
title: 'Name',
field: 'resolved.name',
highlight: true,
customSort({ entity: entity1 }, { entity: entity2 }) {
// TODO: We could implement this more efficiently by comparing field by field.
// This has similar issues as above.
return formatContent(entity1).localeCompare(formatContent(entity2));
},
render: ({ entity }) => (
<EntityRefLink
entityRef={entity}