Merge pull request #24122 from Andy2003/bugfix/ordering-in-catalog-client

Fix the `CatalogClient::getEntities` method to only sort the resulting entities in case no `order`-parameter is provided.
This commit is contained in:
Fredrik Adelöw
2024-04-09 12:44:00 +02:00
committed by GitHub
3 changed files with 16 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/catalog-client': patch
---
Fix the `CatalogClient::getEntities` method to only sort the resulting entities in case no `order`-parameter is provided.
@@ -237,6 +237,10 @@ describe('CatalogClient', () => {
it('handles ordering properly', async () => {
expect.assertions(2);
const sortedEntities = [
{ apiVersion: '1', kind: 'Component', metadata: { name: 'b' } },
{ apiVersion: '1', kind: 'Component', metadata: { name: 'a' } },
];
server.use(
rest.get(`${mockBaseUrl}/entities`, (req, res, ctx) => {
@@ -245,7 +249,7 @@ describe('CatalogClient', () => {
'asc:kind',
'desc:metadata.name',
]);
return res(ctx.json([]));
return res(ctx.json(sortedEntities));
}),
);
@@ -259,7 +263,7 @@ describe('CatalogClient', () => {
{ token },
);
expect(response.items).toEqual([]);
expect(response.items).toEqual(sortedEntities);
});
});
@@ -143,6 +143,11 @@ export class CatalogClient implements CatalogApi {
),
);
// do not sort entities, if order is provided
if (encodedOrder.length) {
return { items: entities };
}
const refCompare = (a: Entity, b: Entity) => {
// in case field filtering is used, these fields might not be part of the response
if (