From f55c195f039802376a753ee9adad6e84f953e1f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Mon, 30 Mar 2026 21:42:51 +0200 Subject: [PATCH] Use lodash sortBy for entity sorting to avoid repeated presentation lookups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: Fredrik Adelöw --- .../src/components/CatalogTable/CatalogTable.tsx | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx b/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx index a57a5f3d31..6c55ff21a3 100644 --- a/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx +++ b/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx @@ -42,7 +42,7 @@ import Typography from '@material-ui/core/Typography'; import { visuallyHidden } from '@mui/utils'; import Edit from '@material-ui/icons/Edit'; import OpenInNew from '@material-ui/icons/OpenInNew'; -import { capitalize } from 'lodash'; +import { capitalize, sortBy } from 'lodash'; import pluralize from 'pluralize'; import { ReactNode, useMemo } from 'react'; import { columnFactories } from './columns'; @@ -86,10 +86,8 @@ function getTitle( return defaultEntityPresentation(entityOrRef, context).primaryTitle; } -const refCompare = (a: Entity, b: Entity, api?: EntityPresentationApi) => { - return getTitle(a, { defaultKind: 'Component' }, api).localeCompare( - getTitle(b, { defaultKind: 'Component' }, api), - ); +const sortEntities = (entities: Entity[], api?: EntityPresentationApi) => { + return sortBy(entities, e => getTitle(e, { defaultKind: 'Component' }, api)); }; /** @@ -269,9 +267,9 @@ export const CatalogTable = (props: CatalogTableProps) => { ); } - const rows = entities - .sort((a, b) => refCompare(a, b, entityPresentationApi)) - .map(e => toEntityRow(e, entityPresentationApi)); + const rows = sortEntities(entities, entityPresentationApi).map(e => + toEntityRow(e, entityPresentationApi), + ); const pageSize = 20; const showPagination = rows.length > pageSize;