Skip to content

Commit

Permalink
[Enterprise Search] Add parseQueryParams helper (#83750)
Browse files Browse the repository at this point in the history
* [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
scottybollinger authored Nov 19, 2020
1 parent 6c23302 commit 40d4787
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
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';
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'] });
});
});
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' });

0 comments on commit 40d4787

Please sign in to comment.