-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cases] Enable case search by ID (#149233)
Fixes #148084 [The uuid PR was merged](#149135) so I am removing the `draft` status here. ## Summary This PR introduces search by UUID in the Cases table. If a user puts a UUID in the search bar and presses enter the search result will now return the case with that ID. Additionally, we look for the matches of that search text in the title and description fields. See the example below: <img width="1554" alt="Screenshot 2023-01-19 at 16 06 53" src="https://user-images.githubusercontent.com/1533137/213477884-498d34c0-d4d1-405d-8d76-f077d46157aa.png"> We are searching for `733e1c40-9586-11ed-a29f-8b57be9cf211`. There are two matches because that search text matches the ID of a case and the title of another. ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) ### Release notes Users can now search for Cases by ID. Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
7f2bf93
commit a04a03b
Showing
16 changed files
with
323 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { v1 as uuidv1 } from 'uuid'; | ||
|
||
import type { CaseResponse } from '../../../common/api'; | ||
|
||
import { flattenCaseSavedObject } from '../../common/utils'; | ||
import { mockCases } from '../../mocks'; | ||
import { createCasesClientMockArgs, createCasesClientMockFindRequest } from '../mocks'; | ||
import { find } from './find'; | ||
|
||
describe('find', () => { | ||
describe('constructSearch', () => { | ||
const clientArgs = createCasesClientMockArgs(); | ||
const casesMap = new Map<string, CaseResponse>( | ||
mockCases.map((obj) => { | ||
return [obj.id, flattenCaseSavedObject({ savedObject: obj, totalComment: 2 })]; | ||
}) | ||
); | ||
clientArgs.services.caseService.findCasesGroupedByID.mockResolvedValue({ | ||
page: 1, | ||
perPage: 10, | ||
total: casesMap.size, | ||
casesMap, | ||
}); | ||
clientArgs.services.caseService.getCaseStatusStats.mockResolvedValue({ | ||
open: 1, | ||
'in-progress': 2, | ||
closed: 3, | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('search by uuid updates search term and adds rootSearchFields', async () => { | ||
const search = uuidv1(); | ||
const findRequest = createCasesClientMockFindRequest({ search }); | ||
|
||
await find(findRequest, clientArgs); | ||
await expect(clientArgs.services.caseService.findCasesGroupedByID).toHaveBeenCalled(); | ||
|
||
const call = clientArgs.services.caseService.findCasesGroupedByID.mock.calls[0][0]; | ||
|
||
expect(call.caseOptions.search).toBe(`"${search}" "cases:${search}"`); | ||
expect(call.caseOptions).toHaveProperty('rootSearchFields'); | ||
expect(call.caseOptions.rootSearchFields).toStrictEqual(['_id']); | ||
}); | ||
|
||
it('regular search term does not cause rootSearchFields to be appended', async () => { | ||
const search = 'foobar'; | ||
const findRequest = createCasesClientMockFindRequest({ search }); | ||
await find(findRequest, clientArgs); | ||
await expect(clientArgs.services.caseService.findCasesGroupedByID).toHaveBeenCalled(); | ||
|
||
const call = clientArgs.services.caseService.findCasesGroupedByID.mock.calls[0][0]; | ||
|
||
expect(call.caseOptions.search).toBe(search); | ||
expect(call.caseOptions).not.toHaveProperty('rootSearchFields'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.