catalog-backend: reuse EntityOrderQuery
Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
@@ -46,12 +46,6 @@ export type EntityOrder = {
|
||||
order: 'asc' | 'desc';
|
||||
};
|
||||
|
||||
// TODO(vinzscam): remove this type in favor of EntityOrder
|
||||
export type EntitySortField = {
|
||||
field: string;
|
||||
order?: 'asc' | 'desc' | undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Matches rows in the search table.
|
||||
* @public
|
||||
@@ -240,7 +234,7 @@ export interface PaginatedEntitiesInitialRequest {
|
||||
fields?: (entity: Entity) => Entity;
|
||||
limit?: number;
|
||||
filter?: EntityFilter;
|
||||
sortFields?: EntitySortField[];
|
||||
sortFields?: EntityOrder[];
|
||||
query?: string;
|
||||
}
|
||||
|
||||
@@ -291,7 +285,7 @@ export type Cursor = {
|
||||
* An array of fields used for sorting the data.
|
||||
* For example, [ { field: 'metadata.name', order: 'asc' } ]
|
||||
*/
|
||||
sortFields: EntitySortField[];
|
||||
sortFields: EntityOrder[];
|
||||
/**
|
||||
* The values of the fields of a specific item used for paginating the data.
|
||||
*/
|
||||
|
||||
@@ -767,7 +767,7 @@ describe('DefaultEntitiesCatalog', () => {
|
||||
const request1: PaginatedEntitiesInitialRequest = {
|
||||
filter,
|
||||
limit,
|
||||
sortFields: [{ field: 'metadata.name' }],
|
||||
sortFields: [{ field: 'metadata.name', order: 'asc' }],
|
||||
};
|
||||
const response1 = await catalog.paginatedEntities(request1);
|
||||
expect(response1.entities).toEqual([entityFrom('A'), entityFrom('B')]);
|
||||
@@ -1056,7 +1056,7 @@ describe('DefaultEntitiesCatalog', () => {
|
||||
filter,
|
||||
limit: 100,
|
||||
|
||||
sortFields: [{ field: 'metadata.name' }],
|
||||
sortFields: [{ field: 'metadata.name', order: 'asc' }],
|
||||
query: 'cAt ',
|
||||
};
|
||||
const response = await catalog.paginatedEntities(request);
|
||||
@@ -1127,7 +1127,7 @@ describe('DefaultEntitiesCatalog', () => {
|
||||
// initial request
|
||||
const request1: PaginatedEntitiesInitialRequest = {
|
||||
limit,
|
||||
sortFields: [{ field: 'metadata.name' }],
|
||||
sortFields: [{ field: 'metadata.name', order: 'asc' }],
|
||||
};
|
||||
const response1 = await catalog.paginatedEntities(request1);
|
||||
expect(response1.entities).toMatchObject([
|
||||
|
||||
@@ -36,9 +36,9 @@ import {
|
||||
EntityFacetsResponse,
|
||||
EntityFilter,
|
||||
EntityPagination,
|
||||
EntitySortField,
|
||||
PaginatedEntitiesRequest,
|
||||
PaginatedEntitiesResponse,
|
||||
EntityOrder,
|
||||
} from '../catalog/types';
|
||||
import {
|
||||
DbFinalEntitiesRow,
|
||||
@@ -56,7 +56,7 @@ import {
|
||||
isPaginatedEntitiesInitialRequest,
|
||||
} from './util';
|
||||
|
||||
const defaultSortField: EntitySortField = {
|
||||
const defaultSortField: EntityOrder = {
|
||||
field: 'metadata.uid',
|
||||
order: 'asc',
|
||||
};
|
||||
@@ -351,7 +351,7 @@ export class DefaultEntitiesCatalog implements EntitiesCatalog {
|
||||
this.logger.warn(`Only one sort field is supported, ignoring the rest`);
|
||||
}
|
||||
|
||||
const sortField: EntitySortField = {
|
||||
const sortField: EntityOrder = {
|
||||
...defaultSortField,
|
||||
...cursor.sortFields[0],
|
||||
};
|
||||
@@ -683,7 +683,7 @@ function parseCursorFromRequest(
|
||||
return {};
|
||||
}
|
||||
|
||||
function invertOrder(order: EntitySortField['order']) {
|
||||
function invertOrder(order: EntityOrder['order']) {
|
||||
return order === 'asc' ? 'desc' : 'asc';
|
||||
}
|
||||
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
|
||||
import { InputError } from '@backstage/errors';
|
||||
import { EntitySortField } from '../../catalog/types';
|
||||
import { EntityOrder } from '../../catalog/types';
|
||||
import { parseStringsParam } from './common';
|
||||
|
||||
export function parseEntitySortFieldParams(
|
||||
params: Record<string, unknown>,
|
||||
): EntitySortField[] | undefined {
|
||||
): EntityOrder[] | undefined {
|
||||
const sortFieldStrings = parseStringsParam(params.sortField, 'sortField');
|
||||
if (!sortFieldStrings) {
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user