-
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.
Merge branch 'ml-ts-project-refs' of github.com:peteharverson/kibana …
…into ml-ts-project-refs
- Loading branch information
Showing
26 changed files
with
515 additions
and
182 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
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
49 changes: 49 additions & 0 deletions
49
...s/enterprise_search/public/applications/app_search/utils/encode_path_params/index.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,49 @@ | ||
/* | ||
* 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 '../../../__mocks__/react_router_history.mock'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
import { encodePathParams, generateEncodedPath, useDecodedParams } from './'; | ||
|
||
describe('encodePathParams', () => { | ||
it('encodeURIComponent()s all object values', () => { | ||
const params = { | ||
someValue: 'hello world???', | ||
anotherValue: 'test!@#$%^&*[]/|;:"<>~`', | ||
}; | ||
expect(encodePathParams(params)).toEqual({ | ||
someValue: 'hello%20world%3F%3F%3F', | ||
anotherValue: 'test!%40%23%24%25%5E%26*%5B%5D%2F%7C%3B%3A%22%3C%3E~%60', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('generateEncodedPath', () => { | ||
it('generates a react router path with encoded path parameters', () => { | ||
expect( | ||
generateEncodedPath('/values/:someValue/:anotherValue/new', { | ||
someValue: 'hello world???', | ||
anotherValue: 'test!@#$%^&*[]/|;:"<>~`', | ||
}) | ||
).toEqual( | ||
'/values/hello%20world%3F%3F%3F/test!%40%23%24%25%5E%26*%5B%5D%2F%7C%3B%3A%22%3C%3E~%60/new' | ||
); | ||
}); | ||
}); | ||
|
||
describe('useDecodedParams', () => { | ||
it('decodeURIComponent()s all object values from useParams()', () => { | ||
(useParams as jest.Mock).mockReturnValue({ | ||
someValue: 'hello%20world%3F%3F%3F', | ||
anotherValue: 'test!%40%23%24%25%5E%26*%5B%5D%2F%7C%3B%3A%22%3C%3E~%60', | ||
}); | ||
expect(useDecodedParams()).toEqual({ | ||
someValue: 'hello world???', | ||
anotherValue: 'test!@#$%^&*[]/|;:"<>~`', | ||
}); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
...lugins/enterprise_search/public/applications/app_search/utils/encode_path_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,34 @@ | ||
/* | ||
* 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 { generatePath, useParams } from 'react-router-dom'; | ||
|
||
type PathParams = Record<string, string>; | ||
|
||
export const encodePathParams = (pathParams: PathParams) => { | ||
const encodedParams: PathParams = {}; | ||
|
||
Object.entries(pathParams).map(([key, value]) => { | ||
encodedParams[key] = encodeURIComponent(value); | ||
}); | ||
|
||
return encodedParams; | ||
}; | ||
|
||
export const generateEncodedPath = (path: string, pathParams: PathParams) => { | ||
return generatePath(path, encodePathParams(pathParams)); | ||
}; | ||
|
||
export const useDecodedParams = () => { | ||
const decodedParams: PathParams = {}; | ||
|
||
const params = useParams(); | ||
Object.entries(params).map(([key, value]) => { | ||
decodedParams[key] = decodeURIComponent(value as string); | ||
}); | ||
|
||
return decodedParams; | ||
}; |
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.