Fix the CatalogClient::getEntities method to only sort the resulting entities in case no order-parameter is provided.
Signed-off-by: Andreas Berger <andreas@berger-ecommerce.com>
This commit is contained in:
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user