2021-08-18 10:29:52 +00:00
|
|
|
import React, { memo, useCallback } from "react";
|
2021-08-26 06:56:13 +00:00
|
|
|
import store, { useSelector } from "store";
|
2019-11-13 07:00:25 +00:00
|
|
|
import WidgetFactory from "utils/WidgetFactory";
|
|
|
|
|
import { RenderModes } from "constants/WidgetConstants";
|
|
|
|
|
import { ContainerWidgetProps } from "widgets/ContainerWidget";
|
|
|
|
|
import { WidgetProps } from "widgets/BaseWidget";
|
2020-02-26 12:44:56 +00:00
|
|
|
import PropertyPane from "pages/Editor/PropertyPane";
|
2019-11-25 05:07:27 +00:00
|
|
|
import ArtBoard from "pages/common/ArtBoard";
|
2021-07-05 05:49:43 +00:00
|
|
|
import log from "loglevel";
|
|
|
|
|
import * as Sentry from "@sentry/react";
|
2021-08-18 10:29:52 +00:00
|
|
|
import CanvasMultiPointerArena, {
|
|
|
|
|
POINTERS_CANVAS_ID,
|
|
|
|
|
} from "../common/CanvasMultiPointerArena";
|
|
|
|
|
import { throttle } from "lodash";
|
|
|
|
|
import { io } from "socket.io-client";
|
|
|
|
|
import {
|
|
|
|
|
APP_COLLAB_EVENTS,
|
|
|
|
|
NAMESPACE_COLLAB_PAGE_EDIT,
|
|
|
|
|
} from "constants/AppCollabConstants";
|
2021-09-02 03:17:42 +00:00
|
|
|
import { RTS_BASE_PATH } from "constants/WebsocketConstants";
|
2021-08-26 06:56:13 +00:00
|
|
|
import { isMultiplayerEnabledForUser as isMultiplayerEnabledForUserSelector } from "selectors/appCollabSelectors";
|
2019-03-21 17:42:23 +00:00
|
|
|
|
2019-08-26 12:41:21 +00:00
|
|
|
interface CanvasProps {
|
2019-09-19 22:25:37 +00:00
|
|
|
dsl: ContainerWidgetProps<WidgetProps>;
|
2021-08-18 10:29:52 +00:00
|
|
|
pageId: string;
|
2019-08-29 11:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-18 10:29:52 +00:00
|
|
|
// This auto connects the socket
|
2021-09-02 03:17:42 +00:00
|
|
|
const pageEditSocket = io(NAMESPACE_COLLAB_PAGE_EDIT, {
|
|
|
|
|
path: RTS_BASE_PATH,
|
|
|
|
|
});
|
2021-08-18 10:29:52 +00:00
|
|
|
|
|
|
|
|
const shareMousePointer = (e: any, pageId: string) => {
|
|
|
|
|
if (store.getState().ui.appCollab.editors.length < 2) return;
|
|
|
|
|
if (pageEditSocket && pageEditSocket.connected) {
|
|
|
|
|
const selectionCanvas: any = document.getElementById(POINTERS_CANVAS_ID);
|
|
|
|
|
const rect = selectionCanvas.getBoundingClientRect();
|
|
|
|
|
|
|
|
|
|
const x = e.clientX - rect.left;
|
|
|
|
|
const y = e.clientY - rect.top;
|
|
|
|
|
pageEditSocket.emit(APP_COLLAB_EVENTS.SHARE_USER_POINTER, {
|
|
|
|
|
data: { x, y },
|
|
|
|
|
pageId,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
pageEditSocket && pageEditSocket.connect();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-27 09:02:11 +00:00
|
|
|
// TODO(abhinav): get the render mode from context
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
const Canvas = memo((props: CanvasProps) => {
|
2021-08-18 10:29:52 +00:00
|
|
|
const { pageId } = props;
|
2021-08-26 06:56:13 +00:00
|
|
|
const isMultiplayerEnabledForUser = useSelector(
|
|
|
|
|
isMultiplayerEnabledForUserSelector,
|
|
|
|
|
);
|
2021-08-18 10:29:52 +00:00
|
|
|
const delayedShareMousePointer = useCallback(
|
|
|
|
|
throttle((e) => shareMousePointer(e, pageId), 50, {
|
|
|
|
|
trailing: false,
|
|
|
|
|
}),
|
|
|
|
|
[shareMousePointer, pageId],
|
|
|
|
|
);
|
2021-08-26 06:56:13 +00:00
|
|
|
|
2019-11-26 10:45:46 +00:00
|
|
|
try {
|
|
|
|
|
return (
|
2021-04-28 10:28:39 +00:00
|
|
|
<>
|
2020-01-20 09:00:37 +00:00
|
|
|
<PropertyPane />
|
2021-05-18 18:29:39 +00:00
|
|
|
<ArtBoard
|
|
|
|
|
className="t--canvas-artboard"
|
|
|
|
|
data-testid="t--canvas-artboard"
|
2021-06-17 13:26:54 +00:00
|
|
|
id="art-board"
|
2021-08-18 10:29:52 +00:00
|
|
|
onMouseMove={(e) => {
|
|
|
|
|
e.persist();
|
2021-08-26 06:56:13 +00:00
|
|
|
if (!isMultiplayerEnabledForUser) return;
|
2021-08-18 10:29:52 +00:00
|
|
|
delayedShareMousePointer(e);
|
|
|
|
|
}}
|
2021-05-18 18:29:39 +00:00
|
|
|
width={props.dsl.rightColumn}
|
|
|
|
|
>
|
2020-01-20 09:00:37 +00:00
|
|
|
{props.dsl.widgetId &&
|
|
|
|
|
WidgetFactory.createWidget(props.dsl, RenderModes.CANVAS)}
|
2021-08-26 06:56:13 +00:00
|
|
|
{isMultiplayerEnabledForUser && (
|
|
|
|
|
<CanvasMultiPointerArena
|
|
|
|
|
pageEditSocket={pageEditSocket}
|
|
|
|
|
pageId={pageId}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2020-01-20 09:00:37 +00:00
|
|
|
</ArtBoard>
|
2021-04-28 10:28:39 +00:00
|
|
|
</>
|
2019-11-26 10:45:46 +00:00
|
|
|
);
|
|
|
|
|
} catch (error) {
|
2021-07-05 05:49:43 +00:00
|
|
|
log.error("Error rendering DSL", error);
|
|
|
|
|
Sentry.captureException(error);
|
2019-11-26 10:45:46 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Canvas.displayName = "Canvas";
|
2019-02-10 13:06:05 +00:00
|
|
|
|
2019-09-09 10:30:22 +00:00
|
|
|
export default Canvas;
|