Skip to content

Commit

Permalink
Fix URI string generation logic. (#639)
Browse files Browse the repository at this point in the history
* Fix URI string generation logic.

Signed-off-by: AWSHurneyt <[email protected]>

* Updated test.

Signed-off-by: AWSHurneyt <[email protected]>

---------

Signed-off-by: AWSHurneyt <[email protected]>
  • Loading branch information
AWSHurneyt authored Jul 13, 2023
1 parent 0e73fba commit 043881b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('clusterMetricsMonitorHelpers', () => {
uri: {
api_type: API_TYPES.CLUSTER_HEALTH.type,
path: path,
path_params: pathParams,
path_params: '/' + pathParams,
url: `http://localhost:9200/${path}/${pathParams}`,
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,18 @@ export function formikToClusterMetricsInput(values) {
if (_.isEmpty(apiType)) apiType = getApiType(_.get(values, 'uri'));
let pathParams = _.get(values, 'uri.path_params', FORMIK_INITIAL_VALUES.uri.path_params);
pathParams = _.trim(pathParams);
// Trim '/' characters from the beginning and end of the path
pathParams = pathParams?.replace(/^\/+|\/+$/g, '');
const hasPathParams = !_.isEmpty(pathParams);
const path = getApiPath(hasPathParams, apiType);
let url = FORMIK_INITIAL_VALUES.uri.url;
if (!_.isEmpty(apiType)) {
url = URL_DEFAULT_PREFIX;
if (!_.isEmpty(path)) url = url + '/' + path;
if (hasPathParams) url = url + '/' + pathParams + _.get(API_TYPES, `${apiType}.appendText`, '');
if (hasPathParams) {
pathParams = '/' + pathParams;
url = url + pathParams + _.get(API_TYPES, `${apiType}.appendText`, '');
}
}
return {
uri: {
Expand Down

0 comments on commit 043881b

Please sign in to comment.