2021-07-05 05:49:43 +00:00
|
|
|
import log from "loglevel";
|
|
|
|
|
import * as Sentry from "@sentry/react";
|
2022-05-04 09:45:57 +00:00
|
|
|
import styled from "styled-components";
|
|
|
|
|
import store, { useSelector } from "store";
|
2022-08-19 10:10:36 +00:00
|
|
|
import { CanvasWidgetStructure } from "widgets/constants";
|
2022-05-04 09:45:57 +00:00
|
|
|
import WidgetFactory from "utils/WidgetFactory";
|
|
|
|
|
import React, { memo, useCallback, useEffect } from "react";
|
2021-09-09 15:10:22 +00:00
|
|
|
|
2021-08-18 10:29:52 +00:00
|
|
|
import CanvasMultiPointerArena, {
|
|
|
|
|
POINTERS_CANVAS_ID,
|
2022-04-12 10:50:01 +00:00
|
|
|
} from "pages/common/CanvasArenas/CanvasMultiPointerArena";
|
2021-08-18 10:29:52 +00:00
|
|
|
import { throttle } from "lodash";
|
2021-09-09 15:10:22 +00:00
|
|
|
import { RenderModes } from "constants/WidgetConstants";
|
2021-08-26 06:56:13 +00:00
|
|
|
import { isMultiplayerEnabledForUser as isMultiplayerEnabledForUserSelector } from "selectors/appCollabSelectors";
|
2021-10-01 16:44:19 +00:00
|
|
|
import { useDispatch } from "react-redux";
|
|
|
|
|
import { initPageLevelSocketConnection } from "actions/websocketActions";
|
|
|
|
|
import { collabShareUserPointerEvent } from "actions/appCollabActions";
|
2022-04-12 10:50:01 +00:00
|
|
|
import { getIsPageLevelSocketConnected } from "selectors/websocketSelectors";
|
2021-12-07 07:59:32 +00:00
|
|
|
import { getCurrentGitBranch } from "selectors/gitSyncSelectors";
|
2022-05-04 09:45:57 +00:00
|
|
|
import { getSelectedAppTheme } from "selectors/appThemingSelectors";
|
2021-12-07 07:59:32 +00:00
|
|
|
import { getPageLevelSocketRoomId } from "sagas/WebsocketSagas/utils";
|
2022-05-04 09:45:57 +00:00
|
|
|
import { previewModeSelector } from "selectors/editorSelectors";
|
2019-03-21 17:42:23 +00:00
|
|
|
|
2019-08-26 12:41:21 +00:00
|
|
|
interface CanvasProps {
|
2022-08-19 10:10:36 +00:00
|
|
|
widgetsStructure: CanvasWidgetStructure;
|
2021-08-18 10:29:52 +00:00
|
|
|
pageId: string;
|
2022-08-19 10:10:36 +00:00
|
|
|
canvasWidth: number;
|
2019-08-29 11:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-01 16:44:19 +00:00
|
|
|
type PointerEventDataType = {
|
|
|
|
|
data: { x: number; y: number };
|
|
|
|
|
user: any;
|
|
|
|
|
};
|
2021-08-18 10:29:52 +00:00
|
|
|
|
2022-05-04 09:45:57 +00:00
|
|
|
const Container = styled.section<{
|
|
|
|
|
background: string;
|
|
|
|
|
}>`
|
|
|
|
|
background: ${({ background }) => background};
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2021-10-01 16:44:19 +00:00
|
|
|
const getPointerData = (
|
|
|
|
|
e: any,
|
|
|
|
|
pageId: string,
|
|
|
|
|
isWebsocketConnected: boolean,
|
2021-12-07 07:59:32 +00:00
|
|
|
currentGitBranch?: string,
|
2021-10-01 16:44:19 +00:00
|
|
|
) => {
|
|
|
|
|
if (store.getState().ui.appCollab.editors.length < 2 || !isWebsocketConnected)
|
|
|
|
|
return;
|
|
|
|
|
const selectionCanvas: any = document.getElementById(POINTERS_CANVAS_ID);
|
|
|
|
|
const rect = selectionCanvas.getBoundingClientRect();
|
2021-08-18 10:29:52 +00:00
|
|
|
|
2021-10-01 16:44:19 +00:00
|
|
|
const x = e.clientX - rect.left;
|
|
|
|
|
const y = e.clientY - rect.top;
|
|
|
|
|
return {
|
|
|
|
|
data: { x, y },
|
2021-12-07 07:59:32 +00:00
|
|
|
pageId: getPageLevelSocketRoomId(pageId, currentGitBranch),
|
2021-10-01 16:44:19 +00:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const useShareMousePointerEvent = () => {
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
const isWebsocketConnected = useSelector(getIsPageLevelSocketConnected);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!isWebsocketConnected) {
|
|
|
|
|
dispatch(initPageLevelSocketConnection());
|
|
|
|
|
}
|
|
|
|
|
}, [isWebsocketConnected]);
|
|
|
|
|
|
|
|
|
|
return (pointerData: PointerEventDataType) =>
|
|
|
|
|
dispatch(collabShareUserPointerEvent(pointerData));
|
2021-08-18 10:29:52 +00:00
|
|
|
};
|
|
|
|
|
|
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) => {
|
2022-08-19 10:10:36 +00:00
|
|
|
const { canvasWidth, pageId } = props;
|
2022-05-04 09:45:57 +00:00
|
|
|
const isPreviewMode = useSelector(previewModeSelector);
|
|
|
|
|
const selectedTheme = useSelector(getSelectedAppTheme);
|
|
|
|
|
|
2021-10-01 16:44:19 +00:00
|
|
|
const shareMousePointer = useShareMousePointerEvent();
|
|
|
|
|
const isWebsocketConnected = useSelector(getIsPageLevelSocketConnected);
|
2021-12-07 07:59:32 +00:00
|
|
|
const currentGitBranch = useSelector(getCurrentGitBranch);
|
2021-08-26 06:56:13 +00:00
|
|
|
const isMultiplayerEnabledForUser = useSelector(
|
|
|
|
|
isMultiplayerEnabledForUserSelector,
|
|
|
|
|
);
|
2021-08-18 10:29:52 +00:00
|
|
|
const delayedShareMousePointer = useCallback(
|
2021-10-01 16:44:19 +00:00
|
|
|
throttle((data) => shareMousePointer(data), 50, {
|
2021-08-18 10:29:52 +00:00
|
|
|
trailing: false,
|
|
|
|
|
}),
|
|
|
|
|
[shareMousePointer, pageId],
|
|
|
|
|
);
|
2021-08-26 06:56:13 +00:00
|
|
|
|
2022-05-04 09:45:57 +00:00
|
|
|
/**
|
|
|
|
|
* background for canvas
|
|
|
|
|
*/
|
|
|
|
|
let backgroundForCanvas;
|
2022-11-23 09:48:23 +00:00
|
|
|
let renderMode = RenderModes.CANVAS;
|
2022-05-04 09:45:57 +00:00
|
|
|
|
|
|
|
|
if (isPreviewMode) {
|
|
|
|
|
backgroundForCanvas = "initial";
|
2022-11-23 09:48:23 +00:00
|
|
|
renderMode = RenderModes.PREVIEW;
|
2022-05-04 09:45:57 +00:00
|
|
|
} else {
|
|
|
|
|
backgroundForCanvas = selectedTheme.properties.colors.backgroundColor;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-26 10:45:46 +00:00
|
|
|
try {
|
|
|
|
|
return (
|
2022-05-04 09:45:57 +00:00
|
|
|
<Container
|
|
|
|
|
background={backgroundForCanvas}
|
|
|
|
|
className="relative mx-auto t--canvas-artboard pb-52"
|
2021-11-23 08:01:46 +00:00
|
|
|
data-testid="t--canvas-artboard"
|
|
|
|
|
id="art-board"
|
|
|
|
|
onMouseMove={(e) => {
|
|
|
|
|
if (!isMultiplayerEnabledForUser) return;
|
2021-12-07 07:59:32 +00:00
|
|
|
const data = getPointerData(
|
|
|
|
|
e,
|
|
|
|
|
pageId,
|
|
|
|
|
isWebsocketConnected,
|
|
|
|
|
currentGitBranch,
|
|
|
|
|
);
|
2021-11-23 08:01:46 +00:00
|
|
|
!!data && delayedShareMousePointer(data);
|
|
|
|
|
}}
|
2022-05-04 09:45:57 +00:00
|
|
|
style={{
|
2022-08-19 10:10:36 +00:00
|
|
|
width: canvasWidth,
|
2022-05-04 09:45:57 +00:00
|
|
|
}}
|
2021-11-23 08:01:46 +00:00
|
|
|
>
|
2022-08-19 10:10:36 +00:00
|
|
|
{props.widgetsStructure.widgetId &&
|
2022-11-23 09:48:23 +00:00
|
|
|
WidgetFactory.createWidget(props.widgetsStructure, renderMode)}
|
2021-11-23 08:01:46 +00:00
|
|
|
{isMultiplayerEnabledForUser && (
|
|
|
|
|
<CanvasMultiPointerArena pageId={pageId} />
|
|
|
|
|
)}
|
2022-05-04 09:45:57 +00:00
|
|
|
</Container>
|
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;
|