Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cases] Create internal API to filter cases by custom fields #170297

Merged
merged 36 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e4a7863
create searchCases route with post method
js-jankisalvi Oct 27, 2023
d6d0e22
build customFields filter 1
js-jankisalvi Nov 1, 2023
f50a616
Merge remote-tracking branch 'upstream/main' into filter-custom-field…
js-jankisalvi Nov 1, 2023
ae583d0
update filter
js-jankisalvi Nov 1, 2023
0e8b9c3
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Nov 1, 2023
7a3b3ed
rename find to search
js-jankisalvi Nov 3, 2023
d066f10
update method name
js-jankisalvi Nov 3, 2023
8e1ba81
add test for schema, combine kuqerynode
js-jankisalvi Nov 3, 2023
4d393ba
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Nov 3, 2023
35e7929
update filter, added tests
js-jankisalvi Nov 6, 2023
06decf8
updated utils test
js-jankisalvi Nov 6, 2023
e272eb0
add check for max custom fields
js-jankisalvi Nov 7, 2023
452305b
update typo
js-jankisalvi Nov 7, 2023
9afe55f
Merge remote-tracking branch 'upstream/main' into filter-custom-field…
js-jankisalvi Nov 8, 2023
b1e8c2b
add integration test
js-jankisalvi Nov 8, 2023
bfe0f3e
lint fix
js-jankisalvi Nov 8, 2023
5f74cf0
allow null to filter
js-jankisalvi Nov 8, 2023
01f33c2
Merge branch 'main' into filter-custom-fields-api
js-jankisalvi Nov 8, 2023
8925520
Merge branch 'main' into filter-custom-fields-api
js-jankisalvi Nov 9, 2023
c6d70f5
fix afterEach
js-jankisalvi Nov 9, 2023
fd45e41
clean up
js-jankisalvi Nov 9, 2023
2f976bf
update ICasesCustomField type
js-jankisalvi Nov 9, 2023
1c993c7
update comment
js-jankisalvi Nov 9, 2023
a259ed5
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Nov 9, 2023
190187e
add test for multiple selection
js-jankisalvi Nov 9, 2023
a69571c
Merge branch 'filter-custom-fields-api' of https://github.com/js-jank…
js-jankisalvi Nov 9, 2023
1ef7383
PR feedback 1
js-jankisalvi Nov 10, 2023
ad9a62a
PR feedback 2: added more integration tests, mapping check in buildCu…
js-jankisalvi Nov 10, 2023
14a64bb
add type validation to each custom field type config
js-jankisalvi Nov 10, 2023
c364147
Merge branch 'main' into filter-custom-fields-api
js-jankisalvi Nov 13, 2023
b5feaca
PR feedback
js-jankisalvi Nov 14, 2023
37861b2
throow error if multiple owners passed
js-jankisalvi Nov 14, 2023
15abde6
Merge branch 'main' into filter-custom-fields-api
js-jankisalvi Nov 14, 2023
c17dfea
Update error message, add check for empty string
js-jankisalvi Nov 14, 2023
05e0ece
lint fix
js-jankisalvi Nov 14, 2023
3ee8220
Merge branch 'main' into filter-custom-fields-api
js-jankisalvi Nov 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions x-pack/plugins/cases/common/types/api/case/v1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
CasesFindRequestSortFieldsRt,
CasesFindResponseRt,
CasesPatchRequestRt,
CasesSearchRequestRt,
} from './v1';
import { CustomFieldTypes } from '../../domain/custom_field/v1';

Expand Down Expand Up @@ -461,6 +462,50 @@ describe('CasesFindRequestRt', () => {
});
});

describe('CasesSearchRequestRt', () => {
const defaultRequest = {
tags: ['new', 'case'],
status: CaseStatuses.open,
severity: CaseSeverity.LOW,
assignees: ['damaged_racoon'],
reporters: ['damaged_racoon'],
defaultSearchOperator: 'AND',
from: 'now',
page: '1',
perPage: '10',
search: 'search text',
searchFields: ['title', 'description'],
to: '1w',
sortOrder: 'desc',
sortField: 'createdAt',
owner: 'cases',
customFields: {
toggle_custom_field_key: [true],
js-jankisalvi marked this conversation as resolved.
Show resolved Hide resolved
another_custom_field: [null, false],
text_custom_field: ['hello'],
number_custom_field: [1234],
},
};

it('has expected attributes in request', () => {
const query = CasesSearchRequestRt.decode(defaultRequest);

expect(query).toStrictEqual({
_tag: 'Right',
right: { ...defaultRequest, page: 1, perPage: 10 },
});
});

it('removes foo:bar attributes from request', () => {
const query = CasesSearchRequestRt.decode({ ...defaultRequest, foo: 'bar' });

expect(query).toStrictEqual({
_tag: 'Right',
right: { ...defaultRequest, page: 1, perPage: 10 },
});
});
});

describe('Status', () => {
describe('CasesStatusRequestRt', () => {
const defaultRequest = {
Expand Down
16 changes: 16 additions & 0 deletions x-pack/plugins/cases/common/types/api/case/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,21 @@ export const CasesFindRequestRt = rt.intersection([
paginationSchema({ maxPerPage: MAX_CASES_PER_PAGE }),
]);

export const CasesSearchRequestRt = rt.intersection([
rt.exact(
rt.partial({
/**
* custom fields of the case
*/
customFields: rt.record(
rt.string,
rt.array(rt.union([rt.string, rt.boolean, rt.number, rt.null]))
js-jankisalvi marked this conversation as resolved.
Show resolved Hide resolved
),
})
),
CasesFindRequestRt,
]);

export const CasesFindResponseRt = rt.intersection([
rt.strict({
cases: rt.array(CaseRt),
Expand Down Expand Up @@ -487,6 +502,7 @@ export type CaseResolveResponse = rt.TypeOf<typeof CaseResolveResponseRt>;
export type CasesDeleteRequest = rt.TypeOf<typeof CasesDeleteRequestRt>;
export type CasesByAlertIDRequest = rt.TypeOf<typeof CasesByAlertIDRequestRt>;
export type CasesFindRequest = rt.TypeOf<typeof CasesFindRequestRt>;
export type CasesSearchRequest = rt.TypeOf<typeof CasesSearchRequestRt>;
export type CasesFindRequestSortFields = rt.TypeOf<typeof CasesFindRequestSortFieldsRt>;
export type CasesFindResponse = rt.TypeOf<typeof CasesFindResponseRt>;
export type CasePatchRequest = rt.TypeOf<typeof CasePatchRequestRt>;
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/cases/server/client/cases/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import type { Case, Cases, User } from '../../../common/types/domain';
import type {
CasePostRequest,
CasesFindRequest,
CasesFindResponse,
CaseResolveResponse,
CasesBulkGetRequest,
Expand All @@ -20,14 +19,15 @@ import type {
CasesBulkGetResponse,
BulkCreateCasesRequest,
BulkCreateCasesResponse,
CasesSearchRequest,
} from '../../../common/types/api';
import type { CasesClient } from '../client';
import type { CasesClientInternal } from '../client_internal';
import type { CasesClientArgs } from '../types';
import { bulkGet } from './bulk_get';
import { create } from './create';
import { deleteCases } from './delete';
import { find } from './find';
import { search } from './search';
import type { CasesByAlertIDParams, GetParams } from './get';
import { get, resolve, getCasesByAlertID, getReporters, getTags, getCategories } from './get';
import type { PushParams } from './push';
Expand All @@ -52,7 +52,7 @@ export interface CasesSubClient {
*
* If the `owner` field is left empty then all the cases that the user has access to will be returned.
*/
find(params: CasesFindRequest): Promise<CasesFindResponse>;
search(params: CasesSearchRequest): Promise<CasesFindResponse>;
js-jankisalvi marked this conversation as resolved.
Show resolved Hide resolved
/**
* Retrieves a single case with the specified ID.
*/
Expand Down Expand Up @@ -111,7 +111,7 @@ export const createCasesSubClient = (
const casesSubClient: CasesSubClient = {
create: (data: CasePostRequest) => create(data, clientArgs, casesClient),
bulkCreate: (data: BulkCreateCasesRequest) => bulkCreate(data, clientArgs, casesClient),
find: (params: CasesFindRequest) => find(params, clientArgs),
search: (params: CasesSearchRequest) => search(params, clientArgs, casesClient),
get: (params: GetParams) => get(params, clientArgs),
resolve: (params: GetParams) => resolve(params, clientArgs),
bulkGet: (params) => bulkGet(params, clientArgs),
Expand Down
184 changes: 0 additions & 184 deletions x-pack/plugins/cases/server/client/cases/find.test.ts

This file was deleted.

Loading