Skip to content

Commit

Permalink
FE: Escape cluster name in API (#113)
Browse files Browse the repository at this point in the history
Co-authored-by: Roman Zabaluev <[email protected]>
  • Loading branch information
Nilumilak and Haarolean authored Mar 1, 2024
1 parent b0cf76b commit 81f73a5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
14 changes: 13 additions & 1 deletion frontend/src/lib/hooks/useAppParams.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import { Params, useParams } from 'react-router-dom';
import { ClusterNameRoute } from 'lib/paths';

export default function useAppParams<
T extends { [K in keyof Params]?: string }
>() {
return useParams<T>() as T;
const params = useParams<T>() as T;

const hasClusterName = (
checkingParams: T
): checkingParams is T & ClusterNameRoute =>
typeof checkingParams.clusterName !== 'undefined';

if (hasClusterName(params)) {
params.clusterName = decodeURIComponent(params.clusterName);
}

return params;
}
7 changes: 6 additions & 1 deletion frontend/src/lib/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ export const accessErrorPage = '/403';

export const clusterPath = (
clusterName: ClusterName = RouteParams.clusterName
) => `/ui/clusters/${clusterName}`;
) =>
`/ui/clusters/${
clusterName === RouteParams.clusterName
? clusterName
: encodeURIComponent(clusterName)
}`;

export type ClusterNameRoute = { clusterName: ClusterName };

Expand Down

0 comments on commit 81f73a5

Please sign in to comment.