Fix/chart-link-cluster-mode (#474)

This commit is contained in:
Nir Parisian
2023-10-02 19:10:04 +03:00
committed by GitHub
parent 88ea89a5ba
commit c251e6c697
19 changed files with 157 additions and 170 deletions

View File

@@ -1,4 +1,5 @@
import { NavLink, useLocation } from "react-router-dom";
import { NavLink, useLocation, useParams } from "react-router-dom";
import { useAppContext } from "../context/AppContext";
const LinkWithSearchParams = ({
to,
@@ -11,14 +12,22 @@ const LinkWithSearchParams = ({
children: React.ReactNode;
}) => {
const { search } = useLocation();
const params = new URLSearchParams(search);
const { context } = useParams();
const {clusterMode} = useAppContext();
const params = new URLSearchParams(search);
// For state we don't want to keep while navigating
props.exclude?.forEach((key) => {
params.delete(key);
});
return <NavLink to={`${to}/?${params.toString()}`} {...props} />;
let prefixedUrl = to;
if (!clusterMode) {
prefixedUrl = `/${context}${to}`;
}
return <NavLink to={`${prefixedUrl}/?${params.toString()}`} {...props} />;
};
export default LinkWithSearchParams;