-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enterprise Search] Add parseQueryParams helper (#83750)
* [Enterprise Search] Add parseQueryParams helper This PR migrates part of the ent-search queryParams util, `parseQueryParams` for use in Workplace Search. `setQueryParams` was no a part of this PR because it is only used one time in App Search and a better alternative might be available for that use-case * Remove mock * Actually test functionality of query-string * Add test for array * Better test name
- Loading branch information
1 parent
6c23302
commit 40d4787
Showing
3 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
x-pack/plugins/enterprise_search/public/applications/shared/query_params/index.ts
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,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { parseQueryParams } from './query_params'; |
14 changes: 14 additions & 0 deletions
14
...ck/plugins/enterprise_search/public/applications/shared/query_params/query_params.test.ts
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,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { parseQueryParams } from './'; | ||
|
||
describe('parseQueryParams', () => { | ||
it('parse query strings', () => { | ||
expect(parseQueryParams('?foo=bar')).toEqual({ foo: 'bar' }); | ||
expect(parseQueryParams('?foo[]=bar&foo[]=baz')).toEqual({ foo: ['bar', 'baz'] }); | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
x-pack/plugins/enterprise_search/public/applications/shared/query_params/query_params.ts
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,10 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import queryString from 'query-string'; | ||
|
||
export const parseQueryParams = (search: string) => | ||
queryString.parse(search, { arrayFormat: 'bracket' }); |