Skip to content

Commit

Permalink
Revert "Sort saved objects management table by _id"
Browse files Browse the repository at this point in the history
This reverts commit d2b90749634c5f1d7daac61751a81b4f5057fc9b.
That approach unfortunately did not work due to the problem that is
described in elastic#52517.
  • Loading branch information
jportner committed Jul 13, 2020
1 parent 48884ef commit bcd7ebd
Show file tree
Hide file tree
Showing 16 changed files with 242 additions and 246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions
| [rawSearchFields](./kibana-plugin-core-public.savedobjectsfindoptions.rawsearchfields.md) | <code>string[]</code> | The fields to perform the parsed query against. Unlike the <code>searchFields</code> argument, these are expected to be raw and will not be modified. If used in conjunction with <code>searchFields</code>, both are concatenated together. |
| [search](./kibana-plugin-core-public.savedobjectsfindoptions.search.md) | <code>string</code> | Search documents using the Elasticsearch Simple Query String syntax. See Elasticsearch Simple Query String <code>query</code> argument for more information |
| [searchFields](./kibana-plugin-core-public.savedobjectsfindoptions.searchfields.md) | <code>string[]</code> | The fields to perform the parsed query against. See Elasticsearch Simple Query String <code>fields</code> argument for more information |
| [sortField](./kibana-plugin-core-public.savedobjectsfindoptions.sortfield.md) | <code>string &#124; string[]</code> | |
| [sortOrder](./kibana-plugin-core-public.savedobjectsfindoptions.sortorder.md) | <code>string &#124; string[]</code> | |
| [sortField](./kibana-plugin-core-public.savedobjectsfindoptions.sortfield.md) | <code>string</code> | |
| [sortOrder](./kibana-plugin-core-public.savedobjectsfindoptions.sortorder.md) | <code>string</code> | |
| [type](./kibana-plugin-core-public.savedobjectsfindoptions.type.md) | <code>string &#124; string[]</code> | |
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
sortField?: string | string[];
sortField?: string;
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
sortOrder?: string | string[];
sortOrder?: string;
```
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions
| [rawSearchFields](./kibana-plugin-core-server.savedobjectsfindoptions.rawsearchfields.md) | <code>string[]</code> | The fields to perform the parsed query against. Unlike the <code>searchFields</code> argument, these are expected to be raw and will not be modified. If used in conjunction with <code>searchFields</code>, both are concatenated together. |
| [search](./kibana-plugin-core-server.savedobjectsfindoptions.search.md) | <code>string</code> | Search documents using the Elasticsearch Simple Query String syntax. See Elasticsearch Simple Query String <code>query</code> argument for more information |
| [searchFields](./kibana-plugin-core-server.savedobjectsfindoptions.searchfields.md) | <code>string[]</code> | The fields to perform the parsed query against. See Elasticsearch Simple Query String <code>fields</code> argument for more information |
| [sortField](./kibana-plugin-core-server.savedobjectsfindoptions.sortfield.md) | <code>string &#124; string[]</code> | |
| [sortOrder](./kibana-plugin-core-server.savedobjectsfindoptions.sortorder.md) | <code>string &#124; string[]</code> | |
| [sortField](./kibana-plugin-core-server.savedobjectsfindoptions.sortfield.md) | <code>string</code> | |
| [sortOrder](./kibana-plugin-core-server.savedobjectsfindoptions.sortorder.md) | <code>string</code> | |
| [type](./kibana-plugin-core-server.savedobjectsfindoptions.type.md) | <code>string &#124; string[]</code> | |
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
sortField?: string | string[];
sortField?: string;
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
sortOrder?: string | string[];
sortOrder?: string;
```
4 changes: 2 additions & 2 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1302,9 +1302,9 @@ export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions {
search?: string;
searchFields?: string[];
// (undocumented)
sortField?: string | string[];
sortField?: string;
// (undocumented)
sortOrder?: string | string[];
sortOrder?: string;
// (undocumented)
type: string | string[];
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,12 @@ describe('getSearchDsl', () => {
});
}).toThrowError(/type must be specified/);
});

it('throws when sortOrder is defined and sortField is undefined', () => {
expect(() => {
getSearchDsl(mappings, registry, { type: 'foo', sortOrder: 'desc' });
}).toThrowError(/sortOrder requires a sortField/);
});

it('throws when sortOrder length is greater than sortField length', () => {
it('throws when sortOrder without sortField', () => {
expect(() => {
const options = { type: 'foo', sortField: ['bar'], sortOrder: ['baz', 'qux'] };
getSearchDsl(mappings, registry, options);
getSearchDsl(mappings, registry, {
type: 'foo',
sortOrder: 'desc',
});
}).toThrowError(/sortOrder requires a sortField/);
});
});
Expand Down Expand Up @@ -91,30 +86,22 @@ describe('getSearchDsl', () => {
});
});

describe('passes (mappings, type, sortField, sortOrder) to getSortingParams', () => {
it('with string type and undefined sortField/sortOrder', () => {
getSortingParams.mockReturnValue({});

getSearchDsl(mappings, registry, { type: 'foo' });
expect(getSortingParams).toHaveBeenCalledTimes(1);
expect(getSortingParams).toHaveBeenCalledWith(mappings, 'foo', [], []);
});

it('with strings', () => {
getSortingParams.mockReturnValue({});

getSearchDsl(mappings, registry, { type: 'foo', sortField: 'bar', sortOrder: 'baz' });
expect(getSortingParams).toHaveBeenCalledTimes(1);
expect(getSortingParams).toHaveBeenCalledWith(mappings, 'foo', ['bar'], ['baz']);
});

it('with string arrays', () => {
getSortingParams.mockReturnValue({});
it('passes (mappings, type, sortField, sortOrder) to getSortingParams', () => {
getSortingParams.mockReturnValue({});
const opts = {
type: 'foo',
sortField: 'bar',
sortOrder: 'baz',
};

getSearchDsl(mappings, registry, { type: ['foo'], sortField: ['bar'], sortOrder: ['baz'] });
expect(getSortingParams).toHaveBeenCalledTimes(1);
expect(getSortingParams).toHaveBeenCalledWith(mappings, ['foo'], ['bar'], ['baz']);
});
getSearchDsl(mappings, registry, opts);
expect(getSortingParams).toHaveBeenCalledTimes(1);
expect(getSortingParams).toHaveBeenCalledWith(
mappings,
opts.type,
opts.sortField,
opts.sortOrder
);
});

it('returns combination of getQueryParams and getSortingParams', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ interface GetSearchDslOptions {
defaultSearchOperator?: string;
searchFields?: string[];
rawSearchFields?: string[];
sortField?: string | string[];
sortOrder?: string | string[];
sortField?: string;
sortOrder?: string;
namespace?: string;
hasReference?: {
type: string;
Expand Down Expand Up @@ -64,10 +64,7 @@ export function getSearchDsl(
throw Boom.notAcceptable('type must be specified');
}

const sortFields = sortField ? (Array.isArray(sortField) ? sortField : [sortField]) : [];
const sortOrders = sortOrder ? (Array.isArray(sortOrder) ? sortOrder : [sortOrder]) : [];

if (sortOrders.length > sortFields.length) {
if (sortOrder && !sortField) {
throw Boom.notAcceptable('sortOrder requires a sortField');
}

Expand All @@ -84,6 +81,6 @@ export function getSearchDsl(
hasReference,
kueryNode,
}),
...getSortingParams(mappings, type, sortFields, sortOrders),
...getSortingParams(mappings, type, sortField, sortOrder),
};
}
Loading

0 comments on commit bcd7ebd

Please sign in to comment.