PromucFlow_constructor/app/client/src/pages/Editor/routes.tsx

217 lines
6.0 KiB
TypeScript
Raw Normal View History

import React, { useEffect, ReactNode } from "react";
import {
Switch,
withRouter,
RouteComponentProps,
Route,
matchPath,
} from "react-router-dom";
2019-11-25 09:15:11 +00:00
import ApiEditor from "./APIEditor";
import QueryEditor from "./QueryEditor";
import DataSourceEditor from "./DataSourceEditor";
import CurlImportForm from "./APIEditor/CurlImportForm";
import ProviderTemplates from "./APIEditor/ProviderTemplates";
2019-10-21 15:12:45 +00:00
import {
API_EDITOR_ID_URL,
API_EDITOR_URL,
QUERIES_EDITOR_URL,
QUERIES_EDITOR_ID_URL,
DATA_SOURCES_EDITOR_URL,
DATA_SOURCES_EDITOR_ID_URL,
BUILDER_PAGE_URL,
BuilderRouteParams,
APIEditorRouteParams,
getCurlImportPageURL,
API_EDITOR_URL_WITH_SELECTED_PAGE_ID,
getProviderTemplatesURL,
2019-11-25 05:07:27 +00:00
} from "constants/routes";
2019-10-18 08:16:26 +00:00
import styled from "styled-components";
import {
useShowPropertyPane,
useWidgetSelection,
} from "utils/hooks/dragResizeHooks";
import { closeAllModals } from "actions/widgetActions";
import { useDispatch } from "react-redux";
import PerformanceTracker, {
PerformanceTransactionName,
} from "utils/PerformanceTracker";
2019-10-18 08:16:26 +00:00
import * as Sentry from "@sentry/react";
const SentryRoute = Sentry.withSentryRouting(Route);
Introducing Google Sheets Plugin (#3517) * cherry pick -make new * revert to enable fix from release * attempt to hook into existing datasource editor * gSheets plugin skeleton from Rest API * Changes for database migration * fix for auth code * separate it out * action page loads! * add to explorer * create action from datasource * Editor JSON WIP * working query form * Editor JSON WIP * import to * fix toast message * redirect from datasource and editor pages * fix onboarding * fix imports and constants * refactor form out * refactor queryForm * Merge branch 'release' into feature/google-sheets * Merge branch 'release' into feature/google-sheets * initial values from settings, editor and form * Check * remove dangling code around lightTheme * Safety net * remove class * try mouseover solve * force click * changes from review * fix action form name on import * Merge branch 'release' into feature/google-sheets * minor cleanup * Merge branch 'release' into feature/google-sheets * WIP * Google sheets changes * Merge conflicts * Merging and fixes, needs refactoring * Check * Merge branch 'release' into feature/google-sheets * Fixed tests * Add cloud services env variable * Clean up saga * Clean up * Refactoring * Deleted svg file * Minor fixes * Modified design to allow behaviour in google sheets methods (#3486) * Modified design to allow behaviour in google sheets methods * Review changes * Removed sysout * Added handling of edge cases with table data * Merge branch 'release' into feature/google-sheets * Fixes * Fixes * Added validations * Improved tests * Removed extraneous injected bean * Review changes * Fixed bug with method * Changes to Google sheets plugin's request and response structures (#3692) * Method changes * Removed logging * Renaming options * Reverting pom version * Modified type of collection variables, fixed errors * Converted row offset field to one that supports dynamic bindings * Review changes * List SAAS plugin type actions under lightning menu apis (#3820) * list saas plugin type actions under lightning menu apis * combine saas plugin type actions in the other sub menu of lightning menu Co-authored-by: Hetu Nandu <hetunandu@gmail.com> * Fix merge issues * Prettified query editor and a few fixes w/ ux * Test fixes * Reformatting request * code for REST added (#3876) Co-authored-by: hetunandu <hetu@appsmith.com> * Renamed body to row object * Renamed placeholder for range * Renamed range heading * Modifications to handle range semantics * Use spreadsheet Url instead of id * Ordering of methods * Removed logging * Add tests for Dynamic text controls * Add tests for url helpers * Fix coverage config * Nevermind * Interface changes * There is no body here * Yay to hints * Delete row field is separately handled as row index * placeholder support (#4001) * Fixed tests, typos and creating new sheets with random rows * Switched to using 'rowIndex' throughout * binding path added for query input field (#4016) * - Fixed QA bugs (#4032) - Split delete sheet into two - Removed dynamic query input types from hidden keys * Proper exceptions * Removed extra logging * Throw exception if update method does not match any of the columns * Same for bulk update * Zero-indexed delete row * I'm a space bound rocket ship * Logic to register installations with cs (#4062) * Logic to register installations with cs * Clean up * Casting to string * Checking to see if this makes the test pass * Added an extra null check Co-authored-by: Piyush <piyush@codeitout.com> Co-authored-by: hetunandu <hetu@appsmith.com> Co-authored-by: Hetu Nandu <hetunandu@gmail.com> Co-authored-by: Apeksha Bhosale <7846888+ApekshaBhosale@users.noreply.github.com>
2021-04-22 03:30:09 +00:00
import { SaaSEditorRoutes } from "./SaaSEditor/routes";
const Wrapper = styled.div<{ isVisible: boolean }>`
2019-10-18 08:16:26 +00:00
position: absolute;
2019-12-11 10:35:07 +00:00
top: 0;
left: 0;
2020-12-24 04:32:25 +00:00
width: ${(props) => (!props.isVisible ? "0px" : "100%")};
height: calc(100vh - ${(props) => props.theme.smallHeaderHeight});
2020-12-24 04:32:25 +00:00
background-color: ${(props) =>
props.isVisible ? "rgba(0, 0, 0, 0.26)" : "transparent"};
2020-12-24 04:32:25 +00:00
z-index: ${(props) => (props.isVisible ? 2 : -1)};
`;
2020-01-27 08:24:58 +00:00
const DrawerWrapper = styled.div<{
isVisible: boolean;
2021-04-23 13:50:55 +00:00
isActionPath: any;
2020-01-27 08:24:58 +00:00
}>`
background-color: white;
width: ${(props) => (!props.isVisible ? "0" : "100%")};
height: 100%;
2019-10-18 08:16:26 +00:00
`;
interface RouterState {
isVisible: boolean;
2021-04-23 13:50:55 +00:00
isActionPath: Record<any, any> | null;
2019-10-18 08:16:26 +00:00
}
class EditorsRouter extends React.Component<
RouteComponentProps<BuilderRouteParams>,
RouterState
> {
constructor(props: RouteComponentProps<APIEditorRouteParams>) {
2019-10-18 08:16:26 +00:00
super(props);
const { applicationId, pageId } = this.props.match.params;
2019-10-18 08:16:26 +00:00
this.state = {
isVisible:
this.props.location.pathname !==
BUILDER_PAGE_URL(applicationId, pageId),
2021-04-23 13:50:55 +00:00
isActionPath: this.isMatchPath(),
2019-10-18 08:16:26 +00:00
};
}
2020-01-27 08:24:58 +00:00
2019-10-18 08:16:26 +00:00
componentDidUpdate(prevProps: Readonly<RouteComponentProps>): void {
if (this.props.location.pathname !== prevProps.location.pathname) {
const { applicationId, pageId } = this.props.match.params;
2019-10-18 08:16:26 +00:00
this.setState({
isVisible:
this.props.location.pathname !==
BUILDER_PAGE_URL(applicationId, pageId),
2021-04-23 13:50:55 +00:00
isActionPath: this.isMatchPath(),
2019-10-18 08:16:26 +00:00
});
}
}
isMatchPath = () => {
return matchPath(this.props.location.pathname, {
path: [
API_EDITOR_URL(),
API_EDITOR_ID_URL(),
API_EDITOR_URL_WITH_SELECTED_PAGE_ID(),
2021-04-23 13:50:55 +00:00
QUERIES_EDITOR_URL(),
QUERIES_EDITOR_ID_URL(),
],
exact: true,
strict: false,
});
};
handleClose = (e: React.MouseEvent) => {
PerformanceTracker.startTracking(
PerformanceTransactionName.CLOSE_SIDE_PANE,
{ path: this.props.location.pathname },
);
e.stopPropagation();
const { applicationId, pageId } = this.props.match.params;
this.setState({
isVisible: false,
});
this.props.history.replace(BUILDER_PAGE_URL(applicationId, pageId));
};
preventClose = (e: React.MouseEvent) => {
e.stopPropagation();
};
2019-10-18 08:16:26 +00:00
render(): React.ReactNode {
return (
<Wrapper isVisible={this.state.isVisible} onClick={this.handleClose}>
<PaneDrawer
2021-04-23 13:50:55 +00:00
isActionPath={this.state.isActionPath}
isVisible={this.state.isVisible}
onClick={this.preventClose}
2019-10-18 08:16:26 +00:00
>
<Switch>
<SentryRoute component={ApiEditor} exact path={API_EDITOR_URL()} />
<SentryRoute
component={ApiEditor}
2020-03-11 13:59:46 +00:00
exact
path={API_EDITOR_ID_URL()}
/>
<SentryRoute
component={ApiEditor}
exact
path={API_EDITOR_URL_WITH_SELECTED_PAGE_ID()}
/>
<SentryRoute
component={QueryEditor}
exact
path={QUERIES_EDITOR_URL()}
/>
<SentryRoute
component={QueryEditor}
exact
path={QUERIES_EDITOR_ID_URL()}
/>
<SentryRoute
component={CurlImportForm}
exact
path={getCurlImportPageURL()}
/>
Introducing Google Sheets Plugin (#3517) * cherry pick -make new * revert to enable fix from release * attempt to hook into existing datasource editor * gSheets plugin skeleton from Rest API * Changes for database migration * fix for auth code * separate it out * action page loads! * add to explorer * create action from datasource * Editor JSON WIP * working query form * Editor JSON WIP * import to * fix toast message * redirect from datasource and editor pages * fix onboarding * fix imports and constants * refactor form out * refactor queryForm * Merge branch 'release' into feature/google-sheets * Merge branch 'release' into feature/google-sheets * initial values from settings, editor and form * Check * remove dangling code around lightTheme * Safety net * remove class * try mouseover solve * force click * changes from review * fix action form name on import * Merge branch 'release' into feature/google-sheets * minor cleanup * Merge branch 'release' into feature/google-sheets * WIP * Google sheets changes * Merge conflicts * Merging and fixes, needs refactoring * Check * Merge branch 'release' into feature/google-sheets * Fixed tests * Add cloud services env variable * Clean up saga * Clean up * Refactoring * Deleted svg file * Minor fixes * Modified design to allow behaviour in google sheets methods (#3486) * Modified design to allow behaviour in google sheets methods * Review changes * Removed sysout * Added handling of edge cases with table data * Merge branch 'release' into feature/google-sheets * Fixes * Fixes * Added validations * Improved tests * Removed extraneous injected bean * Review changes * Fixed bug with method * Changes to Google sheets plugin's request and response structures (#3692) * Method changes * Removed logging * Renaming options * Reverting pom version * Modified type of collection variables, fixed errors * Converted row offset field to one that supports dynamic bindings * Review changes * List SAAS plugin type actions under lightning menu apis (#3820) * list saas plugin type actions under lightning menu apis * combine saas plugin type actions in the other sub menu of lightning menu Co-authored-by: Hetu Nandu <hetunandu@gmail.com> * Fix merge issues * Prettified query editor and a few fixes w/ ux * Test fixes * Reformatting request * code for REST added (#3876) Co-authored-by: hetunandu <hetu@appsmith.com> * Renamed body to row object * Renamed placeholder for range * Renamed range heading * Modifications to handle range semantics * Use spreadsheet Url instead of id * Ordering of methods * Removed logging * Add tests for Dynamic text controls * Add tests for url helpers * Fix coverage config * Nevermind * Interface changes * There is no body here * Yay to hints * Delete row field is separately handled as row index * placeholder support (#4001) * Fixed tests, typos and creating new sheets with random rows * Switched to using 'rowIndex' throughout * binding path added for query input field (#4016) * - Fixed QA bugs (#4032) - Split delete sheet into two - Removed dynamic query input types from hidden keys * Proper exceptions * Removed extra logging * Throw exception if update method does not match any of the columns * Same for bulk update * Zero-indexed delete row * I'm a space bound rocket ship * Logic to register installations with cs (#4062) * Logic to register installations with cs * Clean up * Casting to string * Checking to see if this makes the test pass * Added an extra null check Co-authored-by: Piyush <piyush@codeitout.com> Co-authored-by: hetunandu <hetu@appsmith.com> Co-authored-by: Hetu Nandu <hetunandu@gmail.com> Co-authored-by: Apeksha Bhosale <7846888+ApekshaBhosale@users.noreply.github.com>
2021-04-22 03:30:09 +00:00
{SaaSEditorRoutes.map((props) => (
<SentryRoute exact key={props.path} {...props} />
))}
<SentryRoute
component={DataSourceEditor}
exact
path={DATA_SOURCES_EDITOR_URL()}
/>
<SentryRoute
component={DataSourceEditor}
exact
path={DATA_SOURCES_EDITOR_ID_URL()}
/>
<SentryRoute
component={ProviderTemplates}
exact
path={getProviderTemplatesURL()}
/>
2019-10-18 08:16:26 +00:00
</Switch>
</PaneDrawer>
</Wrapper>
2019-10-18 08:16:26 +00:00
);
}
}
type PaneDrawerProps = {
isVisible: boolean;
2021-04-23 13:50:55 +00:00
isActionPath: Record<any, any> | null;
onClick: (e: React.MouseEvent) => void;
children: ReactNode;
};
function PaneDrawer(props: PaneDrawerProps) {
const showPropertyPane = useShowPropertyPane();
const { selectWidget, focusWidget } = useWidgetSelection();
const dispatch = useDispatch();
useEffect(() => {
// This pane drawer is only open when NOT on canvas.
// De-select all widgets
// Un-focus all widgets
// Hide property pane
// Close all modals
if (props.isVisible) {
showPropertyPane();
selectWidget(undefined);
focusWidget(undefined);
dispatch(closeAllModals());
}
}, [dispatch, props.isVisible, selectWidget, showPropertyPane, focusWidget]);
return <DrawerWrapper {...props}>{props.children}</DrawerWrapper>;
}
PaneDrawer.displayName = "PaneDrawer";
2019-10-18 08:16:26 +00:00
export default withRouter(EditorsRouter);