Skip to content
Snippets Groups Projects
Unverified Commit 12964441 authored by Alexander Lesnenko's avatar Alexander Lesnenko Committed by GitHub
Browse files

fix ModalRoute close removes last segment instead of navigating to the parent path (#17508)

parent ecf10466
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,15 @@ import { push } from "react-router-redux";
import { connect } from "react-redux";
import Modal from "metabase/components/Modal";
export const getParentPath = (route, location) => {
const fullPathSegments = location.pathname.split("/");
const routeSegments = route.path.split("/");
fullPathSegments.splice(-routeSegments.length);
return fullPathSegments.join("/");
};
const ModalWithRoute = (ComposedModal, modalProps = {}) =>
connect(
null,
......@@ -15,14 +24,10 @@ const ModalWithRoute = (ComposedModal, modalProps = {}) =>
ComposedModal.name}]`;
onClose = () => {
const {
location: { pathname },
} = this.props;
const urlWithoutLastSegment = pathname.substring(
0,
pathname.lastIndexOf("/"),
);
this.props.onChangeLocation(urlWithoutLastSegment);
const { location, route } = this.props;
const parentPath = getParentPath(route, location);
this.props.onChangeLocation(parentPath);
};
render() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment