2020-03-11 13:59:46 +00:00
|
|
|
import React, { useEffect } from "react";
|
2019-12-16 08:49:10 +00:00
|
|
|
import { Route } from "react-router-dom";
|
2020-03-27 09:02:11 +00:00
|
|
|
import {
|
|
|
|
|
useShowPropertyPane,
|
|
|
|
|
useWidgetSelection,
|
|
|
|
|
} from "utils/hooks/dragResizeHooks";
|
2020-03-11 13:59:46 +00:00
|
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
2019-12-23 12:16:33 +00:00
|
|
|
|
|
|
|
|
export const WrappedComponent = (props: any) => {
|
2020-01-27 11:39:27 +00:00
|
|
|
const showPropertyPane = useShowPropertyPane();
|
|
|
|
|
showPropertyPane();
|
|
|
|
|
|
2020-03-27 09:02:11 +00:00
|
|
|
const { selectWidget, focusWidget } = useWidgetSelection();
|
|
|
|
|
selectWidget(undefined);
|
|
|
|
|
focusWidget(undefined);
|
|
|
|
|
|
2020-05-05 12:16:51 +00:00
|
|
|
return props.children;
|
2019-12-23 12:16:33 +00:00
|
|
|
};
|
2019-09-02 15:36:24 +00:00
|
|
|
|
2020-03-11 13:59:46 +00:00
|
|
|
const AppRoute = ({
|
2019-09-09 10:30:22 +00:00
|
|
|
component: Component,
|
|
|
|
|
...rest
|
|
|
|
|
}: {
|
2020-03-11 13:59:46 +00:00
|
|
|
path?: string;
|
2019-09-09 10:30:22 +00:00
|
|
|
component: React.ReactType;
|
2019-11-22 14:02:55 +00:00
|
|
|
exact?: boolean;
|
2020-03-11 13:59:46 +00:00
|
|
|
routeProtected?: boolean;
|
|
|
|
|
logDisable?: boolean;
|
|
|
|
|
name: string;
|
|
|
|
|
location?: any;
|
2019-09-09 10:30:22 +00:00
|
|
|
}) => {
|
2020-03-11 13:59:46 +00:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (!rest.logDisable) {
|
|
|
|
|
AnalyticsUtil.logEvent("NAVIGATE_EDITOR", {
|
|
|
|
|
page: rest.name,
|
|
|
|
|
path: rest.location.pathname,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, [rest.name, rest.logDisable, rest.location.pathname]);
|
|
|
|
|
|
2019-12-23 12:16:33 +00:00
|
|
|
return (
|
|
|
|
|
<Route
|
|
|
|
|
{...rest}
|
2020-03-11 13:59:46 +00:00
|
|
|
render={props => {
|
|
|
|
|
return rest.routeProtected ? (
|
|
|
|
|
<WrappedComponent {...props}>
|
|
|
|
|
<Component {...props} />
|
|
|
|
|
</WrappedComponent>
|
|
|
|
|
) : (
|
|
|
|
|
<Component {...props}></Component>
|
|
|
|
|
);
|
|
|
|
|
}}
|
2019-12-23 12:16:33 +00:00
|
|
|
/>
|
|
|
|
|
);
|
2019-09-09 10:30:22 +00:00
|
|
|
};
|
2019-09-02 14:50:01 +00:00
|
|
|
|
2020-03-11 13:59:46 +00:00
|
|
|
export default AppRoute;
|