2019-10-18 08:16:26 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import {
|
|
|
|
|
Route,
|
|
|
|
|
Switch,
|
|
|
|
|
withRouter,
|
|
|
|
|
RouteComponentProps,
|
|
|
|
|
} from "react-router-dom";
|
2019-11-25 09:15:11 +00:00
|
|
|
import ApiEditor from "./APIEditor";
|
2019-10-21 15:12:45 +00:00
|
|
|
import {
|
|
|
|
|
API_EDITOR_ID_URL,
|
|
|
|
|
API_EDITOR_URL,
|
2019-11-22 14:02:55 +00:00
|
|
|
BUILDER_PAGE_URL,
|
|
|
|
|
BUILDER_BASE_URL,
|
|
|
|
|
BuilderRouteParams,
|
|
|
|
|
APIEditorRouteParams,
|
2019-11-25 05:07:27 +00:00
|
|
|
} from "constants/routes";
|
2019-10-18 08:16:26 +00:00
|
|
|
import styled from "styled-components";
|
|
|
|
|
|
2019-10-29 12:02:58 +00:00
|
|
|
const Wrapper = styled.div<{ isVisible: boolean }>`
|
2019-10-18 08:16:26 +00:00
|
|
|
position: absolute;
|
2019-10-29 12:02:58 +00:00
|
|
|
top: 1px;
|
|
|
|
|
left: 1px;
|
|
|
|
|
width: 100%;
|
2019-10-18 08:16:26 +00:00
|
|
|
height: calc(100vh - ${props => props.theme.headerHeight});
|
2019-10-29 12:02:58 +00:00
|
|
|
background-color: ${props =>
|
|
|
|
|
props.isVisible ? "rgba(0, 0, 0, 0.26)" : "transparent"};
|
|
|
|
|
z-index: ${props => (props.isVisible ? 10 : -1)};
|
|
|
|
|
transition-property: z-index;
|
|
|
|
|
transition-delay: ${props => (props.isVisible ? "0" : "0.25s")};
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const DrawerWrapper = styled.div<{ isVisible: boolean }>`
|
|
|
|
|
background-color: white;
|
2019-11-13 11:34:11 +00:00
|
|
|
width: 75%;
|
2019-10-29 12:02:58 +00:00
|
|
|
height: 100%;
|
|
|
|
|
box-shadow: -1px 2px 3px 0px ${props => props.theme.colors.paneBG};
|
|
|
|
|
transform: translateX(${props => (props.isVisible ? `0` : `-80vw`)});
|
|
|
|
|
transition: 0.25s;
|
2019-10-18 08:16:26 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
interface RouterState {
|
2019-10-29 12:02:58 +00:00
|
|
|
isVisible: boolean;
|
2019-10-18 08:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
2019-11-22 14:02:55 +00:00
|
|
|
class EditorsRouter extends React.Component<
|
|
|
|
|
RouteComponentProps<BuilderRouteParams>,
|
|
|
|
|
RouterState
|
|
|
|
|
> {
|
|
|
|
|
constructor(props: RouteComponentProps<APIEditorRouteParams>) {
|
2019-10-18 08:16:26 +00:00
|
|
|
super(props);
|
2019-11-22 14:02:55 +00:00
|
|
|
const { applicationId, pageId } = this.props.match.params;
|
2019-10-18 08:16:26 +00:00
|
|
|
this.state = {
|
2019-11-22 14:02:55 +00:00
|
|
|
isVisible:
|
|
|
|
|
this.props.location.pathname !== BUILDER_BASE_URL(applicationId) &&
|
|
|
|
|
this.props.location.pathname !==
|
|
|
|
|
BUILDER_PAGE_URL(applicationId, pageId),
|
2019-10-18 08:16:26 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
componentDidUpdate(prevProps: Readonly<RouteComponentProps>): void {
|
|
|
|
|
if (this.props.location.pathname !== prevProps.location.pathname) {
|
2019-11-22 14:02:55 +00:00
|
|
|
const { applicationId, pageId } = this.props.match.params;
|
2019-10-18 08:16:26 +00:00
|
|
|
this.setState({
|
2019-11-22 14:02:55 +00:00
|
|
|
isVisible:
|
|
|
|
|
this.props.location.pathname !== BUILDER_BASE_URL(applicationId) &&
|
|
|
|
|
this.props.location.pathname !==
|
|
|
|
|
BUILDER_PAGE_URL(applicationId, pageId),
|
2019-10-18 08:16:26 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-29 12:02:58 +00:00
|
|
|
handleClose = (e: React.MouseEvent) => {
|
|
|
|
|
e.stopPropagation();
|
2019-11-22 14:02:55 +00:00
|
|
|
const { applicationId, pageId } = this.props.match.params;
|
2019-10-29 12:02:58 +00:00
|
|
|
this.setState({
|
|
|
|
|
isVisible: false,
|
|
|
|
|
});
|
2019-11-22 14:02:55 +00:00
|
|
|
this.props.history.replace(BUILDER_PAGE_URL(applicationId, pageId));
|
2019-10-29 12:02:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
preventClose = (e: React.MouseEvent) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-18 08:16:26 +00:00
|
|
|
render(): React.ReactNode {
|
|
|
|
|
return (
|
2019-10-29 12:02:58 +00:00
|
|
|
<Wrapper isVisible={this.state.isVisible} onClick={this.handleClose}>
|
|
|
|
|
<DrawerWrapper
|
|
|
|
|
isVisible={this.state.isVisible}
|
|
|
|
|
onClick={this.preventClose}
|
2019-10-18 08:16:26 +00:00
|
|
|
>
|
|
|
|
|
<Switch>
|
2019-11-22 14:02:55 +00:00
|
|
|
<Route exact path={API_EDITOR_URL()} component={ApiEditor} />
|
|
|
|
|
<Route exact path={API_EDITOR_ID_URL()} component={ApiEditor} />
|
2019-10-18 08:16:26 +00:00
|
|
|
</Switch>
|
2019-10-29 12:02:58 +00:00
|
|
|
</DrawerWrapper>
|
|
|
|
|
</Wrapper>
|
2019-10-18 08:16:26 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default withRouter(EditorsRouter);
|