2019-10-31 08:36:04 +00:00
|
|
|
import React, { Component } from "react";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import { connect } from "react-redux";
|
2020-09-24 16:05:18 +00:00
|
|
|
import { withRouter, RouteComponentProps, Route } from "react-router";
|
2020-03-11 13:59:46 +00:00
|
|
|
import { Switch } from "react-router-dom";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { AppState } from "reducers";
|
2019-11-22 14:02:55 +00:00
|
|
|
import {
|
|
|
|
|
AppViewerRouteParams,
|
2020-02-18 10:41:52 +00:00
|
|
|
BuilderRouteParams,
|
2019-11-22 14:02:55 +00:00
|
|
|
getApplicationViewerPageURL,
|
|
|
|
|
} from "constants/routes";
|
2020-08-06 11:06:53 +00:00
|
|
|
import { ReduxActionTypes } from "constants/ReduxActionConstants";
|
2020-11-04 11:40:59 +00:00
|
|
|
import {
|
|
|
|
|
getIsInitialized,
|
|
|
|
|
getIsInitializeError,
|
|
|
|
|
} from "selectors/appViewSelectors";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { executeAction } from "actions/widgetActions";
|
2020-02-18 10:41:52 +00:00
|
|
|
import { ExecuteActionPayload } from "constants/ActionConstants";
|
2020-02-26 12:44:56 +00:00
|
|
|
import { updateWidgetPropertyRequest } from "actions/controlActions";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { RenderModes } from "constants/WidgetConstants";
|
2019-11-13 07:00:25 +00:00
|
|
|
import { EditorContext } from "components/editorComponents/EditorContextProvider";
|
2019-11-22 14:02:55 +00:00
|
|
|
import AppViewerPageContainer from "./AppViewerPageContainer";
|
2020-03-06 09:45:21 +00:00
|
|
|
import {
|
|
|
|
|
resetChildrenMetaProperty,
|
|
|
|
|
updateWidgetMetaProperty,
|
|
|
|
|
} from "actions/metaActions";
|
2020-04-16 13:00:53 +00:00
|
|
|
import { editorInitializer } from "utils/EditorUtils";
|
2020-08-28 17:23:07 +00:00
|
|
|
import * as Sentry from "@sentry/react";
|
2020-11-04 11:40:59 +00:00
|
|
|
import log from "loglevel";
|
|
|
|
|
import ServerTimeout from "../common/ServerTimeout";
|
2020-09-24 16:05:18 +00:00
|
|
|
const SentryRoute = Sentry.withSentryRouting(Route);
|
2019-10-31 08:36:04 +00:00
|
|
|
|
|
|
|
|
const AppViewerBody = styled.section`
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
align-items: stretch;
|
|
|
|
|
justify-content: flex-start;
|
2019-11-01 05:28:56 +00:00
|
|
|
height: calc(100vh - ${props => props.theme.headerHeight});
|
2019-10-31 08:36:04 +00:00
|
|
|
`;
|
2019-11-01 05:28:56 +00:00
|
|
|
|
2019-10-31 08:36:04 +00:00
|
|
|
export type AppViewerProps = {
|
2020-10-24 11:45:16 +00:00
|
|
|
initializeAppViewer: (applicationId: string, pageId?: string) => void;
|
2020-01-24 09:54:40 +00:00
|
|
|
isInitialized: boolean;
|
2020-11-04 11:40:59 +00:00
|
|
|
isInitializeError: boolean;
|
2020-02-18 10:41:52 +00:00
|
|
|
executeAction: (actionPayload: ExecuteActionPayload) => void;
|
2019-11-08 11:02:00 +00:00
|
|
|
updateWidgetProperty: (
|
|
|
|
|
widgetId: string,
|
|
|
|
|
propertyName: string,
|
|
|
|
|
propertyValue: any,
|
|
|
|
|
) => void;
|
2020-02-07 02:32:52 +00:00
|
|
|
updateWidgetMetaProperty: (
|
|
|
|
|
widgetId: string,
|
|
|
|
|
propertyName: string,
|
|
|
|
|
propertyValue: any,
|
|
|
|
|
) => void;
|
2020-03-06 09:45:21 +00:00
|
|
|
resetChildrenMetaProperty: (widgetId: string) => void;
|
2020-02-18 10:41:52 +00:00
|
|
|
} & RouteComponentProps<BuilderRouteParams>;
|
2019-10-31 08:36:04 +00:00
|
|
|
|
2019-11-22 14:02:55 +00:00
|
|
|
class AppViewer extends Component<
|
|
|
|
|
AppViewerProps & RouteComponentProps<AppViewerRouteParams>
|
|
|
|
|
> {
|
2020-04-16 13:00:53 +00:00
|
|
|
public state = {
|
|
|
|
|
registered: false,
|
2020-07-23 12:28:02 +00:00
|
|
|
isSideNavOpen: true,
|
2020-04-16 13:00:53 +00:00
|
|
|
};
|
2019-10-31 08:36:04 +00:00
|
|
|
componentDidMount() {
|
2020-04-16 13:00:53 +00:00
|
|
|
editorInitializer().then(() => {
|
|
|
|
|
this.setState({ registered: true });
|
|
|
|
|
});
|
2020-10-24 11:45:16 +00:00
|
|
|
const { applicationId, pageId } = this.props.match.params;
|
2020-11-04 11:40:59 +00:00
|
|
|
log.debug({ applicationId, pageId });
|
2020-10-24 11:45:16 +00:00
|
|
|
if (applicationId) {
|
|
|
|
|
this.props.initializeAppViewer(applicationId, pageId);
|
2019-11-06 06:21:56 +00:00
|
|
|
}
|
2019-10-31 08:36:04 +00:00
|
|
|
}
|
2020-02-18 10:41:52 +00:00
|
|
|
|
2020-07-23 12:28:02 +00:00
|
|
|
toggleCollapse = (open: boolean) => {
|
|
|
|
|
this.setState({ isSideNavOpen: open });
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-31 08:36:04 +00:00
|
|
|
public render() {
|
2020-11-04 11:40:59 +00:00
|
|
|
const { isInitialized, isInitializeError } = this.props;
|
|
|
|
|
if (isInitializeError) {
|
|
|
|
|
return <ServerTimeout />;
|
|
|
|
|
}
|
2019-10-31 08:36:04 +00:00
|
|
|
return (
|
2019-11-13 07:00:25 +00:00
|
|
|
<EditorContext.Provider
|
2019-11-08 11:02:00 +00:00
|
|
|
value={{
|
|
|
|
|
executeAction: this.props.executeAction,
|
2020-02-07 02:32:52 +00:00
|
|
|
updateWidgetMetaProperty: this.props.updateWidgetMetaProperty,
|
2020-03-06 09:45:21 +00:00
|
|
|
resetChildrenMetaProperty: this.props.resetChildrenMetaProperty,
|
2019-11-08 11:02:00 +00:00
|
|
|
}}
|
|
|
|
|
>
|
2020-08-06 11:06:53 +00:00
|
|
|
<AppViewerBody>
|
|
|
|
|
{isInitialized && this.state.registered && (
|
|
|
|
|
<Switch>
|
2020-09-24 16:05:18 +00:00
|
|
|
<SentryRoute
|
2020-08-06 11:06:53 +00:00
|
|
|
path={getApplicationViewerPageURL()}
|
|
|
|
|
exact
|
|
|
|
|
component={AppViewerPageContainer}
|
2020-07-23 12:28:02 +00:00
|
|
|
/>
|
2020-08-06 11:06:53 +00:00
|
|
|
</Switch>
|
|
|
|
|
)}
|
|
|
|
|
</AppViewerBody>
|
2019-11-13 07:00:25 +00:00
|
|
|
</EditorContext.Provider>
|
2019-10-31 08:36:04 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-22 14:02:55 +00:00
|
|
|
const mapStateToProps = (state: AppState) => ({
|
2020-01-24 09:54:40 +00:00
|
|
|
isInitialized: getIsInitialized(state),
|
2020-11-04 11:40:59 +00:00
|
|
|
isInitializeError: getIsInitializeError(state),
|
2019-10-31 08:36:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch: any) => ({
|
2020-02-18 10:41:52 +00:00
|
|
|
executeAction: (actionPayload: ExecuteActionPayload) =>
|
|
|
|
|
dispatch(executeAction(actionPayload)),
|
2019-11-08 11:02:00 +00:00
|
|
|
updateWidgetProperty: (
|
|
|
|
|
widgetId: string,
|
|
|
|
|
propertyName: string,
|
|
|
|
|
propertyValue: any,
|
|
|
|
|
) =>
|
|
|
|
|
dispatch(
|
2020-02-26 12:44:56 +00:00
|
|
|
updateWidgetPropertyRequest(
|
2019-11-08 11:02:00 +00:00
|
|
|
widgetId,
|
|
|
|
|
propertyName,
|
|
|
|
|
propertyValue,
|
|
|
|
|
RenderModes.PAGE,
|
|
|
|
|
),
|
|
|
|
|
),
|
2020-02-07 02:32:52 +00:00
|
|
|
updateWidgetMetaProperty: (
|
|
|
|
|
widgetId: string,
|
|
|
|
|
propertyName: string,
|
|
|
|
|
propertyValue: any,
|
|
|
|
|
) =>
|
|
|
|
|
dispatch(updateWidgetMetaProperty(widgetId, propertyName, propertyValue)),
|
2020-03-06 09:45:21 +00:00
|
|
|
resetChildrenMetaProperty: (widgetId: string) =>
|
|
|
|
|
dispatch(resetChildrenMetaProperty(widgetId)),
|
2020-10-24 11:45:16 +00:00
|
|
|
initializeAppViewer: (applicationId: string, pageId?: string) => {
|
2019-10-31 08:36:04 +00:00
|
|
|
dispatch({
|
|
|
|
|
type: ReduxActionTypes.INITIALIZE_PAGE_VIEWER,
|
2020-10-24 11:45:16 +00:00
|
|
|
payload: { applicationId, pageId },
|
|
|
|
|
});
|
|
|
|
|
},
|
2019-10-31 08:36:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default withRouter(
|
2020-08-28 17:23:07 +00:00
|
|
|
connect(mapStateToProps, mapDispatchToProps)(Sentry.withProfiler(AppViewer)),
|
2019-10-31 08:36:04 +00:00
|
|
|
);
|