Move Registration to application editor

This commit is contained in:
Abhinav Jha 2020-04-16 17:26:36 +05:30
parent 0b87848baf
commit 87b1554e10
9 changed files with 169 additions and 148 deletions

View File

@ -107,6 +107,7 @@
"start": "REACT_APP_BASE_URL=https://release-api.appsmith.com REACT_APP_ENVIRONMENT=DEVELOPMENT HOST=dev.appsmith.com craco start",
"build": "./build.sh",
"build-local": "craco --max-old-space-size=4096 build --config craco.build.config.js",
"build-staging": "REACT_APP_BASE_URL=https://release-api.appsmith.com REACT_APP_ENVIRONMENT=STAGING craco --max-old-space-size=4096 build --config craco.build.config.js",
"test": "cypress/test.sh",
"eject": "react-scripts eject",
"start-prod": "REACT_APP_BASE_URL=https://api.appsmith.com REACT_APP_ENVIRONMENT=PRODUCTION craco start",

View File

@ -0,0 +1 @@
export default null;

View File

@ -4,12 +4,10 @@ import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import Loader from "pages/common/Loader";
import "./index.css";
import * as serviceWorker from "./serviceWorker";
// import * as serviceWorker from "./serviceWorker";
import { Router, Switch, Redirect } from "react-router-dom";
import history from "./utils/history";
import { ThemeProvider, theme } from "constants/DefaultTheme";
import { DndProvider } from "react-dnd";
import TouchBackend from "react-dnd-touch-backend";
import { appInitializer } from "utils/AppsmithUtils";
import AppRoute from "./pages/common/AppRoute";
@ -31,96 +29,99 @@ import {
const loadingIndicator = <Loader />;
const App = lazy(() => import("./App"));
const UserAuth = lazy(() => import("./pages/UserAuth"));
const Editor = lazy(() => import("./pages/Editor"));
const Applications = lazy(() => import("./pages/Applications"));
const PageNotFound = lazy(() => import("./pages/common/PageNotFound"));
const AppViewer = lazy(() => import("./pages/AppViewer"));
const Organization = lazy(() => import("./pages/organization"));
const Users = lazy(() => import("./pages/users"));
const UserAuth = lazy(() =>
import(/* webpackPrefetch: 5 */ "./pages/UserAuth"),
);
const Editor = lazy(() => import(/* webpackPrefetch: 3 */ "./pages/Editor"));
const Applications = lazy(() =>
import(/* webpackPrefetch: 4 */ "./pages/Applications"),
);
const PageNotFound = lazy(() =>
import(/* webpackPrefetch: true */ "./pages/common/PageNotFound"),
);
const AppViewer = lazy(() =>
import(/* webpackPrefetch: 2 */ "./pages/AppViewer"),
);
const Organization = lazy(() =>
import(/* webpackPrefetch: 1 */ "./pages/organization"),
);
const Users = lazy(() => import(/* webpackPrefetch: true */ "./pages/users"));
appInitializer();
ReactDOM.render(
<DndProvider
backend={TouchBackend}
options={{
enableMouseEvents: true,
}}
>
<Provider store={store}>
<ThemeProvider theme={theme}>
<ToastContainer
hideProgressBar
draggable={false}
transition={Slide}
autoClose={5000}
closeButton={false}
/>
<Helmet>
<meta charSet="utf-8" />
<link rel="shortcut icon" href="/favicon-orange.ico" />
</Helmet>
<Router history={history}>
<Suspense fallback={loadingIndicator}>
<Switch>
<AppRoute
exact
path={BASE_URL}
component={App}
name={"App"}
routeProtected
/>
<AppRoute
path={ORG_URL}
component={Organization}
name={"Organisation"}
routeProtected
/>
<AppRoute
exact
path={USERS_URL}
component={Users}
name={"Users"}
routeProtected
/>
<AppRoute
path={USER_AUTH_URL}
component={UserAuth}
name={"UserAuth"}
/>
<Redirect exact from={BASE_LOGIN_URL} to={AUTH_LOGIN_URL} />
<Redirect exact from={BASE_SIGNUP_URL} to={SIGN_UP_URL} />
<AppRoute
exact
path={APPLICATIONS_URL}
component={Applications}
name={"Home"}
routeProtected
/>
<AppRoute
path={BUILDER_URL}
component={Editor}
name={"Editor"}
routeProtected
/>
<AppRoute
path={APP_VIEW_URL}
component={AppViewer}
name={"AppViewer"}
routeProtected
logDisable
/>
<AppRoute component={PageNotFound} name={"PageNotFound"} />
</Switch>
</Suspense>
</Router>
</ThemeProvider>
</Provider>
</DndProvider>,
<Provider store={store}>
<ThemeProvider theme={theme}>
<ToastContainer
hideProgressBar
draggable={false}
transition={Slide}
autoClose={5000}
closeButton={false}
/>
<Helmet>
<meta charSet="utf-8" />
<link rel="shortcut icon" href="/favicon-orange.ico" />
</Helmet>
<Router history={history}>
<Suspense fallback={loadingIndicator}>
<Switch>
<AppRoute
exact
path={BASE_URL}
component={App}
name={"App"}
routeProtected
/>
<AppRoute
path={ORG_URL}
component={Organization}
name={"Organisation"}
routeProtected
/>
<AppRoute
exact
path={USERS_URL}
component={Users}
name={"Users"}
routeProtected
/>
<AppRoute
path={USER_AUTH_URL}
component={UserAuth}
name={"UserAuth"}
/>
<Redirect exact from={BASE_LOGIN_URL} to={AUTH_LOGIN_URL} />
<Redirect exact from={BASE_SIGNUP_URL} to={SIGN_UP_URL} />
<AppRoute
exact
path={APPLICATIONS_URL}
component={Applications}
name={"Home"}
routeProtected
/>
<AppRoute
path={BUILDER_URL}
component={Editor}
name={"Editor"}
routeProtected
/>
<AppRoute
path={APP_VIEW_URL}
component={AppViewer}
name={"AppViewer"}
routeProtected
logDisable
/>
<AppRoute component={PageNotFound} name={"PageNotFound"} />
</Switch>
</Suspense>
</Router>
</ThemeProvider>
</Provider>,
document.getElementById("root"),
);
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: http://bit.ly/CRA-PWA
serviceWorker.unregister();
// serviceWorker.unregister();

View File

@ -12,6 +12,8 @@ import { UserApplication } from "constants/userConstants";
import { AppState } from "reducers";
import EditorHeader from "./EditorHeader";
import MainContainer from "./MainContainer";
import { DndProvider } from "react-dnd";
import TouchBackend from "react-dnd-touch-backend";
import {
getCurrentApplicationId,
getCurrentLayoutId,
@ -35,6 +37,7 @@ import { RenderModes } from "constants/WidgetConstants";
import { getCurrentApplication } from "selectors/applicationSelectors";
import AnalyticsUtil from "utils/AnalyticsUtil";
import { fetchPage } from "actions/pageActions";
import { editorInitializer } from "utils/EditorUtils";
type EditorProps = {
currentPageName?: string;
@ -62,9 +65,13 @@ type EditorProps = {
class Editor extends Component<EditorProps> {
public state = {
isDialogOpen: false,
registered: false,
};
componentDidMount() {
editorInitializer().then(() => {
this.setState({ registered: true });
});
const { applicationId, pageId } = this.props.match.params;
if (applicationId && pageId) {
this.props.initEditor(applicationId, pageId);
@ -116,55 +123,62 @@ class Editor extends Component<EditorProps> {
if (!this.props.match.params.applicationId) {
return <Redirect to="/applications" />;
}
if (!this.props.isEditorInitialized) return null;
if (!this.props.isEditorInitialized || !this.state.registered) return null;
return (
<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}
isPublishing={this.props.isPublishing}
publishedTime={this.props.publishedTime}
createModal={this.props.createModal}
/>
<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"
/>
<DndProvider
backend={TouchBackend}
options={{
enableMouseEvents: true,
}}
>
<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}
isPublishing={this.props.isPublishing}
publishedTime={this.props.publishedTime}
createModal={this.props.createModal}
/>
<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>
</Dialog>
</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>
</div>
</Dialog>
</div>
</DndProvider>
);
}
}

View File

@ -3,12 +3,8 @@ import { getAppsmithConfigs } from "configs";
import * as Sentry from "@sentry/browser";
import AnalyticsUtil from "./AnalyticsUtil";
import FontFaceObserver from "fontfaceobserver";
import PropertyControlRegistry from "./PropertyControlRegistry";
import WidgetBuilderRegistry from "./WidgetRegistry";
import { Property } from "api/ActionAPI";
import _ from "lodash";
import moment from "moment-timezone";
import ValidationRegistry from "./ValidationRegistry";
import { ActionDataState } from "reducers/entityReducers/actionsReducer";
import * as log from "loglevel";
import { LogLevelDesc } from "loglevel";
@ -27,10 +23,6 @@ export const createReducer = (
};
export const appInitializer = () => {
WidgetBuilderRegistry.registerWidgetBuilders();
PropertyControlRegistry.registerPropertyControlBuilders();
ValidationRegistry.registerInternalValidators();
moment.tz.setDefault(moment.tz.guess());
const appsmithConfigs = getAppsmithConfigs();
if (appsmithConfigs.sentry.enabled && appsmithConfigs.sentry.config) {
Sentry.init(appsmithConfigs.sentry.config);

View File

@ -0,0 +1,11 @@
import WidgetBuilderRegistry from "./WidgetRegistry";
import PropertyControlRegistry from "./PropertyControlRegistry";
import ValidationRegistry from "./ValidationRegistry";
export const editorInitializer = async () => {
WidgetBuilderRegistry.registerWidgetBuilders();
PropertyControlRegistry.registerPropertyControlBuilders();
ValidationRegistry.registerInternalValidators();
const moment = await import("moment-timezone");
moment.tz.setDefault(moment.tz.guess());
};

View File

@ -37,8 +37,7 @@ import FormButtonWidget, {
import IconWidget, { IconWidgetProps } from "widgets/IconWidget";
import CanvasWidget from "widgets/CanvasWidget";
class WidgetBuilderRegistry {
export default class WidgetBuilderRegistry {
static registerWidgetBuilders() {
WidgetFactory.registerWidgetBuilder(
"CONTAINER_WIDGET",
@ -281,5 +280,3 @@ class WidgetBuilderRegistry {
);
}
}
export default WidgetBuilderRegistry;

View File

@ -7,7 +7,9 @@ import { VALIDATION_TYPES } from "constants/WidgetValidation";
import Skeleton from "components/utils/Skeleton";
const ChartComponent = lazy(() =>
import("components/designSystems/appsmith/ChartComponent"),
import(
/* webpackPrefetch: true */ "components/designSystems/appsmith/ChartComponent"
),
);
class ChartWidget extends BaseWidget<ChartWidgetProps, WidgetState> {

View File

@ -16,7 +16,9 @@ import { TriggerPropertiesMap } from "utils/WidgetFactory";
import Skeleton from "components/utils/Skeleton";
const TableComponent = lazy(() =>
import("components/designSystems/syncfusion/TableComponent"),
import(
/* webpackPrefetch: true */ "components/designSystems/syncfusion/TableComponent"
),
);
function constructColumns(