2019-10-18 08:16:26 +00:00
|
|
|
import React, { Component } from "react";
|
2019-12-03 09:21:06 +00:00
|
|
|
import { Helmet } from "react-helmet";
|
2019-09-09 10:30:22 +00:00
|
|
|
import { connect } from "react-redux";
|
2019-11-22 14:02:55 +00:00
|
|
|
import { Redirect } from "react-router-dom";
|
|
|
|
|
import { withRouter, RouteComponentProps } from "react-router-dom";
|
|
|
|
|
import {
|
|
|
|
|
BuilderRouteParams,
|
|
|
|
|
getApplicationViewerPageURL,
|
|
|
|
|
BUILDER_PAGE_URL,
|
|
|
|
|
} from "constants/routes";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { AppState } from "reducers";
|
2019-09-09 10:30:22 +00:00
|
|
|
import EditorHeader from "./EditorHeader";
|
2019-10-29 12:02:58 +00:00
|
|
|
import MainContainer from "./MainContainer";
|
2020-04-16 11:56:36 +00:00
|
|
|
import { DndProvider } from "react-dnd";
|
2020-04-21 14:19:12 +00:00
|
|
|
import TouchBackend from "react-dnd-touch-backend";
|
2019-10-24 09:23:50 +00:00
|
|
|
import {
|
|
|
|
|
getCurrentApplicationId,
|
|
|
|
|
getCurrentPageId,
|
2019-10-31 08:36:04 +00:00
|
|
|
getPageList,
|
|
|
|
|
getIsPublishingApplication,
|
|
|
|
|
getPublishingError,
|
|
|
|
|
getIsPageSaving,
|
2019-11-22 14:02:55 +00:00
|
|
|
getIsEditorLoading,
|
|
|
|
|
getLoadingError,
|
2020-01-24 09:54:40 +00:00
|
|
|
getIsEditorInitialized,
|
2019-11-22 14:02:55 +00:00
|
|
|
} from "selectors/editorSelectors";
|
2019-10-31 08:36:04 +00:00
|
|
|
import {
|
|
|
|
|
ReduxActionTypes,
|
|
|
|
|
PageListPayload,
|
2020-07-23 12:28:42 +00:00
|
|
|
ApplicationPayload,
|
2019-11-22 14:02:55 +00:00
|
|
|
} from "constants/ReduxActionConstants";
|
2019-10-31 08:36:04 +00:00
|
|
|
import { Dialog, Classes, AnchorButton } from "@blueprintjs/core";
|
2019-11-22 14:02:55 +00:00
|
|
|
import { initEditor } from "actions/initActions";
|
2020-03-27 09:02:11 +00:00
|
|
|
import { RenderModes } from "constants/WidgetConstants";
|
2020-03-06 04:59:24 +00:00
|
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
2020-03-24 14:05:19 +00:00
|
|
|
import { fetchPage } from "actions/pageActions";
|
2020-04-16 11:56:36 +00:00
|
|
|
import { editorInitializer } from "utils/EditorUtils";
|
2020-08-03 09:14:08 +00:00
|
|
|
import { getCurrentOrgId } from "selectors/organizationSelectors";
|
2019-08-20 13:19:19 +00:00
|
|
|
|
2019-08-29 11:22:09 +00:00
|
|
|
type EditorProps = {
|
2019-11-22 14:02:55 +00:00
|
|
|
currentPageName?: string;
|
2019-09-23 10:27:45 +00:00
|
|
|
isSaving: boolean;
|
2020-08-03 09:14:08 +00:00
|
|
|
currentOrgId: string;
|
2019-10-24 09:23:50 +00:00
|
|
|
currentApplicationId?: string;
|
2019-11-22 14:02:55 +00:00
|
|
|
currentPageId?: string;
|
2019-10-24 09:23:50 +00:00
|
|
|
publishApplication: Function;
|
|
|
|
|
previewPage: Function;
|
2019-11-08 11:02:00 +00:00
|
|
|
initEditor: Function;
|
2019-10-31 08:36:04 +00:00
|
|
|
createPage: Function;
|
2020-03-24 14:05:19 +00:00
|
|
|
fetchPage: (pageId: string) => void;
|
2019-10-31 08:36:04 +00:00
|
|
|
pages: PageListPayload;
|
|
|
|
|
isPublishing: boolean;
|
2019-11-22 14:02:55 +00:00
|
|
|
isEditorLoading: boolean;
|
2020-01-24 09:54:40 +00:00
|
|
|
isEditorInitialized: boolean;
|
2019-11-22 14:02:55 +00:00
|
|
|
editorLoadingError: boolean;
|
2019-10-31 08:36:04 +00:00
|
|
|
errorPublishing: boolean;
|
2020-03-27 09:02:11 +00:00
|
|
|
createModal: () => void;
|
2020-07-23 12:28:42 +00:00
|
|
|
currentApplication?: ApplicationPayload;
|
2019-11-22 14:02:55 +00:00
|
|
|
} & RouteComponentProps<BuilderRouteParams>;
|
2019-08-26 12:41:21 +00:00
|
|
|
|
2019-08-29 11:22:09 +00:00
|
|
|
class Editor extends Component<EditorProps> {
|
2019-10-31 08:36:04 +00:00
|
|
|
public state = {
|
|
|
|
|
isDialogOpen: false,
|
2020-04-16 11:56:36 +00:00
|
|
|
registered: false,
|
2019-10-31 08:36:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
2020-04-16 11:56:36 +00:00
|
|
|
editorInitializer().then(() => {
|
|
|
|
|
this.setState({ registered: true });
|
|
|
|
|
});
|
2020-03-24 14:05:19 +00:00
|
|
|
const { applicationId, pageId } = this.props.match.params;
|
|
|
|
|
if (applicationId && pageId) {
|
|
|
|
|
this.props.initEditor(applicationId, pageId);
|
2019-10-31 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-11-22 14:02:55 +00:00
|
|
|
componentDidUpdate(previously: EditorProps) {
|
2019-11-26 10:45:46 +00:00
|
|
|
if (
|
|
|
|
|
previously.isPublishing &&
|
2020-04-05 06:34:14 +00:00
|
|
|
!(this.props.isPublishing || this.props.errorPublishing)
|
2019-11-26 10:45:46 +00:00
|
|
|
) {
|
|
|
|
|
this.setState({
|
|
|
|
|
isDialogOpen: true,
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-03-24 14:05:19 +00:00
|
|
|
if (this.props.match.params.pageId !== previously.match.params.pageId) {
|
|
|
|
|
this.props.fetchPage(this.props.match.params.pageId);
|
|
|
|
|
}
|
2019-11-22 14:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-31 08:36:04 +00:00
|
|
|
handleDialogClose = () => {
|
|
|
|
|
this.setState({
|
|
|
|
|
isDialogOpen: false,
|
|
|
|
|
});
|
|
|
|
|
};
|
2019-10-24 09:23:50 +00:00
|
|
|
handlePublish = () => {
|
2019-10-31 08:36:04 +00:00
|
|
|
if (this.props.currentApplicationId) {
|
2019-10-24 09:23:50 +00:00
|
|
|
this.props.publishApplication(this.props.currentApplicationId);
|
2020-03-06 04:59:24 +00:00
|
|
|
|
|
|
|
|
const appName = this.props.currentApplication
|
|
|
|
|
? this.props.currentApplication.name
|
|
|
|
|
: "";
|
|
|
|
|
AnalyticsUtil.logEvent("PUBLISH_APP", {
|
|
|
|
|
appId: this.props.currentApplicationId,
|
|
|
|
|
appName: appName,
|
|
|
|
|
});
|
2019-10-31 08:36:04 +00:00
|
|
|
}
|
2019-10-24 09:23:50 +00:00
|
|
|
};
|
2019-10-31 08:36:04 +00:00
|
|
|
handleCreatePage = (pageName: string) => {
|
|
|
|
|
this.props.createPage(this.props.currentApplicationId, pageName);
|
2019-10-24 09:23:50 +00:00
|
|
|
};
|
2019-11-22 14:02:55 +00:00
|
|
|
redirectToPage = (pageId: string) => {
|
|
|
|
|
if (this.props.currentApplicationId) {
|
|
|
|
|
this.props.history.push(
|
|
|
|
|
BUILDER_PAGE_URL(this.props.currentApplicationId, pageId),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-08-29 11:22:09 +00:00
|
|
|
public render() {
|
2019-11-22 14:02:55 +00:00
|
|
|
if (!this.props.match.params.applicationId) {
|
|
|
|
|
return <Redirect to="/applications" />;
|
|
|
|
|
}
|
2019-02-07 05:07:09 +00:00
|
|
|
return (
|
2020-04-16 11:56:36 +00:00
|
|
|
<DndProvider
|
2020-04-21 14:19:12 +00:00
|
|
|
backend={TouchBackend}
|
|
|
|
|
options={{
|
|
|
|
|
enableMouseEvents: true,
|
|
|
|
|
}}
|
2020-04-16 11:56:36 +00:00
|
|
|
>
|
|
|
|
|
<div>
|
|
|
|
|
<Helmet>
|
|
|
|
|
<meta charSet="utf-8" />
|
|
|
|
|
<title>Editor | Appsmith</title>
|
|
|
|
|
</Helmet>
|
|
|
|
|
<EditorHeader
|
|
|
|
|
isSaving={this.props.isSaving}
|
|
|
|
|
pageName={this.props.currentPageName}
|
|
|
|
|
onPublish={this.handlePublish}
|
|
|
|
|
onCreatePage={this.handleCreatePage}
|
|
|
|
|
pages={this.props.pages}
|
|
|
|
|
currentPageId={this.props.currentPageId}
|
|
|
|
|
currentApplicationId={this.props.currentApplicationId}
|
2020-07-23 12:28:42 +00:00
|
|
|
currentApplication={this.props.currentApplication}
|
2020-04-16 11:56:36 +00:00
|
|
|
isPublishing={this.props.isPublishing}
|
|
|
|
|
createModal={this.props.createModal}
|
2020-08-03 09:14:08 +00:00
|
|
|
orgId={this.props.currentOrgId}
|
2020-04-16 11:56:36 +00:00
|
|
|
/>
|
|
|
|
|
<MainContainer />
|
|
|
|
|
<Dialog
|
|
|
|
|
isOpen={this.state.isDialogOpen}
|
|
|
|
|
canOutsideClickClose={true}
|
|
|
|
|
canEscapeKeyClose={true}
|
|
|
|
|
title="Application Published"
|
|
|
|
|
onClose={this.handleDialogClose}
|
|
|
|
|
icon="tick-circle"
|
|
|
|
|
>
|
|
|
|
|
<div className={Classes.DIALOG_BODY}>
|
|
|
|
|
<p>
|
|
|
|
|
{
|
|
|
|
|
"Your awesome application is now published with the current changes!"
|
|
|
|
|
}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div className={Classes.DIALOG_FOOTER}>
|
|
|
|
|
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
|
|
|
|
|
<AnchorButton
|
|
|
|
|
target={this.props.currentApplicationId}
|
|
|
|
|
href={getApplicationViewerPageURL(
|
|
|
|
|
this.props.currentApplicationId,
|
|
|
|
|
this.props.currentPageId,
|
|
|
|
|
)}
|
|
|
|
|
text="View Application"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2019-10-31 08:36:04 +00:00
|
|
|
</div>
|
2020-04-16 11:56:36 +00:00
|
|
|
</Dialog>
|
|
|
|
|
</div>
|
|
|
|
|
</DndProvider>
|
2019-09-09 10:30:22 +00:00
|
|
|
);
|
2019-02-07 05:07:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-24 09:23:50 +00:00
|
|
|
const mapStateToProps = (state: AppState) => ({
|
2019-10-18 08:16:26 +00:00
|
|
|
currentPageName: state.ui.editor.currentPageName,
|
2019-10-31 08:36:04 +00:00
|
|
|
isSaving: getIsPageSaving(state),
|
2020-08-03 09:14:08 +00:00
|
|
|
currentOrgId: getCurrentOrgId(state),
|
2019-10-24 09:23:50 +00:00
|
|
|
currentApplicationId: getCurrentApplicationId(state),
|
2020-07-23 12:28:42 +00:00
|
|
|
currentApplication: state.ui.applications.currentApplication,
|
2019-10-24 09:23:50 +00:00
|
|
|
currentPageId: getCurrentPageId(state),
|
2019-10-31 08:36:04 +00:00
|
|
|
pages: getPageList(state),
|
|
|
|
|
errorPublishing: getPublishingError(state),
|
|
|
|
|
isPublishing: getIsPublishingApplication(state),
|
2019-11-22 14:02:55 +00:00
|
|
|
isEditorLoading: getIsEditorLoading(state),
|
2020-01-24 09:54:40 +00:00
|
|
|
isEditorInitialized: getIsEditorInitialized(state),
|
2019-11-22 14:02:55 +00:00
|
|
|
editorLoadingError: getLoadingError(state),
|
2019-10-18 08:16:26 +00:00
|
|
|
});
|
2019-08-26 12:41:21 +00:00
|
|
|
|
2019-10-24 09:23:50 +00:00
|
|
|
const mapDispatchToProps = (dispatch: any) => {
|
|
|
|
|
return {
|
2020-03-24 14:05:19 +00:00
|
|
|
initEditor: (applicationId: string, pageId: string) =>
|
|
|
|
|
dispatch(initEditor(applicationId, pageId)),
|
2019-10-24 09:23:50 +00:00
|
|
|
publishApplication: (applicationId: string) => {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: ReduxActionTypes.PUBLISH_APPLICATION_INIT,
|
|
|
|
|
payload: {
|
|
|
|
|
applicationId,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
previewPage: (pageId: string, layoutId: string) => {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: ReduxActionTypes.FETCH_PUBLISHED_PAGE_INIT,
|
|
|
|
|
payload: {
|
|
|
|
|
pageId,
|
|
|
|
|
layoutId,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
},
|
2020-03-24 14:05:19 +00:00
|
|
|
fetchPage: (pageId: string) => dispatch(fetchPage(pageId)),
|
2019-10-31 08:36:04 +00:00
|
|
|
createPage: (applicationId: string, name: string) => {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: ReduxActionTypes.CREATE_PAGE_INIT,
|
|
|
|
|
payload: {
|
|
|
|
|
applicationId,
|
|
|
|
|
name,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
},
|
2020-03-27 09:02:11 +00:00
|
|
|
// TODO(abhinav): get the render mode from context
|
|
|
|
|
createModal: () =>
|
|
|
|
|
dispatch({
|
|
|
|
|
type: ReduxActionTypes.CREATE_MODAL_INIT,
|
|
|
|
|
payload: {
|
|
|
|
|
renderMode: RenderModes.CANVAS,
|
|
|
|
|
},
|
|
|
|
|
}),
|
2019-10-24 09:23:50 +00:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2019-11-22 14:02:55 +00:00
|
|
|
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Editor));
|