From 216b5cff7b9a791550081f9df43a7fcf8989ef97 Mon Sep 17 00:00:00 2001 From: intVivek Date: Sat, 10 Jun 2023 16:11:32 +0530 Subject: [PATCH 01/50] chore(uikit-playground): Fixed Prettier --- .../src/Components/CodeEditor/BlockEditor.tsx | 60 ++++++++++ .../CodeEditor/Extensions/Extensions.ts | 25 +++++ .../CodeEditor/Extensions/HighlightStyle.ts | 1 + .../Components/CodeEditor/Extensions/index.ts | 3 +- .../CodeEditor/Extensions/jsonLinter.ts | 4 + .../Components/CodeEditor/Extensions/lint.ts | 5 - .../CodeEditor/Extensions/payloadLinter.ts | 65 +++++++++++ .../src/Components/CodeEditor/Parser/index.ts | 1 + .../CodeEditor/Parser/parsePayload.ts | 15 +++ .../Components/CodeEditor/PreviewEditor.tsx | 27 +++++ .../src/Components/CodeEditor/index.tsx | 14 +-- .../ComponentSideBar/ScrollableSideBar.tsx | 5 +- .../Components/ComponentSideBar/SideBar.tsx | 5 +- .../Components/ComponentSideBar/SliderBtn.tsx | 6 +- .../Components/Draggable/DraggableList.tsx | 60 +++++----- .../Draggable/DraggableListItem.tsx | 7 +- .../src/Components/DropDown/DropDown.tsx | 4 +- .../src/Components/DropDown/Items.tsx | 5 +- .../src/Components/DropDown/ItemsIcon.tsx | 11 +- .../NavBar/BurgerIcon/BurgerIcon.tsx | 2 +- .../src/Components/NavBar/BurgerIcon/Line.tsx | 5 +- .../Components/NavBar/BurgerIcon/Wrapper.tsx | 1 + .../src/Components/NavBar/Divider.tsx | 1 + .../src/Components/NavBar/Logo.tsx | 1 + .../src/Components/NavBar/NavBar.tsx | 22 +++- .../src/Components/NavBar/RightNavBtn.tsx | 5 +- .../RenderPayload/DeleteElementBtn.tsx | 5 +- .../Display/RenderPayload/ElementWrapper.tsx | 2 +- .../Display/RenderPayload/RenderPayload.tsx | 9 +- .../Preview/Display/Surface/BannerSurface.tsx | 1 + .../Display/Surface/MessageSurface.tsx | 7 +- .../Preview/Display/Surface/ModalSurface.tsx | 1 + .../Preview/Display/Surface/Surface.tsx | 64 ++++++++--- .../{Editor.tsx => ActionBlockEditor.tsx} | 11 +- .../Preview/Editor/ActionPreviewEditor.tsx | 25 +++++ .../Components/Preview/Editor/EditorPanel.tsx | 77 +++++++++++++ .../src/Components/Preview/Editor/index.tsx | 2 +- .../Components/Preview/NavPanel/NavPanel.tsx | 38 +++---- .../Components/Preview/NavPanel/PanelBtn.tsx | 6 +- .../src/Components/Preview/Preview.tsx | 7 +- .../SplitPlaneContainer.tsx | 21 ++-- .../SplitPlaneContainer/splitPlane.css | 103 +++++++++--------- .../src/Components/Preview/Wrapper.tsx | 6 +- .../SurfaceSelect/SurfaceSelect.tsx | 7 +- .../src/Components/SurfaceSelect/options.ts | 2 +- .../TabChange.tsx => ToggleTabs/index.tsx} | 21 ++-- .../src/Components/navMenu/Menu/MenuItem.tsx | 1 + .../src/Components/navMenu/Menu/Wrapper.tsx | 1 + .../src/Components/navMenu/Menu/index.tsx | 1 + .../src/Components/navMenu/NavMenu.tsx | 5 +- .../src/Components/utils/codePrettier.ts | 14 --- .../src/Context/action/actionPreviewAction.ts | 11 ++ .../src/Context/action/docAction.ts | 8 +- .../Context/action/editorTabsToggleAction.ts | 9 ++ .../src/Context/action/index.ts | 5 +- .../src/Context/action/isMobileAction.ts | 4 +- .../src/Context/action/isTabletAction.ts | 4 +- .../src/Context/action/navMenuToggleAction.ts | 4 +- .../Context/action/previewTabsToggleAction.ts | 9 ++ .../src/Context/action/sidebarToggleAction.ts | 4 +- .../src/Context/action/surfaceAction.ts | 4 +- .../src/Context/action/tabsToggleAction.ts | 4 +- .../src/Context/action/userAction.ts | 11 ++ .../uikit-playground/src/Context/index.tsx | 3 +- .../src/Context/initialState.ts | 39 ++++++- .../uikit-playground/src/Context/reducer.ts | 17 +-- .../uikit-playground/src/Pages/Playground.tsx | 6 +- .../Payload/{ => actionBlock}/BlocksTree.ts | 2 +- .../{ => actionBlock}/action/button.ts | 0 .../{ => actionBlock}/action/datePicker.ts | 0 .../Payload/{ => actionBlock}/action/image.ts | 0 .../Payload/{ => actionBlock}/action/index.ts | 4 +- .../Payload/{ => actionBlock}/action/input.ts | 0 .../{ => actionBlock}/action/linearScale.ts | 0 .../Payload/{ => actionBlock}/action/menu.ts | 0 .../{ => actionBlock}/action/staticSelect.ts | 0 .../{ => actionBlock}/context/index.ts | 0 .../{ => actionBlock}/divider/index.ts | 0 .../Payload/{ => actionBlock}/image/index.ts | 0 .../{ => actionBlock}/input/datePicker.ts | 0 .../Payload/{ => actionBlock}/input/index.ts | 0 .../Payload/{ => actionBlock}/input/input.ts | 0 .../{ => actionBlock}/input/linearScale.ts | 0 .../{ => actionBlock}/input/staticSelect.ts | 0 .../{ => actionBlock}/preview/index.ts | 2 +- .../{ => actionBlock}/section/button.ts | 0 .../{ => actionBlock}/section/datePicker.ts | 0 .../{ => actionBlock}/section/image.ts | 0 .../{ => actionBlock}/section/index.ts | 0 .../Payload/{ => actionBlock}/section/menu.ts | 0 .../Payload/{ => actionBlock}/section/text.ts | 0 .../src/Payload/actionPreview/container.ts | 19 ++++ .../actionPreview/generateActionPreview.ts | 31 ++++++ .../uikit-playground/src/Payload/index.ts | 2 + .../uikit-playground/src/cssVariables.css | 26 ++--- .../src/hooks/useCodeMirror.ts | 2 +- packages/uikit-playground/src/index.css | 15 +-- packages/uikit-playground/src/module.d.ts | 6 +- .../src/utils/codePrettier.ts | 4 +- 99 files changed, 748 insertions(+), 304 deletions(-) create mode 100644 packages/uikit-playground/src/Components/CodeEditor/BlockEditor.tsx create mode 100644 packages/uikit-playground/src/Components/CodeEditor/Extensions/Extensions.ts create mode 100644 packages/uikit-playground/src/Components/CodeEditor/Extensions/jsonLinter.ts delete mode 100644 packages/uikit-playground/src/Components/CodeEditor/Extensions/lint.ts create mode 100644 packages/uikit-playground/src/Components/CodeEditor/Extensions/payloadLinter.ts create mode 100644 packages/uikit-playground/src/Components/CodeEditor/Parser/index.ts create mode 100644 packages/uikit-playground/src/Components/CodeEditor/Parser/parsePayload.ts create mode 100644 packages/uikit-playground/src/Components/CodeEditor/PreviewEditor.tsx rename packages/uikit-playground/src/Components/Preview/Editor/{Editor.tsx => ActionBlockEditor.tsx} (55%) create mode 100644 packages/uikit-playground/src/Components/Preview/Editor/ActionPreviewEditor.tsx create mode 100644 packages/uikit-playground/src/Components/Preview/Editor/EditorPanel.tsx rename packages/uikit-playground/src/Components/{Preview/NavPanel/TabChange.tsx => ToggleTabs/index.tsx} (57%) delete mode 100644 packages/uikit-playground/src/Components/utils/codePrettier.ts create mode 100644 packages/uikit-playground/src/Context/action/actionPreviewAction.ts create mode 100644 packages/uikit-playground/src/Context/action/editorTabsToggleAction.ts create mode 100644 packages/uikit-playground/src/Context/action/previewTabsToggleAction.ts create mode 100644 packages/uikit-playground/src/Context/action/userAction.ts rename packages/uikit-playground/src/Payload/{ => actionBlock}/BlocksTree.ts (99%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/action/button.ts (100%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/action/datePicker.ts (100%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/action/image.ts (100%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/action/index.ts (83%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/action/input.ts (100%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/action/linearScale.ts (100%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/action/menu.ts (100%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/action/staticSelect.ts (100%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/context/index.ts (100%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/divider/index.ts (100%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/image/index.ts (100%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/input/datePicker.ts (100%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/input/index.ts (100%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/input/input.ts (100%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/input/linearScale.ts (100%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/input/staticSelect.ts (100%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/preview/index.ts (98%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/section/button.ts (100%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/section/datePicker.ts (100%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/section/image.ts (100%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/section/index.ts (100%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/section/menu.ts (100%) rename packages/uikit-playground/src/Payload/{ => actionBlock}/section/text.ts (100%) create mode 100644 packages/uikit-playground/src/Payload/actionPreview/container.ts create mode 100644 packages/uikit-playground/src/Payload/actionPreview/generateActionPreview.ts create mode 100644 packages/uikit-playground/src/Payload/index.ts diff --git a/packages/uikit-playground/src/Components/CodeEditor/BlockEditor.tsx b/packages/uikit-playground/src/Components/CodeEditor/BlockEditor.tsx new file mode 100644 index 000000000000..e3e19a228aab --- /dev/null +++ b/packages/uikit-playground/src/Components/CodeEditor/BlockEditor.tsx @@ -0,0 +1,60 @@ +import type { Extension } from '@codemirror/state'; +import { Box } from '@rocket.chat/fuselage'; +import { useDebouncedValue } from '@rocket.chat/fuselage-hooks'; +import json5 from 'json5'; +import { useEffect, useContext } from 'react'; + +import { docAction, context } from '../../Context'; +import useCodeMirror from '../../hooks/useCodeMirror'; +import codePrettier from '../../utils/codePrettier'; + +type CodeMirrorProps = { + extensions?: Extension[], +}; + +const BlockEditor = ({ extensions }: CodeMirrorProps) => { + const { state, dispatch } = useContext(context); + const { editor, changes, setValue } = useCodeMirror( + extensions, + JSON.stringify(state.doc.payload, undefined, 4) + ); + const debounceValue = useDebouncedValue(changes?.value, 1500); + + useEffect(() => { + if (!changes?.isDispatch) { + try { + const parsedCode = json5.parse(changes.value); + dispatch(docAction({ payload: parsedCode })); + } catch (e) { + // do nothing + } + } + }, [changes?.value]); + + useEffect(() => { + if (!changes?.isDispatch) { + try { + const prettierCode = codePrettier(changes.value, changes.cursor); + setValue(prettierCode.formatted, { + cursor: prettierCode.cursorOffset, + }); + } catch (e) { + // do nothing + } + } + }, [debounceValue]); + + useEffect(() => { + if (!state.doc.changedByEditor) { + setValue(JSON.stringify(state.doc.payload, undefined, 4), {}); + } + }, [state.doc.payload]); + + return ( + <> + + + ); +}; + +export default BlockEditor; diff --git a/packages/uikit-playground/src/Components/CodeEditor/Extensions/Extensions.ts b/packages/uikit-playground/src/Components/CodeEditor/Extensions/Extensions.ts new file mode 100644 index 000000000000..cb276ceaf2f9 --- /dev/null +++ b/packages/uikit-playground/src/Components/CodeEditor/Extensions/Extensions.ts @@ -0,0 +1,25 @@ +import { json } from '@codemirror/lang-json'; +import { EditorView } from 'codemirror'; + +import highlightStyle from './HighlightStyle'; +import basicSetup from './basicSetup'; +import jsonLinter from './jsonLinter'; +// import payloadLinter from './payloadLinter'; +import theme from './theme'; + +export const actionBlockExtensions = [ + highlightStyle, + json(), + jsonLinter, + basicSetup, + // payloadLinter, + ...theme, +]; + +export const actionPreviewExtensions = [ + EditorView.contentAttributes.of({ contenteditable: 'false' }), + highlightStyle, + json(), + basicSetup, + ...theme, +]; diff --git a/packages/uikit-playground/src/Components/CodeEditor/Extensions/HighlightStyle.ts b/packages/uikit-playground/src/Components/CodeEditor/Extensions/HighlightStyle.ts index 3329c3c6a859..fc5aa5e9e958 100644 --- a/packages/uikit-playground/src/Components/CodeEditor/Extensions/HighlightStyle.ts +++ b/packages/uikit-playground/src/Components/CodeEditor/Extensions/HighlightStyle.ts @@ -6,6 +6,7 @@ const highLightStyle = () => { { tag: t.literal, color: 'var(--RCPG-primary-color)' }, { tag: t.bool, color: 'var(--RCPG-tertary-color)' }, { tag: t.number, color: 'var(--RCPG-secondary-color)' }, + { tag: t.null, color: 'var(--RCPG-tertary-color)' }, ]); return syntaxHighlighting(style); diff --git a/packages/uikit-playground/src/Components/CodeEditor/Extensions/index.ts b/packages/uikit-playground/src/Components/CodeEditor/Extensions/index.ts index 9dda5b45b58d..4e2251e75a9c 100644 --- a/packages/uikit-playground/src/Components/CodeEditor/Extensions/index.ts +++ b/packages/uikit-playground/src/Components/CodeEditor/Extensions/index.ts @@ -2,9 +2,8 @@ import { javascript } from '@codemirror/lang-javascript'; import highlightStyle from './HighlightStyle'; import basicSetup from './basicSetup'; -import lint from './lint'; import theme from './theme'; -const extensions = [highlightStyle, javascript(), lint, basicSetup, ...theme]; +const extensions = [highlightStyle, javascript(), basicSetup, ...theme]; export default extensions; diff --git a/packages/uikit-playground/src/Components/CodeEditor/Extensions/jsonLinter.ts b/packages/uikit-playground/src/Components/CodeEditor/Extensions/jsonLinter.ts new file mode 100644 index 000000000000..663ec6092024 --- /dev/null +++ b/packages/uikit-playground/src/Components/CodeEditor/Extensions/jsonLinter.ts @@ -0,0 +1,4 @@ +import { jsonParseLinter } from '@codemirror/lang-json'; +import { lintGutter, linter } from '@codemirror/lint'; + +export default [lintGutter(), linter(jsonParseLinter())]; diff --git a/packages/uikit-playground/src/Components/CodeEditor/Extensions/lint.ts b/packages/uikit-playground/src/Components/CodeEditor/Extensions/lint.ts deleted file mode 100644 index d8eb7870f0ec..000000000000 --- a/packages/uikit-playground/src/Components/CodeEditor/Extensions/lint.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { esLint } from '@codemirror/lang-javascript'; -import { lintGutter, linter } from '@codemirror/lint'; -import Linter from 'eslint4b-prebuilt'; - -export default [lintGutter(), linter(esLint(new Linter()))]; diff --git a/packages/uikit-playground/src/Components/CodeEditor/Extensions/payloadLinter.ts b/packages/uikit-playground/src/Components/CodeEditor/Extensions/payloadLinter.ts new file mode 100644 index 000000000000..e6a2b8168998 --- /dev/null +++ b/packages/uikit-playground/src/Components/CodeEditor/Extensions/payloadLinter.ts @@ -0,0 +1,65 @@ +import { syntaxTree } from '@codemirror/language'; +import type { Diagnostic } from '@codemirror/lint'; +import { linter } from '@codemirror/lint'; +import type { EditorView } from 'codemirror'; + +import parsePayload from '../Parser'; + +const payloadLinter = linter((view: EditorView) => { + const diagnostics: Diagnostic[] = []; + const tree = syntaxTree(view.state); + let head = tree.topNode.firstChild; + if (!head || !head.matchContext(['Script'])) { + diagnostics.push({ + from: 0, + to: 0, + message: 'Expecting a Script', + severity: 'error', + }); + return diagnostics; + } + head = head.firstChild; + if (!head || !head.matchContext(['ExpressionStatement'])) { + diagnostics.push({ + from: 0, + to: 0, + message: 'Expecting an expression statement', + severity: 'error', + }); + return diagnostics; + } + head = head.firstChild; + if (!head || !head.matchContext(['ArrayExpression'])) { + diagnostics.push({ + from: 0, + to: 0, + message: 'Expecting an array expression', + severity: 'error', + }); + return diagnostics; + } + // while (head.nextSibling && head.nextSibling.name !== ']') { + // } + do { + if ( + head.name !== '[' && + head.name !== ',' && + head.name !== ']' && + head.name !== 'ObjectExpression' + ) { + diagnostics.push({ + from: head.from, + to: head.to, + message: 'Expecting an Object expression', + severity: 'error', + }); + return diagnostics; + } + if (head.name === 'ObjectExpression') parsePayload(head, diagnostics, view); + head = head.nextSibling; + } while (head); + + return diagnostics; +}); + +export default payloadLinter; diff --git a/packages/uikit-playground/src/Components/CodeEditor/Parser/index.ts b/packages/uikit-playground/src/Components/CodeEditor/Parser/index.ts new file mode 100644 index 000000000000..482568e69baf --- /dev/null +++ b/packages/uikit-playground/src/Components/CodeEditor/Parser/index.ts @@ -0,0 +1 @@ +export { default } from './parsePayload'; diff --git a/packages/uikit-playground/src/Components/CodeEditor/Parser/parsePayload.ts b/packages/uikit-playground/src/Components/CodeEditor/Parser/parsePayload.ts new file mode 100644 index 000000000000..114ec242009d --- /dev/null +++ b/packages/uikit-playground/src/Components/CodeEditor/Parser/parsePayload.ts @@ -0,0 +1,15 @@ +import type { Diagnostic } from '@codemirror/lint'; +import type { EditorView } from 'codemirror'; + +const parsePayload = ( + head: any, + Diagnostic: Diagnostic[], + view: EditorView +) => { + const payload = JSON.parse( + view.state.doc.toString().slice(head.from, head.to) + ); + payload && 1; +}; + +export default parsePayload; diff --git a/packages/uikit-playground/src/Components/CodeEditor/PreviewEditor.tsx b/packages/uikit-playground/src/Components/CodeEditor/PreviewEditor.tsx new file mode 100644 index 000000000000..055a17aae465 --- /dev/null +++ b/packages/uikit-playground/src/Components/CodeEditor/PreviewEditor.tsx @@ -0,0 +1,27 @@ +import type { Extension } from '@codemirror/state'; +import { Box } from '@rocket.chat/fuselage'; +import { useEffect, useContext } from 'react'; + +import { context } from '../../Context'; +import useCodeMirror from '../../hooks/useCodeMirror'; + +type CodeMirrorProps = { + extensions?: Extension[], +}; + +const PreviewEditor = ({ extensions }: CodeMirrorProps) => { + const { state } = useContext(context); + const { editor, setValue } = useCodeMirror(extensions, `{}`); + + useEffect(() => { + setValue(JSON.stringify(state.actionPreview, undefined, 4), {}); + }, [state.actionPreview]); + + return ( + <> + + + ); +}; + +export default PreviewEditor; diff --git a/packages/uikit-playground/src/Components/CodeEditor/index.tsx b/packages/uikit-playground/src/Components/CodeEditor/index.tsx index 781c00c4821a..e9547eeaa08c 100644 --- a/packages/uikit-playground/src/Components/CodeEditor/index.tsx +++ b/packages/uikit-playground/src/Components/CodeEditor/index.tsx @@ -4,13 +4,12 @@ import { useDebouncedValue } from '@rocket.chat/fuselage-hooks'; import json5 from 'json5'; import { useEffect, useContext } from 'react'; -import { context } from '../../Context'; -import { docAction } from '../../Context/action'; +import { docAction, context } from '../../Context'; import useCodeMirror from '../../hooks/useCodeMirror'; import codePrettier from '../../utils/codePrettier'; type CodeMirrorProps = { - extensions?: Extension[]; + extensions?: Extension[], }; const CodeEditor = ({ extensions }: CodeMirrorProps) => { @@ -19,10 +18,9 @@ const CodeEditor = ({ extensions }: CodeMirrorProps) => { extensions, json5.stringify(state.doc.payload, undefined, 4) ); - const debounceValue = useDebouncedValue(changes?.value, 500); + const debounceValue = useDebouncedValue(changes?.value, 1500); useEffect(() => { - console.log('a'); if (!changes?.isDispatch) { try { const parsedCode = json5.parse(changes.value); @@ -35,15 +33,12 @@ const CodeEditor = ({ extensions }: CodeMirrorProps) => { dispatch(docAction({ payload: parsedCode })); } catch (e) { - console.log(e); // do nothing } } - // eslint-disable-next-line react-hooks/exhaustive-deps }, [changes?.value]); useEffect(() => { - console.log('b'); if (!changes?.isDispatch) { try { const prettierCode = codePrettier(changes.value, changes.cursor); @@ -54,15 +49,12 @@ const CodeEditor = ({ extensions }: CodeMirrorProps) => { // do nothing } } - // eslint-disable-next-line react-hooks/exhaustive-deps }, [debounceValue]); useEffect(() => { - console.log('c'); if (!state.doc.changedByEditor) { setValue(JSON.stringify(state.doc.payload, undefined, 4), {}); } - // eslint-disable-next-line react-hooks/exhaustive-deps }, [state.doc.payload]); return ( diff --git a/packages/uikit-playground/src/Components/ComponentSideBar/ScrollableSideBar.tsx b/packages/uikit-playground/src/Components/ComponentSideBar/ScrollableSideBar.tsx index 1c75c93cbf6a..e614f458f1c9 100644 --- a/packages/uikit-playground/src/Components/ComponentSideBar/ScrollableSideBar.tsx +++ b/packages/uikit-playground/src/Components/ComponentSideBar/ScrollableSideBar.tsx @@ -1,14 +1,15 @@ import { css } from '@rocket.chat/css-in-js'; import { Scrollable, Box } from '@rocket.chat/fuselage'; import type { FC } from 'react'; +import React from 'react'; -import BlocksTree from '../../Payload/BlocksTree'; +import BlocksTree from '../../Payload/actionBlock/BlocksTree'; import DropDown from '../DropDown'; const ScrollableSideBar: FC = () => ( { const { @@ -49,6 +48,7 @@ const SliderBtn: FC = () => { transition: var(--animation-default); `; + // eslint-disable-next-line no-nested-ternary const toggleStyle = !isMobile ? css` left: 0px; diff --git a/packages/uikit-playground/src/Components/Draggable/DraggableList.tsx b/packages/uikit-playground/src/Components/Draggable/DraggableList.tsx index 76e7af15538d..2900127afdda 100644 --- a/packages/uikit-playground/src/Components/Draggable/DraggableList.tsx +++ b/packages/uikit-playground/src/Components/Draggable/DraggableList.tsx @@ -1,50 +1,44 @@ import type { LayoutBlock } from '@rocket.chat/ui-kit'; -import * as React from 'react'; +import React from 'react'; import type { OnDragEndResponder } from 'react-beautiful-dnd'; import { DragDropContext, Droppable } from 'react-beautiful-dnd'; import DraggableListItem from './DraggableListItem'; export type Block = { - id: string; - payload: LayoutBlock; + id: string, + payload: LayoutBlock, }; export type DraggableListProps = { - blocks: Block[]; - surface?: number; - onDragEnd: OnDragEndResponder; + blocks: Block[], + surface?: number, + onDragEnd: OnDragEndResponder, }; const DraggableList = React.memo( ({ blocks, surface, onDragEnd }: DraggableListProps) => ( - <> - - <> - - {(provided) => ( -
- <> - {blocks.map((block, index) => ( - - ))} - {provided.placeholder} - -
- )} -
- -
- + + + {(provided) => ( +
+ {blocks.map((block, index) => ( + + ))} + {provided.placeholder} +
+ )} +
+
) ); diff --git a/packages/uikit-playground/src/Components/Draggable/DraggableListItem.tsx b/packages/uikit-playground/src/Components/Draggable/DraggableListItem.tsx index d06d2769f15e..6b644d37a684 100644 --- a/packages/uikit-playground/src/Components/Draggable/DraggableListItem.tsx +++ b/packages/uikit-playground/src/Components/Draggable/DraggableListItem.tsx @@ -1,12 +1,13 @@ +import * as React from 'react'; import { Draggable } from 'react-beautiful-dnd'; import RenderPayload from '../Preview/Display/RenderPayload/RenderPayload'; import type { Block } from './DraggableList'; export type DraggableListItemProps = { - block: Block; - surface: number; - index: number; + block: Block, + surface: number, + index: number, }; const DraggableListItem = ({ diff --git a/packages/uikit-playground/src/Components/DropDown/DropDown.tsx b/packages/uikit-playground/src/Components/DropDown/DropDown.tsx index dd6470a4d632..cc4580576a1f 100644 --- a/packages/uikit-playground/src/Components/DropDown/DropDown.tsx +++ b/packages/uikit-playground/src/Components/DropDown/DropDown.tsx @@ -1,11 +1,11 @@ import { Box } from '@rocket.chat/fuselage'; -import { Fragment } from 'react'; +import React, { Fragment } from 'react'; import Items from './Items'; import type { Item, ItemBranch } from './types'; interface DropDownProps { - readonly BlocksTree: Item; + readonly BlocksTree: Item, } const DropDown = ({ BlocksTree }: DropDownProps) => { diff --git a/packages/uikit-playground/src/Components/DropDown/Items.tsx b/packages/uikit-playground/src/Components/DropDown/Items.tsx index a8cc4acea83f..49bb502434d2 100644 --- a/packages/uikit-playground/src/Components/DropDown/Items.tsx +++ b/packages/uikit-playground/src/Components/DropDown/Items.tsx @@ -1,12 +1,11 @@ import { css } from '@rocket.chat/css-in-js'; import { Box, Label, Chevron } from '@rocket.chat/fuselage'; -import { useState, useContext } from 'react'; +import React, { useState, useContext } from 'react'; -import { context } from '../../Context'; +import { context, docAction } from '../../Context'; import ItemsIcon from './ItemsIcon'; import { itemStyle, labelStyle } from './itemsStyle'; import type { ItemProps } from './types'; -import { docAction } from '../../Context/action'; const Items = ({ label, children, layer, payload }: ItemProps) => { const [isOpen, toggleItemOpen] = useState(layer === 1); diff --git a/packages/uikit-playground/src/Components/DropDown/ItemsIcon.tsx b/packages/uikit-playground/src/Components/DropDown/ItemsIcon.tsx index 9a1d74f3f1f1..1bd1554c6b84 100644 --- a/packages/uikit-playground/src/Components/DropDown/ItemsIcon.tsx +++ b/packages/uikit-playground/src/Components/DropDown/ItemsIcon.tsx @@ -1,13 +1,14 @@ import { Icon } from '@rocket.chat/fuselage'; +import React from 'react'; const ItemsIcon = ({ layer, lastNode, hover, }: { - layer: number; - lastNode: boolean; - hover: boolean; + layer: number, + lastNode: boolean, + hover: boolean, }) => { const selectIcon = (layer: number, hover: boolean) => { if (layer === 1) { @@ -18,9 +19,7 @@ const ItemsIcon = ({ if (lastNode) { return ; } - return ( - - ); + return ; }; return <>{selectIcon(layer, hover)}; }; diff --git a/packages/uikit-playground/src/Components/NavBar/BurgerIcon/BurgerIcon.tsx b/packages/uikit-playground/src/Components/NavBar/BurgerIcon/BurgerIcon.tsx index af02130ca4e0..4c1409153c01 100644 --- a/packages/uikit-playground/src/Components/NavBar/BurgerIcon/BurgerIcon.tsx +++ b/packages/uikit-playground/src/Components/NavBar/BurgerIcon/BurgerIcon.tsx @@ -1,6 +1,6 @@ import { usePrefersReducedMotion } from '@rocket.chat/fuselage-hooks'; import type { ReactElement, ReactNode } from 'react'; -import { useContext } from 'react'; +import React, { useContext } from 'react'; import { context } from '../../../Context'; import Line from './Line'; diff --git a/packages/uikit-playground/src/Components/NavBar/BurgerIcon/Line.tsx b/packages/uikit-playground/src/Components/NavBar/BurgerIcon/Line.tsx index e1ddfed3ac0b..30c22f53d05b 100644 --- a/packages/uikit-playground/src/Components/NavBar/BurgerIcon/Line.tsx +++ b/packages/uikit-playground/src/Components/NavBar/BurgerIcon/Line.tsx @@ -1,13 +1,14 @@ import { css } from '@rocket.chat/css-in-js'; import { Box } from '@rocket.chat/fuselage'; import type { ReactElement } from 'react'; +import React from 'react'; const Line = ({ animated, moved, }: { - animated: boolean; - moved?: boolean; + animated: boolean, + moved?: boolean, }): ReactElement => { const animatedStyle = animated ? css` diff --git a/packages/uikit-playground/src/Components/NavBar/BurgerIcon/Wrapper.tsx b/packages/uikit-playground/src/Components/NavBar/BurgerIcon/Wrapper.tsx index 0d3f8eefa45d..b484b7800f39 100644 --- a/packages/uikit-playground/src/Components/NavBar/BurgerIcon/Wrapper.tsx +++ b/packages/uikit-playground/src/Components/NavBar/BurgerIcon/Wrapper.tsx @@ -1,6 +1,7 @@ import { css } from '@rocket.chat/css-in-js'; import { Box } from '@rocket.chat/fuselage'; import type { ReactElement, ReactNode } from 'react'; +import React from 'react'; const Wrapper = ({ children }: { children: ReactNode }): ReactElement => ( ; diff --git a/packages/uikit-playground/src/Components/NavBar/Logo.tsx b/packages/uikit-playground/src/Components/NavBar/Logo.tsx index 1ea6ccbd5939..64849882d3c7 100644 --- a/packages/uikit-playground/src/Components/NavBar/Logo.tsx +++ b/packages/uikit-playground/src/Components/NavBar/Logo.tsx @@ -1,6 +1,7 @@ import { Box } from '@rocket.chat/fuselage'; import { RocketChatLogo } from '@rocket.chat/logo'; import type { FC } from 'react'; +import React from 'react'; const Logo: FC = () => ( ( > - + + + + + + + + diff --git a/packages/uikit-playground/src/Components/NavBar/RightNavBtn.tsx b/packages/uikit-playground/src/Components/NavBar/RightNavBtn.tsx index 653ab5c07da0..6dc4c2cfb8c4 100644 --- a/packages/uikit-playground/src/Components/NavBar/RightNavBtn.tsx +++ b/packages/uikit-playground/src/Components/NavBar/RightNavBtn.tsx @@ -1,9 +1,8 @@ import { Box, Button } from '@rocket.chat/fuselage'; import type { FC } from 'react'; -import { useContext } from 'react'; +import React, { useContext } from 'react'; -import { context } from '../../Context'; -import { navMenuToggleAction } from '../../Context/action'; +import { context, navMenuToggleAction } from '../../Context'; import BurgerIcon from './BurgerIcon'; const RightNavBtn: FC = () => { diff --git a/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/DeleteElementBtn.tsx b/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/DeleteElementBtn.tsx index 2d03bce3595b..aed482c6d9ec 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/DeleteElementBtn.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/DeleteElementBtn.tsx @@ -1,9 +1,8 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */ import { Icon } from '@rocket.chat/fuselage'; -import { useContext } from 'react'; +import React, { useContext } from 'react'; -import { context } from '../../../../Context'; -import { docAction } from '../../../../Context/action'; +import { context, docAction } from '../../../../Context'; const Display = ({ elementIndex }: { elementIndex: number }) => { const { state, dispatch } = useContext(context); diff --git a/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/ElementWrapper.tsx b/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/ElementWrapper.tsx index e8f4ded24758..0f031532f3df 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/ElementWrapper.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/ElementWrapper.tsx @@ -5,7 +5,7 @@ import type { ReactElement, ReactNode } from 'react'; const ElementWrapper = ({ children, }: { - children: ReactNode; + children: ReactNode, }): ReactElement => ( { - const uiKitRender: { [key: number]: () => unknown } = { + const uiKitRender: { [key: number]: any } = { '1': () => uiKitMessage(payload), '2': () => uiKitBanner(payload), '3': () => uiKitModal(payload), diff --git a/packages/uikit-playground/src/Components/Preview/Display/Surface/BannerSurface.tsx b/packages/uikit-playground/src/Components/Preview/Display/Surface/BannerSurface.tsx index d6eb3a92754e..f3dcb5860401 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/Surface/BannerSurface.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/Surface/BannerSurface.tsx @@ -1,4 +1,5 @@ import { Banner, Icon } from '@rocket.chat/fuselage'; +import React from 'react'; import DraggableList from '../../../Draggable/DraggableList'; import type { DraggableListProps } from '../../../Draggable/DraggableList'; diff --git a/packages/uikit-playground/src/Components/Preview/Display/Surface/MessageSurface.tsx b/packages/uikit-playground/src/Components/Preview/Display/Surface/MessageSurface.tsx index d1a8d74c8b96..86f87a288f7d 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/Surface/MessageSurface.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/Surface/MessageSurface.tsx @@ -1,4 +1,5 @@ import { Message, Avatar } from '@rocket.chat/fuselage'; +import React from 'react'; import DraggableList from '../../../Draggable/DraggableList'; import type { DraggableListProps } from '../../../Draggable/DraggableList'; @@ -23,10 +24,8 @@ const MessageSurface = ({ blocks, onDragEnd }: DraggableListProps) => ( - - Haylie George{' '} - @haylie.george - + Haylie George + @haylie.george Admin User Owner diff --git a/packages/uikit-playground/src/Components/Preview/Display/Surface/ModalSurface.tsx b/packages/uikit-playground/src/Components/Preview/Display/Surface/ModalSurface.tsx index 909cc05274f6..de38af3eff7a 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/Surface/ModalSurface.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/Surface/ModalSurface.tsx @@ -9,6 +9,7 @@ import { ButtonGroup, Button, } from '@rocket.chat/fuselage'; +import React from 'react'; import DraggableList from '../../../Draggable/DraggableList'; import type { DraggableListProps } from '../../../Draggable/DraggableList'; diff --git a/packages/uikit-playground/src/Components/Preview/Display/Surface/Surface.tsx b/packages/uikit-playground/src/Components/Preview/Display/Surface/Surface.tsx index 630c16a7d27f..be7e93584a9d 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/Surface/Surface.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/Surface/Surface.tsx @@ -1,9 +1,11 @@ import { Box } from '@rocket.chat/fuselage'; +import { UiKitContext } from '@rocket.chat/fuselage-ui-kit'; import type { FC } from 'react'; -import { useContext, useState, useEffect } from 'react'; +import React, { useContext, useState, useEffect } from 'react'; import type { DropResult } from 'react-beautiful-dnd'; -import { context } from '../../../../Context'; +import { context, docAction, actionPreviewAction } from '../../../../Context'; +import generateActionPreview from '../../../../Payload/actionPreview/generateActionPreview'; import type { Block } from '../../../Draggable/DraggableList'; import BannerSurface from './BannerSurface'; import MessageSurface from './MessageSurface'; @@ -17,30 +19,66 @@ const Surface: FC = () => { doc: { payload }, surface, }, + dispatch, } = useContext(context); - const [uniqueBlocks, setUniqueBlocks] = useState(payload.map((block, i) => ({ id: `${i}`, payload: block }))); - + const [uniqueBlocks, setUniqueBlocks] = useState<{ + block: Block[]; + isChangeByDnd: boolean; + }>({ + block: payload.map((block, i) => ({ id: `${i}`, payload: block })), + isChangeByDnd: false, + }); + const preview = generateActionPreview('Action Block', {}); useEffect(() => { - setUniqueBlocks(payload.map((block, i) => ({ id: `${i}`, payload: block }))); + setUniqueBlocks({ + block: payload.map((block, i) => ({ id: `${i}`, payload: block })), + isChangeByDnd: false, + }); }, [payload]); + useEffect(() => { + if (uniqueBlocks.isChangeByDnd) { + dispatch( + docAction({ + payload: uniqueBlocks.block.map((block) => block.payload), + changedByEditor: false, + }), + ); + } + }, [uniqueBlocks]); + const onDragEnd = ({ destination, source }: DropResult) => { if (!destination) return; - const newBlocks = reorder(uniqueBlocks, source.index, destination.index); + const newBlocks = reorder(uniqueBlocks.block, source.index, destination.index); - setUniqueBlocks(newBlocks); + setUniqueBlocks({ block: newBlocks, isChangeByDnd: true }); }; - const surfaceRender: { [key: number]: () => JSX.Element } = { - '1': () => , - '2': () => , - '3': () => , + const surfaceRender: { [key: number]: any } = { + '1': () => , + '2': () => , + '3': () => , '4': () => , }; return ( - - {surfaceRender[surface]()} + + { + preview.action = a; + dispatch(actionPreviewAction({ ...preview })); + }, + state: (s) => { + preview.state = s; + dispatch(actionPreviewAction({ ...preview })); + }, + values: {}, + appId: 'core', + }} + > + {surfaceRender[surface]()}{' '} + ); }; diff --git a/packages/uikit-playground/src/Components/Preview/Editor/Editor.tsx b/packages/uikit-playground/src/Components/Preview/Editor/ActionBlockEditor.tsx similarity index 55% rename from packages/uikit-playground/src/Components/Preview/Editor/Editor.tsx rename to packages/uikit-playground/src/Components/Preview/Editor/ActionBlockEditor.tsx index 7b39ea56e372..a7b0b5e09347 100644 --- a/packages/uikit-playground/src/Components/Preview/Editor/Editor.tsx +++ b/packages/uikit-playground/src/Components/Preview/Editor/ActionBlockEditor.tsx @@ -1,10 +1,11 @@ import { Box, Scrollable } from '@rocket.chat/fuselage'; import type { FC } from 'react'; +import React from 'react'; -import CodeEditor from '../../CodeEditor'; -import extensions from '../../CodeEditor/Extensions'; +import BlockEditor from '../../CodeEditor/BlockEditor'; +import { actionBlockExtensions } from '../../CodeEditor/Extensions/Extensions'; -const Editor: FC = () => ( +const ActionBlockEditor: FC = () => ( ( borderInlineStart={'var(--default-border)'} overflow={'auto'} > - + ); -export default Editor; +export default ActionBlockEditor; diff --git a/packages/uikit-playground/src/Components/Preview/Editor/ActionPreviewEditor.tsx b/packages/uikit-playground/src/Components/Preview/Editor/ActionPreviewEditor.tsx new file mode 100644 index 000000000000..70e8c31f655d --- /dev/null +++ b/packages/uikit-playground/src/Components/Preview/Editor/ActionPreviewEditor.tsx @@ -0,0 +1,25 @@ +import { Box, Scrollable } from '@rocket.chat/fuselage'; +import type { FC } from 'react'; +import React from 'react'; + +import { actionPreviewExtensions } from '../../CodeEditor/Extensions/Extensions'; +import PreviewEditor from '../../CodeEditor/PreviewEditor'; + +const ActionPreviewEditor: FC = () => ( + + + + + +); + +export default ActionPreviewEditor; diff --git a/packages/uikit-playground/src/Components/Preview/Editor/EditorPanel.tsx b/packages/uikit-playground/src/Components/Preview/Editor/EditorPanel.tsx new file mode 100644 index 000000000000..14cf52e76f00 --- /dev/null +++ b/packages/uikit-playground/src/Components/Preview/Editor/EditorPanel.tsx @@ -0,0 +1,77 @@ +import { css } from '@rocket.chat/css-in-js'; +import { Box } from '@rocket.chat/fuselage'; +import type { FC } from 'react'; +import React, { useContext } from 'react'; + +import { context, editorTabsToggleAction } from '../../../Context'; +import ToggleTabs from '../../ToggleTabs'; +import ActionBlockEditor from './ActionBlockEditor'; +import ActionPreviewEditor from './ActionPreviewEditor'; + +const EditorPanel: FC = () => { + const tabsItem: string[] = ['Action Block', 'Action Preview']; + const { + state: { editorTabsToggle }, + dispatch, + } = useContext(context); + + const toggleTabsHandler = (index: number) => { + dispatch(editorTabsToggleAction(index)); + }; + + const tabChangeStyle = () => { + switch (editorTabsToggle) { + case 0: + return css` + transition: 0.5s ease; + left: 0; + `; + case 1: + return css` + transition: 0.5s ease; + left: -100%; + `; + } + }; + + return ( + + + + + + + + + + + + ); +}; +export default EditorPanel; diff --git a/packages/uikit-playground/src/Components/Preview/Editor/index.tsx b/packages/uikit-playground/src/Components/Preview/Editor/index.tsx index e7967e758ab1..88fa3c8aa53e 100644 --- a/packages/uikit-playground/src/Components/Preview/Editor/index.tsx +++ b/packages/uikit-playground/src/Components/Preview/Editor/index.tsx @@ -1 +1 @@ -export { default } from './Editor'; +export { default } from './EditorPanel'; diff --git a/packages/uikit-playground/src/Components/Preview/NavPanel/NavPanel.tsx b/packages/uikit-playground/src/Components/Preview/NavPanel/NavPanel.tsx index d4c20e159aed..a856fafb320b 100644 --- a/packages/uikit-playground/src/Components/Preview/NavPanel/NavPanel.tsx +++ b/packages/uikit-playground/src/Components/Preview/NavPanel/NavPanel.tsx @@ -1,47 +1,41 @@ import { css } from '@rocket.chat/css-in-js'; -import { Box, ButtonGroup, Icon } from '@rocket.chat/fuselage'; -import { useContext } from 'react'; +import { Box } from '@rocket.chat/fuselage'; import type { FC } from 'react'; +import React, { useContext } from 'react'; -import { context } from '../../../Context'; +import { context, previewTabsToggleAction } from '../../../Context'; import SurfaceSelect from '../../SurfaceSelect'; -import PanelBtn from './PanelBtn'; -import TabChange from './TabChange'; +import ToggleTabs from '../../ToggleTabs'; const NavPanel: FC = () => { const { - state: { isMobile, isTablet }, + state: { isMobile, isTablet, previewTabsToggle }, + dispatch, } = useContext(context); + const toggleTabsHandler = (index: number) => { + dispatch(previewTabsToggleAction(index)); + }; + const tabsItem: string[] = ['Preview', 'Editor']; return ( - + - - - } name={'Clear Blocks'} isSmall={isTablet} /> - } name={'Copy Payload'} isSmall={isTablet} /> - - - {isTablet && } + {isTablet && } ); }; diff --git a/packages/uikit-playground/src/Components/Preview/NavPanel/PanelBtn.tsx b/packages/uikit-playground/src/Components/Preview/NavPanel/PanelBtn.tsx index 7e49ab128443..2cf3f2f9dc41 100644 --- a/packages/uikit-playground/src/Components/Preview/NavPanel/PanelBtn.tsx +++ b/packages/uikit-playground/src/Components/Preview/NavPanel/PanelBtn.tsx @@ -1,7 +1,7 @@ import { css } from '@rocket.chat/css-in-js'; import { Button, Label } from '@rocket.chat/fuselage'; import type { FC, ReactNode } from 'react'; -import { useState } from 'react'; +import React, { useState } from 'react'; const PanelBtn: FC<{ icon: ReactNode; name: string; isSmall: boolean }> = ({ icon, name, isSmall }) => { const [hover, setHover] = useState(false); @@ -17,12 +17,12 @@ const PanelBtn: FC<{ icon: ReactNode; name: string; isSmall: boolean }> = ({ ico - {payload.map((element) => ( - + ))} diff --git a/packages/uikit-playground/src/Context/initialState.ts b/packages/uikit-playground/src/Context/initialState.ts index d6815c76b1da..661f70fffe91 100644 --- a/packages/uikit-playground/src/Context/initialState.ts +++ b/packages/uikit-playground/src/Context/initialState.ts @@ -1,11 +1,13 @@ import type { LayoutBlock } from '@rocket.chat/ui-kit'; +import { SurfaceOptions } from '../Components/Preview/Display/Surface/constant'; import getUniqueId from '../utils/getUniqueId'; export type docType = { payload: readonly LayoutBlock[]; id: string; name: string; + surface: SurfaceOptions; changedByEditor?: boolean; }; @@ -50,7 +52,6 @@ export type initialStateType = { previewTabsToggle: number; editorTabsToggle: number; navMenuToggle: boolean; - surface: number; activeScreen: string; screens: ScreensType; actionPreview: actionPreviewType; @@ -68,8 +69,7 @@ export const initialState: initialStateType = { previewTabsToggle: 0, editorTabsToggle: 0, navMenuToggle: false, - surface: 1, - screens: {[initialPageId] : { id: initialPageId, name: 'default1', payload: [], changedByEditor: true }, + screens: {[initialPageId] : { id: initialPageId, name: 'default1', payload: [], surface: SurfaceOptions.Message, changedByEditor: true }, }, activeScreen: initialPageId, actionPreview: {}, diff --git a/packages/uikit-playground/src/Context/reducer.ts b/packages/uikit-playground/src/Context/reducer.ts index e5d6080aa99c..d69dd92de516 100644 --- a/packages/uikit-playground/src/Context/reducer.ts +++ b/packages/uikit-playground/src/Context/reducer.ts @@ -1,5 +1,6 @@ import _ from 'lodash'; +import { SurfaceOptions } from '../Components/Preview/Display/Surface/constant'; import getUniqueId from '../utils/getUniqueId'; import type { initialStateType } from './initialState'; @@ -22,7 +23,17 @@ const reducer = (state: initialStateType, action: actionType) => { case 'navMenuToggle': return { ...state, navMenuToggle: action.payload }; case 'surface': - return { ...state, surface: action.payload }; + return { + ...state, + screens: { + ...state.screens, + [state.activeScreen]: { + ...state.screens[state.activeScreen], + surface: action.payload, + changedByEditor: false, + }, + }, + }; case 'updatePayload': return { ...state, @@ -56,6 +67,7 @@ const reducer = (state: initialStateType, action: actionType) => { ...state.screens, [id]: { id, + surface: SurfaceOptions.Message, name: action?.payload || 'default', payload: [], changedByEditor: true, @@ -72,6 +84,7 @@ const reducer = (state: initialStateType, action: actionType) => { screens: { ...state.screens, [id]: { + ...state.screens[action.payload.id], id, name: action?.payload.name || 'default', payload: state.screens[action.payload.id].payload, diff --git a/packages/uikit-playground/src/Payload/actionPreview/container.ts b/packages/uikit-playground/src/Payload/actionPreview/container.ts index 22ecfca5a6b0..ddc6cf9708f1 100644 --- a/packages/uikit-playground/src/Payload/actionPreview/container.ts +++ b/packages/uikit-playground/src/Payload/actionPreview/container.ts @@ -1,19 +1,23 @@ +import { SurfaceOptions } from '../../Components/Preview/Display/Surface/constant'; + type containerType = { - type: string; - text: string; + [key: number]: { + type: string, + text: string, + }, }; -const container: containerType[] = [ - { +const container: containerType = { + [SurfaceOptions.Message]: { type: 'message', text: 'The contents of the original message where the action originated', }, - { + [SurfaceOptions.Banner]: { type: 'banner', text: '', }, - { + [SurfaceOptions.Modal]: { type: 'modal', text: '', }, -]; +}; export default container; diff --git a/packages/uikit-playground/src/Payload/actionPreview/generateActionPreview.ts b/packages/uikit-playground/src/Payload/actionPreview/generateActionPreview.ts index 66456e91db36..65daf4829d59 100644 --- a/packages/uikit-playground/src/Payload/actionPreview/generateActionPreview.ts +++ b/packages/uikit-playground/src/Payload/actionPreview/generateActionPreview.ts @@ -1,12 +1,13 @@ import { useContext } from 'react'; +import { SurfaceOptions } from '../../Components/Preview/Display/Surface/constant'; import { context } from '../../Context'; import type { actionPreviewType } from '../../Context/initialState'; import container from './container'; const generateActionPreview = (type: string, data: actionPreviewType) => { const { - state: { user, surface, screens, activeScreen }, + state: { user, screens, activeScreen }, } = useContext(context); const actionPreview: actionPreviewType = { @@ -14,7 +15,8 @@ const generateActionPreview = (type: string, data: actionPreviewType) => { user, api_app_id: '', token: '', - container: container[surface - 1], + container: + container[screens[activeScreen].surface || SurfaceOptions.Message], trigger_id: '', team: null, enterprise: null, diff --git a/packages/uikit-playground/src/utils/uiKitRenderer.ts b/packages/uikit-playground/src/utils/uiKitRenderer.ts new file mode 100644 index 000000000000..e69de29bb2d1 From 8a2fff2759eb25d3899ac6271ca590c008abdf59 Mon Sep 17 00:00:00 2001 From: intVivek Date: Sat, 10 Jun 2023 17:48:38 +0530 Subject: [PATCH 08/50] chores(uikit-playground): revamp Reactflow and screen selector --- packages/uikit-playground/src/App.tsx | 1 + .../CreateNewScreen/ScreenThumbnail.tsx | 84 +++++++++--------- .../ScreenThumbnailWrapper.tsx | 23 ++++- .../FlowContainer/ConnectionLine.tsx | 37 ++++++++ .../FlowContainer/FlowContainer.tsx | 86 +++++++++++++------ .../Components/FlowContainer/UIKitWrapper.tsx | 48 ++++++++--- .../src/Components/FlowContainer/utils.ts | 34 ++++++++ .../Display/RenderPayload/ElementWrapper.tsx | 2 +- .../Preview/Display/Surface/ModalSurface.tsx | 9 +- .../uikit-playground/src/Context/reducer.ts | 1 + packages/uikit-playground/src/_global.css | 55 ++++++++++++ 11 files changed, 291 insertions(+), 89 deletions(-) create mode 100644 packages/uikit-playground/src/Components/FlowContainer/ConnectionLine.tsx create mode 100644 packages/uikit-playground/src/Components/FlowContainer/utils.ts create mode 100644 packages/uikit-playground/src/_global.css diff --git a/packages/uikit-playground/src/App.tsx b/packages/uikit-playground/src/App.tsx index b4264788ad7a..bd49d508c729 100644 --- a/packages/uikit-playground/src/App.tsx +++ b/packages/uikit-playground/src/App.tsx @@ -1,5 +1,6 @@ import React from 'react'; import './App.css'; +import './_global.css'; import './cssVariables.css'; import { ToastBarProvider } from '@rocket.chat/fuselage-toastbar'; import { BrowserRouter, Route, Routes } from 'react-router-dom'; diff --git a/packages/uikit-playground/src/Components/CreateNewScreen/ScreenThumbnail.tsx b/packages/uikit-playground/src/Components/CreateNewScreen/ScreenThumbnail.tsx index f316a2d5b508..bee68e5dfa62 100644 --- a/packages/uikit-playground/src/Components/CreateNewScreen/ScreenThumbnail.tsx +++ b/packages/uikit-playground/src/Components/CreateNewScreen/ScreenThumbnail.tsx @@ -1,24 +1,16 @@ -import { css } from '@rocket.chat/css-in-js'; -import { Box, Button } from '@rocket.chat/fuselage'; -import type { ReactNode, ComponentProps } from 'react'; -import React, { useContext, useState } from 'react'; +import { Box, Menu } from '@rocket.chat/fuselage'; +import { useToastBarDispatch } from '@rocket.chat/fuselage-toastbar'; +import type { MouseEvent } from 'react'; +import React, { useContext } from 'react'; +import ScreenThumbnailWrapper from './ScreenThumbnailWrapper'; +import Thumbnail from './Thumbnail'; import { context } from '../../Context'; import { activeScreenAction } from '../../Context/action/activeScreenAction'; import { deleteScreenAction } from '../../Context/action/deleteScreenAction'; import { duplicateScreenAction } from '../../Context/action/duplicateScreenAction'; import type { docType } from '../../Context/initialState'; import renderPayload from '../Preview/Display/RenderPayload/RenderPayload'; -import ScreenThumbnailWrapper from './ScreenThumbnailWrapper'; -import Thumbnail from './Thumbnail'; - -const IntractButton = ({ - label, - ...props -}: { - label: string, - icon?: ReactNode, -} & ComponentProps) => ; const ScreenThumbnail = ({ screen, @@ -28,46 +20,52 @@ const ScreenThumbnail = ({ disableDelete: boolean, }) => { const { dispatch } = useContext(context); - const [isHover, setIsHover] = useState(false); + const toast = useToastBarDispatch(); - const activateScreenHandler = () => { + const activateScreenHandler = (e: MouseEvent) => { + e.stopPropagation(); dispatch(activeScreenAction(screen?.id)); }; - const duplicateScreenHandler = () => { + const duplicateScreenHandler = (e: MouseEvent) => { + e.stopPropagation(); dispatch(duplicateScreenAction({ id: screen?.id })); }; - const deleteScreenHandler = () => { + const deleteScreenHandler = (e: MouseEvent) => { + e.stopPropagation(); + if (disableDelete) + return toast({ + type: 'info', + message: 'Cannot delete last screen.', + }); dispatch(deleteScreenAction(screen?.id)); }; return ( - setIsHover(true)} - onFocus={() => setIsHover(true)} - onMouseOut={() => setIsHover(false)} - onBlur={() => setIsHover(false)} - > + - - - - e.stopPropagation()}> + Duplicate, + }, + delete: { + label: ( + + Delete + + ), + disabled: disableDelete, + }, + }} /> diff --git a/packages/uikit-playground/src/Components/CreateNewScreen/ScreenThumbnailWrapper.tsx b/packages/uikit-playground/src/Components/CreateNewScreen/ScreenThumbnailWrapper.tsx index 766ffe76f3c7..376b38268ea7 100644 --- a/packages/uikit-playground/src/Components/CreateNewScreen/ScreenThumbnailWrapper.tsx +++ b/packages/uikit-playground/src/Components/CreateNewScreen/ScreenThumbnailWrapper.tsx @@ -5,8 +5,10 @@ import React from 'react'; const ScreenThumbnailWrapper = ({ children, + onClick, ...props }: { + onClick?: ComponentProps['onClick'], children: ReactNode, } & ComponentProps) => ( - + + {children} diff --git a/packages/uikit-playground/src/Components/FlowContainer/ConnectionLine.tsx b/packages/uikit-playground/src/Components/FlowContainer/ConnectionLine.tsx new file mode 100644 index 000000000000..fdb6c2582a52 --- /dev/null +++ b/packages/uikit-playground/src/Components/FlowContainer/ConnectionLine.tsx @@ -0,0 +1,37 @@ +import React from 'react'; + +const ConnectionLine = ({ + fromX, + fromY, + toX, + toY, +}: { + fromX: number, + fromY: number, + fromPosition: string, + toX: number, + toY: number, + toPosition: string, + connectionLineType: string, + connectionLineStyle?: any, +}) => ( + + + + +); + +export default ConnectionLine; diff --git a/packages/uikit-playground/src/Components/FlowContainer/FlowContainer.tsx b/packages/uikit-playground/src/Components/FlowContainer/FlowContainer.tsx index d33055ed83c7..7abed4d92296 100644 --- a/packages/uikit-playground/src/Components/FlowContainer/FlowContainer.tsx +++ b/packages/uikit-playground/src/Components/FlowContainer/FlowContainer.tsx @@ -1,4 +1,4 @@ -import { useCallback, useContext } from 'react'; +import { useCallback, useContext, useRef } from 'react'; import ReactFlow, { MiniMap, Controls, @@ -6,11 +6,14 @@ import ReactFlow, { useNodesState, useEdgesState, addEdge, + updateEdge, } from 'reactflow'; import 'reactflow/dist/style.css'; import { context } from '../../Context'; +import ConnectionLine from './ConnectionLine'; import UIKitWrapper from './UIKitWrapper'; +import { FlowParams, createNodesAndEdges } from './utils'; const nodeTypes = { custom: UIKitWrapper, @@ -21,39 +24,66 @@ const FlowContainer = () => { state: { screens }, } = useContext(context); - // const initialNodes = [ - // { id: '1', position: { x: 0, y: 0 }, data: { label: '1' } }, - // { id: '2', position: { x: 0, y: 100 }, data: { label: '2' } }, - // ]; - const initialNodes = Object.values(screens).map((screen) => ({ - id: screen.id, - type: 'custom', - position: { x: 0, y: 0 }, - data: screen, - })); - - const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes); + const { nodes: initialNodes } = createNodesAndEdges(screens); + + const [nodes, , onNodesChange] = useNodesState(initialNodes); const [edges, setEdges, onEdgesChange] = useEdgesState([]); + const edgeUpdateSuccessful = useRef(true); const onConnect = useCallback( - (params) => setEdges((eds) => addEdge(params, eds)), + (params) => { + if (params.source === params.target) return; + setEdges((eds) => + addEdge( + { + ...params, + type: FlowParams.edgeType, + markerEnd: FlowParams.markerEnd, + style: FlowParams.style, + }, + eds + ) + ); + }, [setEdges] ); + + const onEdgeUpdateStart = useCallback(() => { + edgeUpdateSuccessful.current = false; + }, []); + + const onEdgeUpdate = useCallback((oldEdge, newConnection) => { + edgeUpdateSuccessful.current = true; + setEdges((els) => updateEdge(oldEdge, newConnection, els)); + }, []); + + const onEdgeUpdateEnd = useCallback((_, edge) => { + if (!edgeUpdateSuccessful.current) { + setEdges((eds) => eds.filter((e) => e.id !== edge.id)); + } + edgeUpdateSuccessful.current = true; + }, []); + return ( - - - - - + <> + + + + + + ); }; diff --git a/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper.tsx b/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper.tsx index b25cfb66d1d6..00ed32671c6b 100644 --- a/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper.tsx +++ b/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper.tsx @@ -1,19 +1,43 @@ import { Box } from '@rocket.chat/fuselage'; -import React from 'react'; +import React, { memo } from 'react'; +import { Handle, Position } from 'reactflow'; import type { docType } from '../../Context/initialState'; import RenderPayload from '../Preview/Display/RenderPayload/RenderPayload'; import SurfaceRender from '../Preview/Display/Surface/SurfaceRender'; -const UIKitWrapper = ({ id, data }: { id: string, data: docType }) => { - console.log(data, id); - return ( - - - - - - ); -}; +const UIKitWrapper = ({ id, data }: { id: string, data: docType }) => ( + + + + {data.payload.map((payload, index) => ( + + + + + ))} + + +); -export default UIKitWrapper; +export default memo(UIKitWrapper); diff --git a/packages/uikit-playground/src/Components/FlowContainer/utils.ts b/packages/uikit-playground/src/Components/FlowContainer/utils.ts new file mode 100644 index 000000000000..a09148ac4989 --- /dev/null +++ b/packages/uikit-playground/src/Components/FlowContainer/utils.ts @@ -0,0 +1,34 @@ +import { MarkerType } from 'reactflow'; + +import type { ScreensType } from '../../Context/initialState'; + +export function createNodesAndEdges(screens: ScreensType) { + const center = { x: window.innerWidth / 2, y: window.innerHeight / 2 }; + + const nodes = Object.values(screens).map((screen, i) => { + const degrees = i * (360 / 8); + const radians = degrees * (Math.PI / 180); + const x = 250 * Math.cos(radians) + center.x; + const y = 250 * Math.sin(radians) + center.y; + + return { + id: screen.id, + type: 'custom', + position: { x, y }, + data: screen, + }; + }); + + return { nodes }; +} + +export const FlowParams = { + edgeType: 'smoothstep', + markerEnd: { + type: MarkerType.Arrow, + }, + style: { + strokeWidth: 2, + stroke: 'var(--RCPG-primary-color)', + }, +}; diff --git a/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/ElementWrapper.tsx b/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/ElementWrapper.tsx index 2842850cc3f8..132901fdaf46 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/ElementWrapper.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/ElementWrapper.tsx @@ -16,7 +16,7 @@ const ElementWrapper = ({ height: fit-content; align-items: center; transition: var(--animation-fast); - padding: 0 8px; + padding: 0px 8px; &:hover { border-radius: 4px; diff --git a/packages/uikit-playground/src/Components/Preview/Display/Surface/ModalSurface.tsx b/packages/uikit-playground/src/Components/Preview/Display/Surface/ModalSurface.tsx index 4185db41db17..54502649520a 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/Surface/ModalSurface.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/Surface/ModalSurface.tsx @@ -1,3 +1,4 @@ +import { css } from '@rocket.chat/css-in-js'; import { Modal, ModalHeader, @@ -19,7 +20,13 @@ const ModalSurface = ({ children }: { children: ReactNode }) => ( Modal Header - {children} + + {children} + diff --git a/packages/uikit-playground/src/Context/reducer.ts b/packages/uikit-playground/src/Context/reducer.ts index d69dd92de516..05826f4b91a6 100644 --- a/packages/uikit-playground/src/Context/reducer.ts +++ b/packages/uikit-playground/src/Context/reducer.ts @@ -91,6 +91,7 @@ const reducer = (state: initialStateType, action: actionType) => { changedByEditor: true, }, }, + openCreateNewScreen: false, activeScreen: id, }; } diff --git a/packages/uikit-playground/src/_global.css b/packages/uikit-playground/src/_global.css new file mode 100644 index 000000000000..2d1df8cfd6bb --- /dev/null +++ b/packages/uikit-playground/src/_global.css @@ -0,0 +1,55 @@ +.react-flow__edges{ + z-index: 1000 !important; +} + +.react-flow__nodes{ + z-index: 1 !important; +} + +.react-flow-targetHandle{ + width: 8px !important; height: 12px !important; + border-radius: 2px !important; + background: rgb(125, 161, 185) !important; +} + +.react-flow-sourceHandle{ + +} + +/* .react-flow-sourceHandle{ + width: 8px !important; height: 12px !important; + border-radius: 2px !important; + background: rgb(125, 161, 185) !important; +} */ + +/* .react-flow-sourceHandle-message-left{ + left: -82px !important; +} + +.react-flow-sourceHandle-message-right{ + right: -38px !important; +} + +.react-flow-sourceHandle-banner-left{ + left: -60px !important; +} + +.react-flow-sourceHandle-banner-right{ + right: -30px !important; +} + +.react-flow-sourceHandle-modal-left{ + left: -38px !important; +} + +.react-flow-sourceHandle-modal-right{ + right: -38px !important; +} */ + +.rcx-modal:has(.uiKitWrapper){ + padding: 0px !important +} + +.rcx-modal__content:has(.uiKitWrapper){ + overflow: visible !important +} \ No newline at end of file From e4fd1a4ce3be5a509e817b0775a1d557b94ea397 Mon Sep 17 00:00:00 2001 From: intVivek Date: Mon, 12 Jun 2023 02:53:49 +0530 Subject: [PATCH 09/50] refactor(uikit-playground): Fix Types in context --- packages/uikit-playground/src/App.tsx | 14 +- .../src/Context/action/actionPreviewAction.ts | 9 +- .../src/Context/action/activeScreenAction.ts | 10 +- .../Context/action/createNewScreenAction.ts | 10 +- .../src/Context/action/deleteScreenAction.ts | 10 +- .../Context/action/duplicateScreenAction.ts | 10 +- .../Context/action/editorTabsToggleAction.ts | 10 +- .../src/Context/action/index.ts | 17 ++ .../src/Context/action/isMobileAction.ts | 10 +- .../src/Context/action/isTabletAction.ts | 10 +- .../src/Context/action/navMenuToggleAction.ts | 10 +- .../action/openCreateNewScreenAction.ts | 10 +- .../Context/action/previewTabsToggleAction.ts | 10 +- .../src/Context/action/sidebarToggleAction.ts | 10 +- .../src/Context/action/surfaceAction.ts | 10 +- .../src/Context/action/tabsToggleAction.ts | 10 +- .../Context/action/templatesToggleAction.ts | 10 +- .../src/Context/action/updatePayloadAction.ts | 18 +- .../src/Context/action/userAction.ts | 9 +- .../uikit-playground/src/Context/reducer.ts | 255 +++++++++++------- 20 files changed, 278 insertions(+), 184 deletions(-) diff --git a/packages/uikit-playground/src/App.tsx b/packages/uikit-playground/src/App.tsx index bd49d508c729..77a6c84e00ca 100644 --- a/packages/uikit-playground/src/App.tsx +++ b/packages/uikit-playground/src/App.tsx @@ -17,19 +17,8 @@ function App() { return ( - {/* - } /> - } - /> - } - /> - } /> - */} + } /> }> } /> } /> - } /> }> } /> diff --git a/packages/uikit-playground/src/Context/action/actionPreviewAction.ts b/packages/uikit-playground/src/Context/action/actionPreviewAction.ts index fbcc1995c324..fabdd706594e 100644 --- a/packages/uikit-playground/src/Context/action/actionPreviewAction.ts +++ b/packages/uikit-playground/src/Context/action/actionPreviewAction.ts @@ -1,11 +1,12 @@ import type { actionPreviewType } from '../initialState'; +import { ActionTypes } from '../reducer'; -type action = { - type: string, +export type ActionPreviewAction = { + type: ActionTypes.ActionPreview, payload: actionPreviewType, }; -export const actionPreviewAction = (payload: actionPreviewType): action => ({ - type: 'actionPreview', +export const actionPreviewAction = (payload: actionPreviewType): ActionPreviewAction => ({ + type: ActionTypes.ActionPreview, payload, }); diff --git a/packages/uikit-playground/src/Context/action/activeScreenAction.ts b/packages/uikit-playground/src/Context/action/activeScreenAction.ts index d3fe5a2fac8e..8e578a2a707e 100644 --- a/packages/uikit-playground/src/Context/action/activeScreenAction.ts +++ b/packages/uikit-playground/src/Context/action/activeScreenAction.ts @@ -1,9 +1,11 @@ -type action = { - type: string, +import { ActionTypes } from "../reducer"; + +export type ActiveScreenAction = { + type: ActionTypes.ActiveScreen, payload: string, }; -export const activeScreenAction = (payload: string): action => ({ - type: 'activeScreen', +export const activeScreenAction = (payload: string): ActiveScreenAction => ({ + type: ActionTypes.ActiveScreen, payload, }); diff --git a/packages/uikit-playground/src/Context/action/createNewScreenAction.ts b/packages/uikit-playground/src/Context/action/createNewScreenAction.ts index 08c9820d196c..bf54e3fb8153 100644 --- a/packages/uikit-playground/src/Context/action/createNewScreenAction.ts +++ b/packages/uikit-playground/src/Context/action/createNewScreenAction.ts @@ -1,9 +1,11 @@ -type action = { - type: string, +import { ActionTypes } from "../reducer"; + +export type CreateNewScreenAction = { + type: ActionTypes.CreateNewScreen, payload?: string, }; -export const createNewScreenAction = (payload?: string): action => ({ - type: 'createNewScreen', +export const createNewScreenAction = (payload?: string): CreateNewScreenAction => ({ + type: ActionTypes.CreateNewScreen, payload, }); diff --git a/packages/uikit-playground/src/Context/action/deleteScreenAction.ts b/packages/uikit-playground/src/Context/action/deleteScreenAction.ts index 9a5e67a251b2..a33c076a3d80 100644 --- a/packages/uikit-playground/src/Context/action/deleteScreenAction.ts +++ b/packages/uikit-playground/src/Context/action/deleteScreenAction.ts @@ -1,9 +1,11 @@ -type action = { - type: string, +import { ActionTypes } from "../reducer"; + +export type DeleteScreenAction = { + type: ActionTypes.DeleteScreen, payload: string, }; -export const deleteScreenAction = (payload: string): action => ({ - type: 'deleteScreen', +export const deleteScreenAction = (payload: string): DeleteScreenAction => ({ + type: ActionTypes.DeleteScreen, payload, }); diff --git a/packages/uikit-playground/src/Context/action/duplicateScreenAction.ts b/packages/uikit-playground/src/Context/action/duplicateScreenAction.ts index ed298c800111..cdfe976b8487 100644 --- a/packages/uikit-playground/src/Context/action/duplicateScreenAction.ts +++ b/packages/uikit-playground/src/Context/action/duplicateScreenAction.ts @@ -1,12 +1,14 @@ -type action = { - type: string, +import { ActionTypes } from "../reducer"; + +export type DuplicateScreenAction = { + type: ActionTypes.DuplicateScreen, payload: { id: string, name?: string }, }; export const duplicateScreenAction = (payload: { id: string, name?: string, -}): action => ({ - type: 'duplicateScreen', +}): DuplicateScreenAction => ({ + type: ActionTypes.DuplicateScreen, payload, }); diff --git a/packages/uikit-playground/src/Context/action/editorTabsToggleAction.ts b/packages/uikit-playground/src/Context/action/editorTabsToggleAction.ts index e1f658a5b210..df5d5d27bb0d 100644 --- a/packages/uikit-playground/src/Context/action/editorTabsToggleAction.ts +++ b/packages/uikit-playground/src/Context/action/editorTabsToggleAction.ts @@ -1,9 +1,11 @@ -type action = { - type: string, +import { ActionTypes } from "../reducer"; + +export type EditorTabsToggleAction = { + type: ActionTypes.EditorToggle, payload: number, }; -export const editorTabsToggleAction = (payload: number): action => ({ - type: 'editorToggle', +export const editorTabsToggleAction = (payload: number): EditorTabsToggleAction => ({ + type: ActionTypes.EditorToggle, payload, }); diff --git a/packages/uikit-playground/src/Context/action/index.ts b/packages/uikit-playground/src/Context/action/index.ts index 8833802ff469..bcd837c9409e 100644 --- a/packages/uikit-playground/src/Context/action/index.ts +++ b/packages/uikit-playground/src/Context/action/index.ts @@ -14,3 +14,20 @@ export { createNewScreenAction } from './createNewScreenAction'; export { activeScreenAction } from './activeScreenAction'; export { duplicateScreenAction } from './duplicateScreenAction'; export { deleteScreenAction } from './deleteScreenAction'; + +export type { IsMobileAction } from './isMobileAction'; +export type { IsTabletAction } from './isTabletAction'; +export type { SidebarToggleAction } from './sidebarToggleAction'; +export type { EditorTabsToggleAction } from './editorTabsToggleAction'; +export type { PreviewTabsToggleAction } from './previewTabsToggleAction'; +export type { NavMenuToggleAction } from './navMenuToggleAction'; +export type { UpdatePayloadAction } from './updatePayloadAction'; +export type { SurfaceAction } from './surfaceAction'; +export type { ActionPreviewAction } from './actionPreviewAction'; +export type { UserAction } from './userAction'; +export type { TemplatesToggleAction } from './templatesToggleAction'; +export type { OpenCreateNewScreenAction } from './openCreateNewScreenAction'; +export type { CreateNewScreenAction } from './createNewScreenAction'; +export type { ActiveScreenAction } from './activeScreenAction'; +export type { DuplicateScreenAction } from './duplicateScreenAction'; +export type { DeleteScreenAction } from './deleteScreenAction'; diff --git a/packages/uikit-playground/src/Context/action/isMobileAction.ts b/packages/uikit-playground/src/Context/action/isMobileAction.ts index 434a8f567aa9..2985481ccde7 100644 --- a/packages/uikit-playground/src/Context/action/isMobileAction.ts +++ b/packages/uikit-playground/src/Context/action/isMobileAction.ts @@ -1,9 +1,11 @@ -type action = { - type: string, +import { ActionTypes } from "../reducer"; + +export type IsMobileAction = { + type: ActionTypes.IsMobile, payload: boolean, }; -export const isMobileAction = (payload: boolean): action => ({ - type: 'isMobile', +export const isMobileAction = (payload: boolean): IsMobileAction => ({ + type: ActionTypes.IsMobile, payload, }); diff --git a/packages/uikit-playground/src/Context/action/isTabletAction.ts b/packages/uikit-playground/src/Context/action/isTabletAction.ts index 068d8df07e00..9c3d0f4f1218 100644 --- a/packages/uikit-playground/src/Context/action/isTabletAction.ts +++ b/packages/uikit-playground/src/Context/action/isTabletAction.ts @@ -1,9 +1,11 @@ -type action = { - type: string, +import { ActionTypes } from "../reducer"; + +export type IsTabletAction = { + type: ActionTypes.IsTablet, payload: boolean, }; -export const isTabletAction = (payload: boolean): action => ({ - type: 'isTablet', +export const isTabletAction = (payload: boolean): IsTabletAction => ({ + type: ActionTypes.IsTablet, payload, }); diff --git a/packages/uikit-playground/src/Context/action/navMenuToggleAction.ts b/packages/uikit-playground/src/Context/action/navMenuToggleAction.ts index 1a2fef9d2147..66ebbce2af9f 100644 --- a/packages/uikit-playground/src/Context/action/navMenuToggleAction.ts +++ b/packages/uikit-playground/src/Context/action/navMenuToggleAction.ts @@ -1,9 +1,11 @@ -type action = { - type: string, +import { ActionTypes } from "../reducer"; + +export type NavMenuToggleAction = { + type: ActionTypes.NavMenuToggle, payload: boolean, }; -export const navMenuToggleAction = (payload: boolean): action => ({ - type: 'navMenuToggle', +export const navMenuToggleAction = (payload: boolean): NavMenuToggleAction => ({ + type: ActionTypes.NavMenuToggle, payload, }); diff --git a/packages/uikit-playground/src/Context/action/openCreateNewScreenAction.ts b/packages/uikit-playground/src/Context/action/openCreateNewScreenAction.ts index d050d47fa3bc..e67c49f8ec52 100644 --- a/packages/uikit-playground/src/Context/action/openCreateNewScreenAction.ts +++ b/packages/uikit-playground/src/Context/action/openCreateNewScreenAction.ts @@ -1,9 +1,11 @@ -type action = { - type: string, +import { ActionTypes } from "../reducer"; + +export type OpenCreateNewScreenAction = { + type: ActionTypes.OpenCreateNewScreen, payload: boolean, }; -export const openCreateNewScreenAction = (payload: boolean): action => ({ - type: 'openCreateNewScreen', +export const openCreateNewScreenAction = (payload: boolean): OpenCreateNewScreenAction => ({ + type: ActionTypes.OpenCreateNewScreen, payload, }); diff --git a/packages/uikit-playground/src/Context/action/previewTabsToggleAction.ts b/packages/uikit-playground/src/Context/action/previewTabsToggleAction.ts index c108d492d2da..cdae84f1caca 100644 --- a/packages/uikit-playground/src/Context/action/previewTabsToggleAction.ts +++ b/packages/uikit-playground/src/Context/action/previewTabsToggleAction.ts @@ -1,9 +1,11 @@ -type action = { - type: string, +import { ActionTypes } from "../reducer"; + +export type PreviewTabsToggleAction = { + type: ActionTypes.PreviewToggle, payload: number, }; -export const previewTabsToggleAction = (payload: number): action => ({ - type: 'previewToggle', +export const previewTabsToggleAction = (payload: number): PreviewTabsToggleAction => ({ + type: ActionTypes.PreviewToggle, payload, }); diff --git a/packages/uikit-playground/src/Context/action/sidebarToggleAction.ts b/packages/uikit-playground/src/Context/action/sidebarToggleAction.ts index 3b43c7e2dea5..57148bb61507 100644 --- a/packages/uikit-playground/src/Context/action/sidebarToggleAction.ts +++ b/packages/uikit-playground/src/Context/action/sidebarToggleAction.ts @@ -1,9 +1,11 @@ -type action = { - type: string, +import { ActionTypes } from "../reducer"; + +export type SidebarToggleAction = { + type: ActionTypes.SidebarToggle, payload: boolean, }; -export const sidebarToggleAction = (payload: boolean): action => ({ - type: 'sidebarToggle', +export const sidebarToggleAction = (payload: boolean): SidebarToggleAction => ({ + type: ActionTypes.SidebarToggle, payload, }); diff --git a/packages/uikit-playground/src/Context/action/surfaceAction.ts b/packages/uikit-playground/src/Context/action/surfaceAction.ts index 74f8c665e324..594d4a9acb07 100644 --- a/packages/uikit-playground/src/Context/action/surfaceAction.ts +++ b/packages/uikit-playground/src/Context/action/surfaceAction.ts @@ -1,9 +1,11 @@ -type action = { - type: string, +import { ActionTypes } from "../reducer"; + +export type SurfaceAction = { + type: ActionTypes.Surface, payload: number, }; -export const surfaceAction = (payload: number): action => ({ - type: 'surface', +export const surfaceAction = (payload: number): SurfaceAction => ({ + type: ActionTypes.Surface, payload, }); diff --git a/packages/uikit-playground/src/Context/action/tabsToggleAction.ts b/packages/uikit-playground/src/Context/action/tabsToggleAction.ts index 38a17c2f73bc..fafe9f6eb76b 100644 --- a/packages/uikit-playground/src/Context/action/tabsToggleAction.ts +++ b/packages/uikit-playground/src/Context/action/tabsToggleAction.ts @@ -1,9 +1,11 @@ -type action = { - type: string, +import { ActionTypes } from "../reducer"; + +export type TabsToggleAction = { + type: ActionTypes.EditorToggle, payload: number, }; -export const tabsToggleAction = (payload: number): action => ({ - type: 'editorToggle', +export const tabsToggleAction = (payload: number): TabsToggleAction => ({ + type: ActionTypes.EditorToggle, payload, }); diff --git a/packages/uikit-playground/src/Context/action/templatesToggleAction.ts b/packages/uikit-playground/src/Context/action/templatesToggleAction.ts index a3dd86b7989a..79918048de82 100644 --- a/packages/uikit-playground/src/Context/action/templatesToggleAction.ts +++ b/packages/uikit-playground/src/Context/action/templatesToggleAction.ts @@ -1,9 +1,11 @@ -type action = { - type: string, +import { ActionTypes } from "../reducer"; + +export type TemplatesToggleAction = { + type: ActionTypes.TemplatesToggle, payload: boolean, }; -export const templatesToggleAction = (payload: boolean): action => ({ - type: 'templatesToggle', +export const templatesToggleAction = (payload: boolean): TemplatesToggleAction => ({ + type: ActionTypes.TemplatesToggle, payload, }); diff --git a/packages/uikit-playground/src/Context/action/updatePayloadAction.ts b/packages/uikit-playground/src/Context/action/updatePayloadAction.ts index 80646957b7eb..3ad445aa10d9 100644 --- a/packages/uikit-playground/src/Context/action/updatePayloadAction.ts +++ b/packages/uikit-playground/src/Context/action/updatePayloadAction.ts @@ -1,11 +1,17 @@ -import type { docType } from '../initialState'; +import type { LayoutBlock } from '@rocket.chat/ui-kit'; +import { ActionTypes } from '../reducer'; -type action = { - type: string, - payload: Partial, +type PayloadType ={ + payload: readonly LayoutBlock[]; + changedByEditor?: boolean; +} + +export type UpdatePayloadAction = { + type: ActionTypes.UpdatePayload, + payload:PayloadType, }; -export const updatePayloadAction = (payload: Partial): action => ({ - type: 'updatePayload', +export const updatePayloadAction = (payload: PayloadType): UpdatePayloadAction => ({ + type: ActionTypes.UpdatePayload, payload, }); diff --git a/packages/uikit-playground/src/Context/action/userAction.ts b/packages/uikit-playground/src/Context/action/userAction.ts index ab1d0ea512cd..7e47389d21c1 100644 --- a/packages/uikit-playground/src/Context/action/userAction.ts +++ b/packages/uikit-playground/src/Context/action/userAction.ts @@ -1,11 +1,12 @@ import type { userType } from '../initialState'; +import { ActionTypes } from '../reducer'; -type action = { - type: string, +export type UserAction = { + type: ActionTypes.User, payload: userType, }; -export const userAction = (payload: userType): action => ({ - type: 'user', +export const userAction = (payload: userType): UserAction => ({ + type: ActionTypes.User, payload, }); diff --git a/packages/uikit-playground/src/Context/reducer.ts b/packages/uikit-playground/src/Context/reducer.ts index 05826f4b91a6..07c5d8374360 100644 --- a/packages/uikit-playground/src/Context/reducer.ts +++ b/packages/uikit-playground/src/Context/reducer.ts @@ -3,116 +3,169 @@ import _ from 'lodash'; import { SurfaceOptions } from '../Components/Preview/Display/Surface/constant'; import getUniqueId from '../utils/getUniqueId'; import type { initialStateType } from './initialState'; +import { + IsMobileAction, + IsTabletAction, + SidebarToggleAction, + PreviewTabsToggleAction, + TemplatesToggleAction, + NavMenuToggleAction, + SurfaceAction, + UpdatePayloadAction, + ActionPreviewAction, + UserAction, + OpenCreateNewScreenAction, + ActiveScreenAction, + CreateNewScreenAction, + DuplicateScreenAction, + DeleteScreenAction, + EditorTabsToggleAction, +} from './action'; -type actionType = { type: string, payload?: any }; + type IAction = + | IsMobileAction + | IsTabletAction + | SidebarToggleAction + | PreviewTabsToggleAction + | EditorTabsToggleAction + | TemplatesToggleAction + | NavMenuToggleAction + | SurfaceAction + | UpdatePayloadAction + | ActionPreviewAction + | UserAction + | OpenCreateNewScreenAction + | ActiveScreenAction + | CreateNewScreenAction + | DuplicateScreenAction + | DeleteScreenAction; -const reducer = (state: initialStateType, action: actionType) => { - switch (action.type) { - case 'isMobile': - return { ...state, isMobile: action.payload }; - case 'isTablet': - return { ...state, isTablet: action.payload }; - case 'sidebarToggle': - return { ...state, sideBarToggle: action.payload }; - case 'previewToggle': - return { ...state, previewTabsToggle: action.payload }; - case 'editorToggle': - return { ...state, editorTabsToggle: action.payload }; - case 'templatesToggle': - return { ...state, templatesToggle: action.payload }; - case 'navMenuToggle': - return { ...state, navMenuToggle: action.payload }; - case 'surface': - return { - ...state, - screens: { - ...state.screens, - [state.activeScreen]: { - ...state.screens[state.activeScreen], - surface: action.payload, - changedByEditor: false, + export enum ActionTypes { + IsMobile, + IsTablet, + SidebarToggle, + PreviewToggle, + EditorToggle, + TemplatesToggle, + NavMenuToggle, + Surface, + UpdatePayload, + ActionPreview, + User, + OpenCreateNewScreen, + ActiveScreen, + CreateNewScreen, + DuplicateScreen, + DeleteScreen, + } + + const reducer = (state: initialStateType, action: IAction) => { + switch (action.type) { + case ActionTypes.IsMobile: + return { ...state, isMobile: action.payload }; + case ActionTypes.IsTablet: + return { ...state, isTablet: action.payload }; + case ActionTypes.SidebarToggle: + return { ...state, sidebarToggle: action.payload }; + case ActionTypes.PreviewToggle: + return { ...state, previewTabsToggle: action.payload }; + case ActionTypes.EditorToggle: + return { ...state, editorTabsToggle: action.payload }; + case ActionTypes.TemplatesToggle: + return { ...state, templatesToggle: action.payload }; + case ActionTypes.NavMenuToggle: + return { ...state, navMenuToggle: action.payload }; + case ActionTypes.Surface: + return { + ...state, + screens: { + ...state.screens, + [state.activeScreen]: { + ...state.screens[state.activeScreen], + surface: action.payload, + changedByEditor: false, + }, }, - }, - }; - case 'updatePayload': - return { - ...state, - screens: { - ...state.screens, - [state.activeScreen]: { - ...state.screens[state.activeScreen], - payload: action.payload.payload, - changedByEditor: action.payload.changedByEditor === undefined, + }; + case ActionTypes.UpdatePayload: + return { + ...state, + screens: { + ...state.screens, + [state.activeScreen]: { + ...state.screens[state.activeScreen], + payload: action?.payload?.payload, + changedByEditor: action?.payload?.changedByEditor === undefined, + }, }, - }, - }; - case 'actionPreview': - return { ...state, actionPreview: action.payload }; - case 'user': - return { ...state, user: action.payload }; - case 'openCreateNewScreen': - return { ...state, openCreateNewScreen: action.payload }; - case 'activeScreen': - return { - ...state, - screens: _.cloneDeep(state.screens), - openCreateNewScreen: false, - activeScreen: action.payload, - }; - case 'createNewScreen': { - const id = getUniqueId(); - return { - ...state, - screens: { - ...state.screens, - [id]: { - id, - surface: SurfaceOptions.Message, - name: action?.payload || 'default', - payload: [], - changedByEditor: true, + }; + case ActionTypes.ActionPreview: + return { ...state, actionPreview: action.payload }; + case ActionTypes.User: + return { ...state, user: action.payload }; + case ActionTypes.OpenCreateNewScreen: + return { ...state, openCreateNewScreen: action.payload }; + case ActionTypes.ActiveScreen: + return { + ...state, + screens: _.cloneDeep(state.screens), + openCreateNewScreen: false, + activeScreen: action.payload, + }; + case ActionTypes.CreateNewScreen: { + const id = getUniqueId(); + return { + ...state, + screens: { + ...state.screens, + [id]: { + id, + surface: SurfaceOptions.Message, + name: action?.payload || 'default', + payload: [], + changedByEditor: true, + }, }, - }, - openCreateNewScreen: false, - activeScreen: id, - }; - } - case 'duplicateScreen': { - const id = getUniqueId(); - return { - ...state, - screens: { - ...state.screens, - [id]: { - ...state.screens[action.payload.id], - id, - name: action?.payload.name || 'default', - payload: state.screens[action.payload.id].payload, - changedByEditor: true, + openCreateNewScreen: false, + activeScreen: id, + }; + } + case ActionTypes.DuplicateScreen: { + const id = getUniqueId(); + return { + ...state, + screens: { + ...state.screens, + [id]: { + ...state.screens[action.payload.id], + id, + name: action?.payload.name || 'default', + payload: state.screens[action?.payload?.id].payload, + changedByEditor: true, + }, }, - }, - openCreateNewScreen: false, - activeScreen: id, - }; - } - case 'deleteScreen': { - const screens = _.cloneDeep(state.screens); - delete screens[action.payload]; - if (state.activeScreen === action.payload) { + openCreateNewScreen: false, + activeScreen: id, + }; + } + case ActionTypes.DeleteScreen: { + const screens = _.cloneDeep(state.screens); + delete screens[action?.payload]; + if (state.activeScreen === action.payload) { + return { + ...state, + screens, + activeScreen: Object.keys(screens)[0], + }; + } return { ...state, screens, - activeScreen: Object.keys(screens)[0], }; } - return { - ...state, - screens, - }; + default: + return state; } - default: - return state; - } -}; - -export default reducer; + }; + + export default reducer; From acd21b3a857d9a9c39cb4a5ecdf1e8b766106849 Mon Sep 17 00:00:00 2001 From: intVivek Date: Wed, 14 Jun 2023 01:05:05 +0530 Subject: [PATCH 10/50] fix(uikit-playground): Added Prettier --- package.json | 1 + packages/uikit-playground/.prettierrc | 5 +++++ yarn.lock | 8 ++++++++ 3 files changed, 14 insertions(+) create mode 100644 packages/uikit-playground/.prettierrc diff --git a/package.json b/package.json index 80c5d3bf1e25..16bb729554d9 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "@changesets/cli": "^2.26.1", "@types/chart.js": "^2.9.37", "@types/js-yaml": "^4.0.5", + "@types/prettier": "^2", "husky": "^7.0.4", "turbo": "latest" }, diff --git a/packages/uikit-playground/.prettierrc b/packages/uikit-playground/.prettierrc new file mode 100644 index 000000000000..e97ea1bfabba --- /dev/null +++ b/packages/uikit-playground/.prettierrc @@ -0,0 +1,5 @@ +{ + "tabWidth": 2, + "useTabs": false, + "singleQuote": true +} diff --git a/yarn.lock b/yarn.lock index 4f60ccfa7ce6..642ce97a90e5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12165,6 +12165,13 @@ __metadata: languageName: node linkType: hard +"@types/prettier@npm:^2": + version: 2.7.3 + resolution: "@types/prettier@npm:2.7.3" + checksum: 705384209cea6d1433ff6c187c80dcc0b95d99d5c5ce21a46a9a58060c527973506822e428789d842761e0280d25e3359300f017fbe77b9755bc772ab3dc2f83 + languageName: node + linkType: hard + "@types/prettier@npm:^2.1.5, @types/prettier@npm:^2.6.3": version: 2.6.3 resolution: "@types/prettier@npm:2.6.3" @@ -33567,6 +33574,7 @@ __metadata: "@changesets/cli": ^2.26.1 "@types/chart.js": ^2.9.37 "@types/js-yaml": ^4.0.5 + "@types/prettier": ^2 husky: ^7.0.4 turbo: latest languageName: unknown From 73b405c5bfdd1b8cf489facf83058ada5de48e5e Mon Sep 17 00:00:00 2001 From: intVivek Date: Sun, 18 Jun 2023 22:00:21 +0530 Subject: [PATCH 11/50] feat(uikit-playground): Added context for "projects" --- .../src/Components/CodeEditor/BlockEditor.tsx | 16 +- .../Components/CodeEditor/PreviewEditor.tsx | 15 +- .../CreateNewScreenContainer.tsx | 23 +- .../Components/Draggable/DraggableList.tsx | 15 +- .../src/Components/DropDown/Items.tsx | 97 +++--- .../Preview/Display/Surface/Surface.tsx | 144 +++++---- .../Preview/Display/Surface/SurfaceRender.tsx | 6 +- .../SurfaceSelect/SurfaceSelect.tsx | 4 +- .../src/Context/initialState.ts | 55 ++-- .../uikit-playground/src/Context/reducer.ts | 277 +++++++++--------- .../actionPreview/generateActionPreview.ts | 32 +- 11 files changed, 377 insertions(+), 307 deletions(-) diff --git a/packages/uikit-playground/src/Components/CodeEditor/BlockEditor.tsx b/packages/uikit-playground/src/Components/CodeEditor/BlockEditor.tsx index f5f5dff40784..25c5d716a0fa 100644 --- a/packages/uikit-playground/src/Components/CodeEditor/BlockEditor.tsx +++ b/packages/uikit-playground/src/Components/CodeEditor/BlockEditor.tsx @@ -9,7 +9,7 @@ import useCodeMirror from '../../hooks/useCodeMirror'; import codePrettier from '../../utils/codePrettier'; type CodeMirrorProps = { - extensions?: Extension[], + extensions?: Extension[]; }; const BlockEditor = ({ extensions }: CodeMirrorProps) => { @@ -17,9 +17,10 @@ const BlockEditor = ({ extensions }: CodeMirrorProps) => { state: { screens, activeScreen }, dispatch, } = useContext(context); + const { editor, changes, setValue } = useCodeMirror( extensions, - JSON.stringify(screens[activeScreen].payload, undefined, 4) + JSON.stringify(screens[activeScreen]?.payload, undefined, 4) ); const debounceValue = useDebouncedValue(changes?.value, 1500); @@ -48,13 +49,16 @@ const BlockEditor = ({ extensions }: CodeMirrorProps) => { }, [debounceValue]); useEffect(() => { - if (!screens[activeScreen].changedByEditor) { - setValue(JSON.stringify(screens[activeScreen].payload, undefined, 4), {}); + if (!screens[activeScreen]?.changedByEditor) { + setValue( + JSON.stringify(screens[activeScreen]?.payload, undefined, 4), + {} + ); } - }, [screens[activeScreen].payload]); + }, [screens[activeScreen]?.payload]); useEffect(() => { - setValue(JSON.stringify(screens[activeScreen].payload, undefined, 4), {}); + setValue(JSON.stringify(screens[activeScreen]?.payload, undefined, 4), {}); }, [activeScreen]); return ( diff --git a/packages/uikit-playground/src/Components/CodeEditor/PreviewEditor.tsx b/packages/uikit-playground/src/Components/CodeEditor/PreviewEditor.tsx index 055a17aae465..9584193f0f81 100644 --- a/packages/uikit-playground/src/Components/CodeEditor/PreviewEditor.tsx +++ b/packages/uikit-playground/src/Components/CodeEditor/PreviewEditor.tsx @@ -6,20 +6,25 @@ import { context } from '../../Context'; import useCodeMirror from '../../hooks/useCodeMirror'; type CodeMirrorProps = { - extensions?: Extension[], + extensions?: Extension[]; }; const PreviewEditor = ({ extensions }: CodeMirrorProps) => { - const { state } = useContext(context); + const { + state: { screens, activeScreen }, + } = useContext(context); const { editor, setValue } = useCodeMirror(extensions, `{}`); useEffect(() => { - setValue(JSON.stringify(state.actionPreview, undefined, 4), {}); - }, [state.actionPreview]); + setValue( + JSON.stringify(screens[activeScreen]?.actionPreview, undefined, 4), + {} + ); + }, [screens[activeScreen]?.actionPreview]); return ( <> - + ); }; diff --git a/packages/uikit-playground/src/Components/CreateNewScreen/CreateNewScreenContainer.tsx b/packages/uikit-playground/src/Components/CreateNewScreen/CreateNewScreenContainer.tsx index 62ebc2054130..7dd6e1ab334c 100644 --- a/packages/uikit-playground/src/Components/CreateNewScreen/CreateNewScreenContainer.tsx +++ b/packages/uikit-playground/src/Components/CreateNewScreen/CreateNewScreenContainer.tsx @@ -1,7 +1,7 @@ import { css } from '@rocket.chat/css-in-js'; import { Box, Icon, Scrollable } from '@rocket.chat/fuselage'; import { useOutsideClick, useMergedRefs } from '@rocket.chat/fuselage-hooks'; -import React, { useContext, useRef } from 'react'; +import { useContext, useRef } from 'react'; import { context } from '../../Context'; import { @@ -13,7 +13,7 @@ import ScreenThumbnail from './ScreenThumbnail'; const CreateNewScreenContainer = () => { const { - state: { screens, openCreateNewScreen }, + state: { projects, screens, activeProject, openCreateNewScreen }, dispatch, } = useContext(context); const ref = useRef(null); @@ -56,13 +56,18 @@ const CreateNewScreenContainer = () => { align-items: center; `} > - {Object.values(screens).map((screen, i) => ( - - ))} + {projects[activeProject]?.screens + .map((id) => screens[id]) + .map((screen, i) => ( + screens[id]) + .length <= 1 + } + /> + ))} ( - + {(provided) => (
{blocks.map((block, index) => ( { - const [isOpen, toggleItemOpen] = useState(layer === 1); - const [hover, setHover] = useState(false); - const { state, dispatch } = useContext(context); + const [isOpen, toggleItemOpen] = useState(layer === 1); + const [hover, setHover] = useState(false); + const { state, dispatch } = useContext(context); + console.log(state); - const itemClickHandler = () => { - toggleItemOpen(!isOpen); - payload && - dispatch( - updatePayloadAction({ - payload: [...state.screens[state.activeScreen].payload, payload[0]], - changedByEditor: false, - }), - ); - }; + const itemClickHandler = () => { + toggleItemOpen(!isOpen); + payload && + dispatch( + updatePayloadAction({ + payload: [...state.screens[state.activeScreen].payload, payload[0]], + changedByEditor: false, + }) + ); + }; - return ( - - setHover(true)} - onMouseLeave={() => setHover(false)} - onClick={itemClickHandler} - > - - {children && children.length > 0 && ( - - - - )} - - - - - - - {isOpen && children} - - ); + return ( + + setHover(true)} + onMouseLeave={() => setHover(false)} + onClick={itemClickHandler} + > + + {children && children.length > 0 && ( + + + + )} + + + + + + + {isOpen && children} + + ); }; export default Items; diff --git a/packages/uikit-playground/src/Components/Preview/Display/Surface/Surface.tsx b/packages/uikit-playground/src/Components/Preview/Display/Surface/Surface.tsx index f5852eb65dcc..5eef0c4c0a60 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/Surface/Surface.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/Surface/Surface.tsx @@ -1,10 +1,14 @@ import { Box } from '@rocket.chat/fuselage'; import { UiKitContext } from '@rocket.chat/fuselage-ui-kit'; import type { FC } from 'react'; -import React, { useContext, useState, useEffect } from 'react'; +import { useContext, useState, useEffect } from 'react'; import type { DropResult } from 'react-beautiful-dnd'; -import { context, updatePayloadAction, actionPreviewAction } from '../../../../Context'; +import { + context, + updatePayloadAction, + actionPreviewAction, +} from '../../../../Context'; import generateActionPreview from '../../../../Payload/actionPreview/generateActionPreview'; import type { Block } from '../../../Draggable/DraggableList'; import DraggableList from '../../../Draggable/DraggableList'; @@ -13,72 +17,86 @@ import SurfaceRender from './SurfaceRender'; import { SurfaceOptions } from './constant'; const Surface: FC = () => { - const { - state: { screens, activeScreen }, - dispatch, - } = useContext(context); - const [uniqueBlocks, setUniqueBlocks] = useState<{ - block: Block[]; - isChangeByDnd: boolean; - }>({ - block: screens[activeScreen]?.payload.map((block, i) => ({ - id: `${i}`, - payload: block, - })), - isChangeByDnd: false, - }); - const preview = generateActionPreview('Action Block', {}); - useEffect(() => { - setUniqueBlocks({ - block: screens[activeScreen]?.payload.map((block, i) => ({ - id: `${i}`, - payload: block, - })), - isChangeByDnd: false, - }); - }, [screens[activeScreen]?.payload]); + const { + state: { screens, activeScreen, user }, + dispatch, + } = useContext(context); + const [uniqueBlocks, setUniqueBlocks] = useState<{ + block: Block[]; + isChangeByDnd: boolean; + }>({ + block: screens[activeScreen]?.payload.map((block, i) => ({ + id: `${i}`, + payload: block, + })), + isChangeByDnd: false, + }); + const preview = generateActionPreview({ + type: 'Action Block', + data: {}, + surface: screens[activeScreen]?.surface, + payload: screens[activeScreen]?.payload, + user: user, + }); + useEffect(() => { + setUniqueBlocks({ + block: screens[activeScreen]?.payload.map((block, i) => ({ + id: `${i}`, + payload: block, + })), + isChangeByDnd: false, + }); + }, [screens[activeScreen]?.payload]); - useEffect(() => { - if (uniqueBlocks.isChangeByDnd) { - dispatch( - updatePayloadAction({ - payload: uniqueBlocks.block.map((block) => block.payload), - changedByEditor: false, - }), - ); - } - }, [uniqueBlocks]); + useEffect(() => { + if (uniqueBlocks.isChangeByDnd) { + dispatch( + updatePayloadAction({ + payload: uniqueBlocks.block.map((block) => block.payload), + changedByEditor: false, + }) + ); + } + }, [uniqueBlocks]); - const onDragEnd = ({ destination, source }: DropResult) => { - if (!destination) return; + const onDragEnd = ({ destination, source }: DropResult) => { + if (!destination) return; - const newBlocks = reorder(uniqueBlocks.block, source.index, destination.index); + const newBlocks = reorder( + uniqueBlocks.block, + source.index, + destination.index + ); - setUniqueBlocks({ block: newBlocks, isChangeByDnd: true }); - }; + setUniqueBlocks({ block: newBlocks, isChangeByDnd: true }); + }; - return ( - - { - preview.action = a; - dispatch(actionPreviewAction({ ...preview })); - }, - state: (s) => { - preview.state = s; - dispatch(actionPreviewAction({ ...preview })); - }, - values: {}, - appId: 'core', - }} - > - - - - - - ); + return ( + + { + preview.action = a; + dispatch(actionPreviewAction({ ...preview })); + }, + state: (s) => { + preview.state = s; + dispatch(actionPreviewAction({ ...preview })); + }, + values: {}, + appId: 'core', + }} + > + + + + + + ); }; export default Surface; diff --git a/packages/uikit-playground/src/Components/Preview/Display/Surface/SurfaceRender.tsx b/packages/uikit-playground/src/Components/Preview/Display/Surface/SurfaceRender.tsx index 54cb132e0ffa..9f2b2f4f33d8 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/Surface/SurfaceRender.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/Surface/SurfaceRender.tsx @@ -7,11 +7,11 @@ import ModalSurface from './ModalSurface'; import { SurfaceOptions } from './constant'; const SurfaceRender = ({ - type, + type = SurfaceOptions.Message, children, }: { - type: SurfaceOptions, - children: ReactNode, + type?: SurfaceOptions; + children: ReactNode; }) => ( <> {SurfaceOptions.Message === type && ( diff --git a/packages/uikit-playground/src/Components/SurfaceSelect/SurfaceSelect.tsx b/packages/uikit-playground/src/Components/SurfaceSelect/SurfaceSelect.tsx index bd5611139dbb..5df95bf14e5f 100644 --- a/packages/uikit-playground/src/Components/SurfaceSelect/SurfaceSelect.tsx +++ b/packages/uikit-playground/src/Components/SurfaceSelect/SurfaceSelect.tsx @@ -1,6 +1,6 @@ import { Select } from '@rocket.chat/fuselage'; import type { FC } from 'react'; -import React, { useContext } from 'react'; +import { useContext } from 'react'; import { context, surfaceAction } from '../../Context'; import options from './options'; @@ -13,7 +13,7 @@ const SurfaceSelect: FC = () => { return ( + + + ); +}; + +export default EditableLabel; diff --git a/packages/uikit-playground/src/Components/ScreenThumbnail/EditableLabel/Editablelabel.scss b/packages/uikit-playground/src/Components/ScreenThumbnail/EditableLabel/Editablelabel.scss new file mode 100644 index 000000000000..a5ba92c2c31f --- /dev/null +++ b/packages/uikit-playground/src/Components/ScreenThumbnail/EditableLabel/Editablelabel.scss @@ -0,0 +1,22 @@ +.rc-editableLabel{ + >input{ + border-width: 0px !important; + padding: 0px !important; + min-height: 0px !important; + + &:focus { + box-shadow: none !important; + } + } + + &:focus-within{ + &.rc-editableLabel>.editableLabel-icon{ + visibility: hidden; + } + } + + >.editableLabel-icon{ + cursor: pointer; + scale: 1.2; + } +} \ No newline at end of file diff --git a/packages/uikit-playground/src/Components/CreateNewScreen/ScreenThumbnailWrapper.tsx b/packages/uikit-playground/src/Components/ScreenThumbnail/ScreenThumbnailWrapper.tsx similarity index 53% rename from packages/uikit-playground/src/Components/CreateNewScreen/ScreenThumbnailWrapper.tsx rename to packages/uikit-playground/src/Components/ScreenThumbnail/ScreenThumbnailWrapper.tsx index 376b38268ea7..17abc17236d2 100644 --- a/packages/uikit-playground/src/Components/CreateNewScreen/ScreenThumbnailWrapper.tsx +++ b/packages/uikit-playground/src/Components/ScreenThumbnail/ScreenThumbnailWrapper.tsx @@ -1,49 +1,55 @@ import { css } from '@rocket.chat/css-in-js'; import { Box } from '@rocket.chat/fuselage'; import type { ReactNode, ComponentProps } from 'react'; -import React from 'react'; const ScreenThumbnailWrapper = ({ children, onClick, + width = '120px', + height = '170px', + padding = '20px', ...props }: { - onClick?: ComponentProps['onClick'], - children: ReactNode, + onClick?: ComponentProps['onClick']; + children: ReactNode; } & ComponentProps) => ( - + {children} diff --git a/packages/uikit-playground/src/Components/CreateNewScreen/Thumbnail.tsx b/packages/uikit-playground/src/Components/ScreenThumbnail/Thumbnail.tsx similarity index 82% rename from packages/uikit-playground/src/Components/CreateNewScreen/Thumbnail.tsx rename to packages/uikit-playground/src/Components/ScreenThumbnail/Thumbnail.tsx index 4a12ccba109a..daf2e5703806 100644 --- a/packages/uikit-playground/src/Components/CreateNewScreen/Thumbnail.tsx +++ b/packages/uikit-playground/src/Components/ScreenThumbnail/Thumbnail.tsx @@ -1,13 +1,16 @@ import { css } from '@rocket.chat/css-in-js'; import { Box } from '@rocket.chat/fuselage'; -import type { ReactNode } from 'react'; +import type { ReactNode, ComponentProps } from 'react'; import React, { useRef, useMemo } from 'react'; interface ThumbnailProps { of: ReactNode; } -const Thumbnail: React.FC = ({ of }) => { +const Thumbnail: React.FC> = ({ + of, + ...props +}) => { const parentRef = useRef(null); const elementRef = useRef(null); @@ -23,7 +26,7 @@ const Thumbnail: React.FC = ({ of }) => { }, [elementRef.current?.offsetHeight, elementRef.current?.offsetWidth]); return ( - + ({ + type: ActionTypes.ActiveProject, + payload, +}); diff --git a/packages/uikit-playground/src/Context/action/createNewProjectAction.ts b/packages/uikit-playground/src/Context/action/createNewProjectAction.ts new file mode 100644 index 000000000000..52cd05fb194c --- /dev/null +++ b/packages/uikit-playground/src/Context/action/createNewProjectAction.ts @@ -0,0 +1,13 @@ +import { ActionTypes } from '../reducer'; + +export type CreateNewProjectAction = { + type: ActionTypes.CreateNewProject; + payload?: string; +}; + +export const createNewProjectAction = ( + payload?: string +): CreateNewProjectAction => ({ + type: ActionTypes.CreateNewProject, + payload, +}); diff --git a/packages/uikit-playground/src/Context/action/deleteProjectAction.ts b/packages/uikit-playground/src/Context/action/deleteProjectAction.ts new file mode 100644 index 000000000000..1991157506a9 --- /dev/null +++ b/packages/uikit-playground/src/Context/action/deleteProjectAction.ts @@ -0,0 +1,11 @@ +import { ActionTypes } from "../reducer"; + +export type DeleteProjectAction = { + type: ActionTypes.DeleteProject, + payload: string, +}; + +export const deleteProjectAction = (payload: string): DeleteProjectAction => ({ + type: ActionTypes.DeleteProject, + payload, +}); \ No newline at end of file diff --git a/packages/uikit-playground/src/Context/action/duplicateProjectAction.ts b/packages/uikit-playground/src/Context/action/duplicateProjectAction.ts new file mode 100644 index 000000000000..3ea4585a987d --- /dev/null +++ b/packages/uikit-playground/src/Context/action/duplicateProjectAction.ts @@ -0,0 +1,14 @@ +import { ActionTypes } from "../reducer"; + +export type DuplicateProjectAction = { + type: ActionTypes.DuplicateProject, + payload: { id: string, name?: string }, +}; + +export const duplicateProjectAction = (payload: { + id: string, + name?: string, +}): DuplicateProjectAction => ({ + type: ActionTypes.DuplicateProject, + payload, +}); diff --git a/packages/uikit-playground/src/Context/action/index.ts b/packages/uikit-playground/src/Context/action/index.ts index bcd837c9409e..8245d0be559f 100644 --- a/packages/uikit-playground/src/Context/action/index.ts +++ b/packages/uikit-playground/src/Context/action/index.ts @@ -14,6 +14,12 @@ export { createNewScreenAction } from './createNewScreenAction'; export { activeScreenAction } from './activeScreenAction'; export { duplicateScreenAction } from './duplicateScreenAction'; export { deleteScreenAction } from './deleteScreenAction'; +export {renameScreenAction} from './renameScreenAction'; +export { createNewProjectAction } from './createNewProjectAction'; +export { activeProjectAction } from './activeProjectAction'; +export { duplicateProjectAction } from './duplicateProjectAction'; +export { deleteProjectAction } from './deleteProjectAction'; +export { renameProjectAction } from './renameProjectAction'; export type { IsMobileAction } from './isMobileAction'; export type { IsTabletAction } from './isTabletAction'; @@ -31,3 +37,10 @@ export type { CreateNewScreenAction } from './createNewScreenAction'; export type { ActiveScreenAction } from './activeScreenAction'; export type { DuplicateScreenAction } from './duplicateScreenAction'; export type { DeleteScreenAction } from './deleteScreenAction'; +export type { RenameScreenAction } from './renameScreenAction'; +export type { CreateNewProjectAction } from './createNewProjectAction'; +export type { ActiveProjectAction } from './activeProjectAction'; +export type { DuplicateProjectAction } from './duplicateProjectAction'; +export type { DeleteProjectAction } from './deleteProjectAction'; +export type { RenameProjectAction } from './renameProjectAction'; + diff --git a/packages/uikit-playground/src/Context/action/renameProjectAction.ts b/packages/uikit-playground/src/Context/action/renameProjectAction.ts new file mode 100644 index 000000000000..fab35366df37 --- /dev/null +++ b/packages/uikit-playground/src/Context/action/renameProjectAction.ts @@ -0,0 +1,16 @@ +import { ActionTypes } from "../reducer"; + +type payloadType = { + id: string, + name: string, +}; + +export type RenameProjectAction = { + type: ActionTypes.RenameProject, + payload:payloadType, +}; + +export const renameProjectAction = (payload: payloadType): RenameProjectAction => ({ + type: ActionTypes.RenameProject, + payload, +}); \ No newline at end of file diff --git a/packages/uikit-playground/src/Context/action/renameScreenAction.ts b/packages/uikit-playground/src/Context/action/renameScreenAction.ts new file mode 100644 index 000000000000..8e94302549e7 --- /dev/null +++ b/packages/uikit-playground/src/Context/action/renameScreenAction.ts @@ -0,0 +1,16 @@ +import { ActionTypes } from "../reducer"; + +type payloadType = { + id: string, + name: string, +}; + +export type RenameScreenAction = { + type: ActionTypes.RenameScreen, + payload: payloadType, +}; + +export const renameScreenAction = (payload: payloadType): RenameScreenAction => ({ + type: ActionTypes.RenameScreen, + payload, +}); \ No newline at end of file diff --git a/packages/uikit-playground/src/Context/initialState.ts b/packages/uikit-playground/src/Context/initialState.ts index 67d21f7d2e7e..1b1a73b329ec 100644 --- a/packages/uikit-playground/src/Context/initialState.ts +++ b/packages/uikit-playground/src/Context/initialState.ts @@ -2,6 +2,7 @@ import type { LayoutBlock } from '@rocket.chat/ui-kit'; import { SurfaceOptions } from '../Components/Preview/Display/Surface/constant'; import getUniqueId from '../utils/getUniqueId'; +import getDate from '../utils/getDate'; export type idType = string; @@ -34,19 +35,24 @@ export type actionPreviewType = { view?: readonly LayoutBlock[]; }; +export type ScreenType = { + payload: readonly LayoutBlock[]; + id: idType; + name: string; + surface: SurfaceOptions; + actionPreview: actionPreviewType; + date: string; + changedByEditor?: boolean; +}; + export type ScreensType = { - [key: idType]: { - payload: readonly LayoutBlock[]; - id: idType; - name: string; - surface: SurfaceOptions; - actionPreview: actionPreviewType; - changedByEditor?: boolean; - }; + [key: idType]: ScreenType; }; +export type ProjectType = { id: idType; name: string; screens: idType[], date: string}; + export type ProjectsType = { - [key: idType]: { id: idType; name: string; screens: idType[] }; + [key: idType]: ProjectType; }; export type initialStateType = { @@ -82,16 +88,18 @@ export const initialState: initialStateType = { projects: { [initialProjectId]: { id: initialProjectId, - name: 'Project1', + name: 'Untitled Project', screens: [initialScreenId], + date: getDate(), }, }, screens: { [initialScreenId]: { payload: [], id: initialScreenId, - name: 'Screen1', + name: 'Untitled Screen', surface: SurfaceOptions.Message, + date: getDate(), actionPreview: {}, }, }, diff --git a/packages/uikit-playground/src/Context/reducer.ts b/packages/uikit-playground/src/Context/reducer.ts index 227c92c07dfe..abeae928bc89 100644 --- a/packages/uikit-playground/src/Context/reducer.ts +++ b/packages/uikit-playground/src/Context/reducer.ts @@ -1,6 +1,5 @@ import _ from 'lodash'; -import { SurfaceOptions } from '../Components/Preview/Display/Surface/constant'; import getUniqueId from '../utils/getUniqueId'; import type { initialStateType } from './initialState'; import { @@ -19,8 +18,15 @@ import { CreateNewScreenAction, DuplicateScreenAction, DeleteScreenAction, + RenameScreenAction, EditorTabsToggleAction, + CreateNewProjectAction, + ActiveProjectAction, + DuplicateProjectAction, + DeleteProjectAction, + RenameProjectAction, } from './action'; +import getDate from '../utils/getDate'; type IAction = | IsMobileAction @@ -38,7 +44,13 @@ type IAction = | ActiveScreenAction | CreateNewScreenAction | DuplicateScreenAction - | DeleteScreenAction; + | DeleteScreenAction + | RenameScreenAction + | CreateNewProjectAction + | ActiveProjectAction + | DuplicateProjectAction + | DeleteProjectAction + | RenameProjectAction; export enum ActionTypes { IsMobile, @@ -57,6 +69,12 @@ export enum ActionTypes { CreateNewScreen, DuplicateScreen, DeleteScreen, + RenameScreen, + CreateNewProject, + ActiveProject, + DeleteProject, + DuplicateProject, + RenameProject, } const reducer = (state: initialStateType, action: IAction) => { @@ -148,6 +166,10 @@ const reducer = (state: initialStateType, action: IAction) => { activeScreen: id, }; } + case ActionTypes.RenameScreen: { + state.screens[action?.payload?.id].name = action.payload.name; + return { ...state }; + } case ActionTypes.DeleteScreen: { delete state.screens[action.payload]; state.projects[activeProject].screens = [ @@ -166,6 +188,81 @@ const reducer = (state: initialStateType, action: IAction) => { } return { ...state }; } + + case ActionTypes.CreateNewProject: { + const activeProjectId = getUniqueId(); + const activeScreenId = getUniqueId(); + return { + ...state, + projects: { + ...state.projects, + [activeProjectId]: { + id: activeProjectId, + name: action?.payload || 'Untitled Project', + screens: [activeScreenId], + date: getDate(), + }, + }, + activeProject: activeProjectId, + screens: { + ...state.screens, + [activeScreenId]: { + id: activeScreenId, + name: 'Untitled Screen', + date: getDate(), + payload: [], + }, + }, + }; + } + case ActionTypes.ActiveProject: + return { + ...state, + activeProject: action.payload, + activeScreen: state.projects[action.payload].screens[0], + }; + + case ActionTypes.DuplicateProject: { + const activeProjectId = getUniqueId(); + const screensIds = state.projects[action.payload.id].screens; + const newScreensIds = screensIds.map(() => getUniqueId()); + const screens = _.cloneDeep(state.screens); + newScreensIds.forEach((id, index) => { + screens[id] = { + ...screens[screensIds[index]], + date: getDate(), + id, + }; + }); + + return { + ...state, + projects: { + ...state.projects, + [activeProjectId]: { + id: activeProjectId, + name: action?.payload.name || 'Untitled Project', + screens: newScreensIds, + date: getDate(), + }, + }, + activeProject: activeProjectId, + screens: screens, + }; + } + + case ActionTypes.DeleteProject: { + delete state.projects[action.payload]; + return { + ...state, + activeProject: '', + activeScreen: '', + } + } + case ActionTypes.RenameProject: { + state.projects[action.payload.id].name = action.payload.name; + return { ...state }; + } default: return state; } diff --git a/packages/uikit-playground/src/Pages/Home.tsx b/packages/uikit-playground/src/Pages/Home.tsx new file mode 100644 index 000000000000..d33ee7250736 --- /dev/null +++ b/packages/uikit-playground/src/Pages/Home.tsx @@ -0,0 +1,16 @@ +import { Box, Scrollable } from '@rocket.chat/fuselage'; +import NavBar from '../Components/NavBar'; +import HomeContainer from '../Components/HomeContainer/HomeContainer'; + +const Home = () => { + return ( + + + + + + + ); +}; + +export default Home; diff --git a/packages/uikit-playground/src/Pages/SignInSignUp.tsx b/packages/uikit-playground/src/Pages/SignInSignUp.tsx index e2e2af78761f..fd8ec305abcf 100644 --- a/packages/uikit-playground/src/Pages/SignInSignUp.tsx +++ b/packages/uikit-playground/src/Pages/SignInSignUp.tsx @@ -26,7 +26,7 @@ const labels = { const SignInSignUp = ({ route }: { route: string }) => { const navigate = useNavigate(); const clickHandler = () => { - navigate(`/${route === routes.login ? routes.signup : routes.login}`); + navigate(route === routes.login ? routes.signup : routes.login); }; return ( diff --git a/packages/uikit-playground/src/Routes/Routes.ts b/packages/uikit-playground/src/Routes/Routes.ts index fe1bbda3c1b3..de3a695db0a7 100644 --- a/packages/uikit-playground/src/Routes/Routes.ts +++ b/packages/uikit-playground/src/Routes/Routes.ts @@ -1,8 +1,9 @@ const routes = { - home: '', - login: 'login', - flow: 'flow', - signup: 'createnewworkspace', + home: '/home', + project: '/:project', + login: '/login', + flow: '/flow', + signup: '/createnewworkspace', }; export default routes; diff --git a/packages/uikit-playground/src/cssVariables.css b/packages/uikit-playground/src/cssVariables.css index ceca8f9d6a16..4ab7a711539e 100644 --- a/packages/uikit-playground/src/cssVariables.css +++ b/packages/uikit-playground/src/cssVariables.css @@ -11,4 +11,6 @@ --default-border: 1px solid #e6e6e6; --elements-border: 1px solid #b9b8b8; --elements-box-shadow: 0px 0px 8px 1px #ddd; + --navbar-height: min(60px, 25vw); + --content-height: calc(100vh - var(--navbar-height)); } \ No newline at end of file diff --git a/packages/uikit-playground/src/utils/formatDate.ts b/packages/uikit-playground/src/utils/formatDate.ts new file mode 100644 index 000000000000..03bfeda2e6db --- /dev/null +++ b/packages/uikit-playground/src/utils/formatDate.ts @@ -0,0 +1,5 @@ +import moment from "moment"; + +export const formatDate = (date: string, type='ll') => { + return moment(date).format(type); +} \ No newline at end of file diff --git a/packages/uikit-playground/src/utils/getDate.ts b/packages/uikit-playground/src/utils/getDate.ts new file mode 100644 index 000000000000..db14236db6a8 --- /dev/null +++ b/packages/uikit-playground/src/utils/getDate.ts @@ -0,0 +1,5 @@ +const getDate = () => { + return new Date().toISOString(); +} + +export default getDate; \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 642ce97a90e5..b9d80c6a9b84 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9038,7 +9038,8 @@ __metadata: "@rocket.chat/icons": next "@rocket.chat/logo": next "@rocket.chat/styled": next - "@rocket.chat/ui-contexts": "workspace:~" + "@rocket.chat/ui-contexts": "workspace:^" + "@types/prettier": ^2 "@types/react": ~17.0.62 "@types/react-beautiful-dnd": ^13.1.4 "@types/react-dom": ~17.0.20 @@ -9051,6 +9052,8 @@ __metadata: eslint-plugin-react-hooks: ^4.6.0 eslint-plugin-react-refresh: ^0.4.1 eslint4b-prebuilt: ^6.7.2 + moment: ^2.29.4 + prettier: ^2.8.8 rc-scrollbars: ^1.1.6 react: ^17.0.2 react-beautiful-dnd: ^13.1.1 @@ -31362,7 +31365,7 @@ __metadata: languageName: node linkType: hard -"prettier@npm:^2.7.1, prettier@npm:~2.8.8": +"prettier@npm:^2.7.1, prettier@npm:^2.8.8, prettier@npm:~2.8.8": version: 2.8.8 resolution: "prettier@npm:2.8.8" bin: From 85b14238a3cd49f6b5d5042dde865c0de4a0a260 Mon Sep 17 00:00:00 2001 From: intVivek Date: Sat, 8 Jul 2023 13:45:14 +0530 Subject: [PATCH 13/50] fix(uikit-playground): Fixed layout --- packages/uikit-playground/src/App.tsx | 70 +++++++++++++------ packages/uikit-playground/src/Pages/Home.tsx | 4 +- .../uikit-playground/src/Pages/Playground.tsx | 27 +------ .../src/Pages/SignInSignUp.tsx | 2 +- 4 files changed, 51 insertions(+), 52 deletions(-) diff --git a/packages/uikit-playground/src/App.tsx b/packages/uikit-playground/src/App.tsx index 8fb980295b41..0ba4261f651b 100644 --- a/packages/uikit-playground/src/App.tsx +++ b/packages/uikit-playground/src/App.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import { useContext, useEffect } from 'react'; import './App.css'; import './_global.css'; import './cssVariables.css'; @@ -10,30 +10,56 @@ import Playground from './Pages/Playground'; import SignInToWorkspace from './Pages/SignInSignUp'; import routes from './Routes/Routes'; import Home from './Pages/Home'; +import { context, isMobileAction, isTabletAction } from './Context'; +import { useMediaQueries } from '@rocket.chat/fuselage-hooks'; +import NavMenu from './Components/navMenu/NavMenu'; +import NavBar from './Components/NavBar'; +import { Box } from '@rocket.chat/fuselage'; function App() { + const { + state: { navMenuToggle }, + dispatch, + } = useContext(context); + + const [isMobile, isTablet] = useMediaQueries( + '(max-width: 630px)', + '(max-width: 1050px)' + ); + + useEffect(() => { + dispatch(isMobileAction(isMobile)); + }, [isMobile, dispatch]); + + useEffect(() => { + dispatch(isTabletAction(isTablet)); + }, [isTablet, dispatch]); return ( - - - - }> - } - /> - } - /> - - {/* }> */} - } /> - } /> - } /> - {/* */} - - - + + + + + {navMenuToggle && } + + }> + } + /> + } + /> + + {/* }> */} + } /> + } /> + } /> + {/* */} + + + + ); } diff --git a/packages/uikit-playground/src/Pages/Home.tsx b/packages/uikit-playground/src/Pages/Home.tsx index d33ee7250736..d935d24a88da 100644 --- a/packages/uikit-playground/src/Pages/Home.tsx +++ b/packages/uikit-playground/src/Pages/Home.tsx @@ -1,11 +1,9 @@ import { Box, Scrollable } from '@rocket.chat/fuselage'; -import NavBar from '../Components/NavBar'; import HomeContainer from '../Components/HomeContainer/HomeContainer'; const Home = () => { return ( - - + diff --git a/packages/uikit-playground/src/Pages/Playground.tsx b/packages/uikit-playground/src/Pages/Playground.tsx index 1f072f22e58b..5e49229f8f33 100644 --- a/packages/uikit-playground/src/Pages/Playground.tsx +++ b/packages/uikit-playground/src/Pages/Playground.tsx @@ -1,37 +1,14 @@ import { Box } from '@rocket.chat/fuselage'; -import { useMediaQueries } from '@rocket.chat/fuselage-hooks'; import type { FC } from 'react'; -import { useEffect, useContext } from 'react'; import ComponentSideBar from '../Components/ComponentSideBar'; import CreateNewScreenContainer from '../Components/CreateNewScreen/CreateNewScreenContainer'; -import NavBar from '../Components/NavBar'; import Preview from '../Components/Preview'; import Templates from '../Components/Templates'; -import NavMenu from '../Components/navMenu'; -import { context, isMobileAction, isTabletAction } from '../Context'; const Playground: FC = () => { - const { - state: { navMenuToggle }, - dispatch, - } = useContext(context); - - const [isMobile, isTablet] = useMediaQueries( - '(max-width: 630px)', - '(max-width: 1050px)' - ); - - useEffect(() => { - dispatch(isMobileAction(isMobile)); - }, [isMobile, dispatch]); - - useEffect(() => { - dispatch(isTabletAction(isTablet)); - }, [isTablet, dispatch]); - return ( - + { overflow="hidden" bg={'var(--primaryBackgroundColor)'} > - - {navMenuToggle && } diff --git a/packages/uikit-playground/src/Pages/SignInSignUp.tsx b/packages/uikit-playground/src/Pages/SignInSignUp.tsx index fd8ec305abcf..a95f5e184246 100644 --- a/packages/uikit-playground/src/Pages/SignInSignUp.tsx +++ b/packages/uikit-playground/src/Pages/SignInSignUp.tsx @@ -30,7 +30,7 @@ const SignInSignUp = ({ route }: { route: string }) => { }; return ( - + Date: Sat, 8 Jul 2023 14:55:43 +0530 Subject: [PATCH 14/50] chore(uikit-playground): Fixed routing --- packages/uikit-playground/src/App.tsx | 13 ++--- .../ProjectsList/ProjectsThumbnail.tsx | 1 - .../src/Components/NavBar/NavBar.tsx | 6 +- .../src/Components/Routes/HomeLayout.tsx | 2 +- .../src/Components/Routes/ProtectedLayout.tsx | 2 +- .../src/Components/navMenu/NavMenu.tsx | 10 ++-- .../uikit-playground/src/Pages/Playground.tsx | 55 +++++++++++++------ .../uikit-playground/src/Routes/Routes.ts | 2 +- 8 files changed, 53 insertions(+), 38 deletions(-) diff --git a/packages/uikit-playground/src/App.tsx b/packages/uikit-playground/src/App.tsx index 0ba4261f651b..71ccadb3360f 100644 --- a/packages/uikit-playground/src/App.tsx +++ b/packages/uikit-playground/src/App.tsx @@ -12,15 +12,11 @@ import routes from './Routes/Routes'; import Home from './Pages/Home'; import { context, isMobileAction, isTabletAction } from './Context'; import { useMediaQueries } from '@rocket.chat/fuselage-hooks'; -import NavMenu from './Components/navMenu/NavMenu'; -import NavBar from './Components/NavBar'; import { Box } from '@rocket.chat/fuselage'; +import FlowDiagram from './Pages/FlowDiagram'; function App() { - const { - state: { navMenuToggle }, - dispatch, - } = useContext(context); + const { dispatch } = useContext(context); const [isMobile, isTablet] = useMediaQueries( '(max-width: 630px)', @@ -38,8 +34,6 @@ function App() { - - {navMenuToggle && } }> {/* }> */} } /> + } /> } /> - } /> + } /> {/* */} diff --git a/packages/uikit-playground/src/Components/HomeContainer/ProjectsList/ProjectsThumbnail.tsx b/packages/uikit-playground/src/Components/HomeContainer/ProjectsList/ProjectsThumbnail.tsx index e2dd6f18bfa7..90d209b16653 100644 --- a/packages/uikit-playground/src/Components/HomeContainer/ProjectsList/ProjectsThumbnail.tsx +++ b/packages/uikit-playground/src/Components/HomeContainer/ProjectsList/ProjectsThumbnail.tsx @@ -35,7 +35,6 @@ const ProjectsThumbnail = ({ const { dispatch } = useContext(context); const toast = useToastBarDispatch(); const activeProjectHandler = () => { - dispatch(activeProjectAction(id)); navigate(`/${id}`); }; diff --git a/packages/uikit-playground/src/Components/NavBar/NavBar.tsx b/packages/uikit-playground/src/Components/NavBar/NavBar.tsx index f52bab6b1d9e..d9e587b1fb73 100644 --- a/packages/uikit-playground/src/Components/NavBar/NavBar.tsx +++ b/packages/uikit-playground/src/Components/NavBar/NavBar.tsx @@ -9,14 +9,12 @@ import { } from '@rocket.chat/fuselage'; import { useToastBarDispatch } from '@rocket.chat/fuselage-toastbar'; import type { FC } from 'react'; -import React, { useContext } from 'react'; +import { useContext } from 'react'; import { useNavigate } from 'react-router-dom'; import { context, updatePayloadAction } from '../../Context'; import { openCreateNewScreenAction } from '../../Context/action/openCreateNewScreenAction'; import routes from '../../Routes/Routes'; -import Divider from './Divider'; -import Logo from './Logo'; import RightNavBtn from './RightNavBtn'; const NabBar: FC = () => { @@ -58,7 +56,7 @@ const NabBar: FC = () => { - - - - + + + + + + + ); export default ContextualBarSurface; diff --git a/packages/uikit-playground/src/Components/Preview/Display/Surface/Surface.tsx b/packages/uikit-playground/src/Components/Preview/Display/Surface/Surface.tsx index 5eef0c4c0a60..6d5b82471a57 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/Surface/Surface.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/Surface/Surface.tsx @@ -72,7 +72,7 @@ const Surface: FC = () => { }; return ( - + { diff --git a/packages/uikit-playground/src/Components/Preview/Display/Surface/SurfaceRender.tsx b/packages/uikit-playground/src/Components/Preview/Display/Surface/SurfaceRender.tsx index 9f2b2f4f33d8..8554aacfe67f 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/Surface/SurfaceRender.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/Surface/SurfaceRender.tsx @@ -5,6 +5,7 @@ import BannerSurface from './BannerSurface'; import MessageSurface from './MessageSurface'; import ModalSurface from './ModalSurface'; import { SurfaceOptions } from './constant'; +import ContextualBarSurface from './ContextualBarSurface'; const SurfaceRender = ({ type = SurfaceOptions.Message, @@ -21,6 +22,9 @@ const SurfaceRender = ({ {children} )} {SurfaceOptions.Modal === type && {children}} + {SurfaceOptions.ContextualBar === type && ( + {children} + )} ); export default SurfaceRender; diff --git a/packages/uikit-playground/src/Components/Preview/Display/Surface/constant.ts b/packages/uikit-playground/src/Components/Preview/Display/Surface/constant.ts index fcdc6f26bfe3..d6e5cc395d25 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/Surface/constant.ts +++ b/packages/uikit-playground/src/Components/Preview/Display/Surface/constant.ts @@ -1,5 +1,6 @@ export enum SurfaceOptions { Message = 1, Banner, - Modal + Modal, + ContextualBar, } \ No newline at end of file diff --git a/packages/uikit-playground/src/Components/SurfaceSelect/options.ts b/packages/uikit-playground/src/Components/SurfaceSelect/options.ts index 9747a704ab50..44c764601a47 100644 --- a/packages/uikit-playground/src/Components/SurfaceSelect/options.ts +++ b/packages/uikit-playground/src/Components/SurfaceSelect/options.ts @@ -3,10 +3,10 @@ import { SurfaceOptions } from '../Preview/Display/Surface/constant'; type SelectOption = [value: string, label: string, selected?: boolean]; const options: SelectOption[] = [ - ['1', 'Message Preview'], - ['2', 'Banner Preview'], - ['3', 'Modal Preview'], - ['4', 'ContextualBar Preview'], + [`${SurfaceOptions.Message}`, 'Message Preview'], + [`${SurfaceOptions.Banner}`, 'Banner Preview'], + [`${SurfaceOptions.Modal}`, 'Modal Preview'], + [`${SurfaceOptions.ContextualBar}`, 'Contextual Bar Preview'], ]; export default options; diff --git a/packages/uikit-playground/src/Payload/actionPreview/container.ts b/packages/uikit-playground/src/Payload/actionPreview/container.ts index ddc6cf9708f1..b814ff81d58b 100644 --- a/packages/uikit-playground/src/Payload/actionPreview/container.ts +++ b/packages/uikit-playground/src/Payload/actionPreview/container.ts @@ -19,5 +19,9 @@ const container: containerType = { type: 'modal', text: '', }, + [SurfaceOptions.ContextualBar]: { + type: 'ContextualBar', + text: '', + }, }; export default container; From 05cb1f58f5b6a258130df7d2b8b86ccf7e599ac2 Mon Sep 17 00:00:00 2001 From: intVivek Date: Wed, 12 Jul 2023 15:29:07 +0530 Subject: [PATCH 18/50] fix(uikit-playground): Saving edges state --- .../FlowContainer/FlowContainer.tsx | 35 ++++++++++--------- .../src/Components/FlowContainer/utils.ts | 6 ++-- .../src/Context/action/index.ts | 2 ++ .../Context/action/updateFlowEdgesAction.ts | 12 +++++++ .../src/Context/initialState.ts | 4 ++- .../uikit-playground/src/Context/reducer.ts | 13 ++++++- 6 files changed, 51 insertions(+), 21 deletions(-) create mode 100644 packages/uikit-playground/src/Context/action/updateFlowEdgesAction.ts diff --git a/packages/uikit-playground/src/Components/FlowContainer/FlowContainer.tsx b/packages/uikit-playground/src/Components/FlowContainer/FlowContainer.tsx index 0baab99df80f..9a2033ccfc05 100644 --- a/packages/uikit-playground/src/Components/FlowContainer/FlowContainer.tsx +++ b/packages/uikit-playground/src/Components/FlowContainer/FlowContainer.tsx @@ -1,4 +1,4 @@ -import { useCallback, useContext, useRef } from 'react'; +import { useCallback, useContext, useEffect, useRef } from 'react'; import ReactFlow, { MiniMap, Background, @@ -9,7 +9,7 @@ import ReactFlow, { } from 'reactflow'; import 'reactflow/dist/style.css'; -import { context } from '../../Context'; +import { context, updateFlowEdgesAction } from '../../Context'; import ConnectionLine from './ConnectionLine'; import UIKitWrapper from './UIKitWrapper'; import { FlowParams, createNodesAndEdges } from './utils'; @@ -21,29 +21,32 @@ const nodeTypes = { const FlowContainer = () => { const { - state: { screens }, + state: { screens, projects, activeProject }, + dispatch, } = useContext(context); - const { nodes: initialNodes } = createNodesAndEdges(screens); + const { nodes: initialNodes } = createNodesAndEdges( + projects[activeProject].screens.map((id) => screens[id]) + ); const [nodes, , onNodesChange] = useNodesState(initialNodes); - const [edges, setEdges, onEdgesChange] = useEdgesState([]); + const [edges, setEdges, onEdgesChange] = useEdgesState( + projects[activeProject].flowEdges + ); const edgeUpdateSuccessful = useRef(true); const onConnect = useCallback( (params) => { + window.console.log({ params }); if (params.source === params.target) return; - setEdges((eds) => - addEdge( - { - ...params, - type: FlowParams.edgeType, - markerEnd: FlowParams.markerEnd, - style: FlowParams.style, - }, - eds - ) - ); + const newEdge = { + ...params, + type: FlowParams.edgeType, + markerEnd: FlowParams.markerEnd, + style: FlowParams.style, + }; + dispatch(updateFlowEdgesAction(newEdge)); + setEdges((eds) => addEdge(newEdge, eds)); }, [setEdges] ); diff --git a/packages/uikit-playground/src/Components/FlowContainer/utils.ts b/packages/uikit-playground/src/Components/FlowContainer/utils.ts index a09148ac4989..2318fe1f1efc 100644 --- a/packages/uikit-playground/src/Components/FlowContainer/utils.ts +++ b/packages/uikit-playground/src/Components/FlowContainer/utils.ts @@ -1,11 +1,11 @@ import { MarkerType } from 'reactflow'; -import type { ScreensType } from '../../Context/initialState'; +import type { ScreenType } from '../../Context/initialState'; -export function createNodesAndEdges(screens: ScreensType) { +export function createNodesAndEdges(screens: ScreenType[]) { const center = { x: window.innerWidth / 2, y: window.innerHeight / 2 }; - const nodes = Object.values(screens).map((screen, i) => { + const nodes = screens.map((screen, i) => { const degrees = i * (360 / 8); const radians = degrees * (Math.PI / 180); const x = 250 * Math.cos(radians) + center.x; diff --git a/packages/uikit-playground/src/Context/action/index.ts b/packages/uikit-playground/src/Context/action/index.ts index 8245d0be559f..10fc34b0499f 100644 --- a/packages/uikit-playground/src/Context/action/index.ts +++ b/packages/uikit-playground/src/Context/action/index.ts @@ -20,6 +20,7 @@ export { activeProjectAction } from './activeProjectAction'; export { duplicateProjectAction } from './duplicateProjectAction'; export { deleteProjectAction } from './deleteProjectAction'; export { renameProjectAction } from './renameProjectAction'; +export { updateFlowEdgesAction } from './updateFlowEdgesAction'; export type { IsMobileAction } from './isMobileAction'; export type { IsTabletAction } from './isTabletAction'; @@ -43,4 +44,5 @@ export type { ActiveProjectAction } from './activeProjectAction'; export type { DuplicateProjectAction } from './duplicateProjectAction'; export type { DeleteProjectAction } from './deleteProjectAction'; export type { RenameProjectAction } from './renameProjectAction'; +export type { UpdateFlowEdgesAction } from './updateFlowEdgesAction'; diff --git a/packages/uikit-playground/src/Context/action/updateFlowEdgesAction.ts b/packages/uikit-playground/src/Context/action/updateFlowEdgesAction.ts new file mode 100644 index 000000000000..4e699261eb84 --- /dev/null +++ b/packages/uikit-playground/src/Context/action/updateFlowEdgesAction.ts @@ -0,0 +1,12 @@ +import { Edge } from "reactflow"; +import { ActionTypes } from "../reducer"; + +export type UpdateFlowEdgesAction = { + type: ActionTypes.UpdateFlowEdges, + payload: Edge, +}; + +export const updateFlowEdgesAction = (payload: Edge): UpdateFlowEdgesAction => ({ + type: ActionTypes.UpdateFlowEdges, + payload, +}); \ No newline at end of file diff --git a/packages/uikit-playground/src/Context/initialState.ts b/packages/uikit-playground/src/Context/initialState.ts index 1b1a73b329ec..090238742011 100644 --- a/packages/uikit-playground/src/Context/initialState.ts +++ b/packages/uikit-playground/src/Context/initialState.ts @@ -3,6 +3,7 @@ import type { LayoutBlock } from '@rocket.chat/ui-kit'; import { SurfaceOptions } from '../Components/Preview/Display/Surface/constant'; import getUniqueId from '../utils/getUniqueId'; import getDate from '../utils/getDate'; +import { Edge } from 'reactflow'; export type idType = string; @@ -49,7 +50,7 @@ export type ScreensType = { [key: idType]: ScreenType; }; -export type ProjectType = { id: idType; name: string; screens: idType[], date: string}; +export type ProjectType = { id: idType; name: string; screens: idType[], date: string, flowEdges: Edge[]}; export type ProjectsType = { [key: idType]: ProjectType; @@ -91,6 +92,7 @@ export const initialState: initialStateType = { name: 'Untitled Project', screens: [initialScreenId], date: getDate(), + flowEdges: [], }, }, screens: { diff --git a/packages/uikit-playground/src/Context/reducer.ts b/packages/uikit-playground/src/Context/reducer.ts index abeae928bc89..7694d08de30e 100644 --- a/packages/uikit-playground/src/Context/reducer.ts +++ b/packages/uikit-playground/src/Context/reducer.ts @@ -25,6 +25,7 @@ import { DuplicateProjectAction, DeleteProjectAction, RenameProjectAction, + UpdateFlowEdgesAction, } from './action'; import getDate from '../utils/getDate'; @@ -50,7 +51,8 @@ type IAction = | ActiveProjectAction | DuplicateProjectAction | DeleteProjectAction - | RenameProjectAction; + | RenameProjectAction + | UpdateFlowEdgesAction; export enum ActionTypes { IsMobile, @@ -75,6 +77,7 @@ export enum ActionTypes { DeleteProject, DuplicateProject, RenameProject, + UpdateFlowEdges, } const reducer = (state: initialStateType, action: IAction) => { @@ -263,6 +266,14 @@ const reducer = (state: initialStateType, action: IAction) => { state.projects[action.payload.id].name = action.payload.name; return { ...state }; } + + case ActionTypes.UpdateFlowEdges: { + let prevEdges = state.projects[activeProject].flowEdges; + prevEdges = [...prevEdges, action.payload] + window.console.log(prevEdges); + state.projects[activeProject].flowEdges = prevEdges; + return { ...state }; + } default: return state; } From d15af3ef091cb30f2bc928564c20ed670ed10ede Mon Sep 17 00:00:00 2001 From: intVivek Date: Sat, 15 Jul 2023 17:34:00 +0530 Subject: [PATCH 19/50] Fix(uikit-playground): preserve flow edges after reorder from dnd --- .../src/Components/Draggable/DraggableList.tsx | 4 ++-- .../uikit-playground/src/Components/DropDown/Items.tsx | 7 +++++-- .../src/Components/FlowContainer/UIKitWrapper.tsx | 8 ++++---- .../Preview/Display/RenderPayload/RenderPayload.tsx | 4 ++-- .../src/Context/action/updatePayloadAction.ts | 4 ++-- packages/uikit-playground/src/Context/initialState.ts | 6 ++++-- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/packages/uikit-playground/src/Components/Draggable/DraggableList.tsx b/packages/uikit-playground/src/Components/Draggable/DraggableList.tsx index 65fd51fd90ac..af48ac55539f 100644 --- a/packages/uikit-playground/src/Components/Draggable/DraggableList.tsx +++ b/packages/uikit-playground/src/Components/Draggable/DraggableList.tsx @@ -1,14 +1,14 @@ -import type { LayoutBlock } from '@rocket.chat/ui-kit'; import React from 'react'; import type { OnDragEndResponder } from 'react-beautiful-dnd'; import { DragDropContext, Droppable } from 'react-beautiful-dnd'; import DraggableListItem from './DraggableListItem'; import { SurfaceOptions } from '../Preview/Display/Surface/constant'; +import { ILayoutBlock } from '../../Context/initialState'; export type Block = { id: string; - payload: LayoutBlock; + payload: ILayoutBlock; }; export type DraggableListProps = { diff --git a/packages/uikit-playground/src/Components/DropDown/Items.tsx b/packages/uikit-playground/src/Components/DropDown/Items.tsx index 23bda2f1d688..84eca2f88e8b 100644 --- a/packages/uikit-playground/src/Components/DropDown/Items.tsx +++ b/packages/uikit-playground/src/Components/DropDown/Items.tsx @@ -6,19 +6,22 @@ import { context, updatePayloadAction } from '../../Context'; import ItemsIcon from './ItemsIcon'; import { itemStyle, labelStyle } from './itemsStyle'; import type { ItemProps } from './types'; +import getUniqueId from '../../utils/getUniqueId'; const Items = ({ label, children, layer, payload }: ItemProps) => { const [isOpen, toggleItemOpen] = useState(layer === 1); const [hover, setHover] = useState(false); const { state, dispatch } = useContext(context); - console.log(state); const itemClickHandler = () => { toggleItemOpen(!isOpen); payload && dispatch( updatePayloadAction({ - payload: [...state.screens[state.activeScreen].payload, payload[0]], + payload: [ + ...state.screens[state.activeScreen].payload, + { actionId: getUniqueId(), ...payload[0] }, + ], changedByEditor: false, }) ); diff --git a/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper.tsx b/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper.tsx index 00ed32671c6b..c75208af5e7c 100644 --- a/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper.tsx +++ b/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper.tsx @@ -1,12 +1,12 @@ import { Box } from '@rocket.chat/fuselage'; -import React, { memo } from 'react'; +import { memo } from 'react'; import { Handle, Position } from 'reactflow'; -import type { docType } from '../../Context/initialState'; import RenderPayload from '../Preview/Display/RenderPayload/RenderPayload'; import SurfaceRender from '../Preview/Display/Surface/SurfaceRender'; +import { ScreenType } from '../../Context/initialState'; -const UIKitWrapper = ({ id, data }: { id: string, data: docType }) => ( +const UIKitWrapper = ({ id, data }: { id: string; data: ScreenType }) => ( ( type="source" className="react-flow-sourceHandle" position={Position.Right} - id={`${id}-${index}`} + id={payload.actionId} /> ))} diff --git a/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/RenderPayload.tsx b/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/RenderPayload.tsx index 8f07b9982d90..9a7f5cf78ad2 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/RenderPayload.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/RenderPayload.tsx @@ -4,16 +4,16 @@ import { UiKitMessage as uiKitMessage, UiKitContextualBar as uiKitContextualBar, } from '@rocket.chat/fuselage-ui-kit'; -import type { LayoutBlock } from '@rocket.chat/ui-kit'; import { SurfaceOptions } from '../Surface/constant'; +import { ILayoutBlock } from '../../../../Context/initialState'; const RenderPayload = ({ payload, surface = 1, }: { index?: number; - payload: readonly LayoutBlock[]; + payload: ILayoutBlock[]; surface?: number; }) => ( <> diff --git a/packages/uikit-playground/src/Context/action/updatePayloadAction.ts b/packages/uikit-playground/src/Context/action/updatePayloadAction.ts index 3ad445aa10d9..dbe4558cdcd8 100644 --- a/packages/uikit-playground/src/Context/action/updatePayloadAction.ts +++ b/packages/uikit-playground/src/Context/action/updatePayloadAction.ts @@ -1,8 +1,8 @@ -import type { LayoutBlock } from '@rocket.chat/ui-kit'; +import { ILayoutBlock } from '../initialState'; import { ActionTypes } from '../reducer'; type PayloadType ={ - payload: readonly LayoutBlock[]; + payload: ILayoutBlock[]; changedByEditor?: boolean; } diff --git a/packages/uikit-playground/src/Context/initialState.ts b/packages/uikit-playground/src/Context/initialState.ts index 090238742011..908080d2ac77 100644 --- a/packages/uikit-playground/src/Context/initialState.ts +++ b/packages/uikit-playground/src/Context/initialState.ts @@ -33,11 +33,13 @@ export type actionPreviewType = { action?: object; response_url?: string; state?: object; - view?: readonly LayoutBlock[]; + view?: ILayoutBlock[]; }; +export type ILayoutBlock = {actionId: string} & LayoutBlock; + export type ScreenType = { - payload: readonly LayoutBlock[]; + payload: ILayoutBlock[]; id: idType; name: string; surface: SurfaceOptions; From 8f3494a73d385f23177b014573b1645482d6cb0e Mon Sep 17 00:00:00 2001 From: intVivek Date: Sun, 16 Jul 2023 13:57:34 +0530 Subject: [PATCH 20/50] fix(Uikit-playground): fix syntax highlighting in codemirror --- packages/uikit-playground/package.json | 2 +- .../Preview/Display/Surface/ContextualBarSurface.tsx | 3 +-- yarn.lock | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/uikit-playground/package.json b/packages/uikit-playground/package.json index c93b81021ca6..c8daf4c74692 100644 --- a/packages/uikit-playground/package.json +++ b/packages/uikit-playground/package.json @@ -13,7 +13,7 @@ "@codemirror/lang-javascript": "^6.1.9", "@codemirror/lang-json": "^6.0.1", "@codemirror/tooltip": "^0.19.16", - "@lezer/highlight": "^1.1.6", + "@lezer/highlight": "^1.0.0", "@rocket.chat/css-in-js": "next", "@rocket.chat/fuselage": "next", "@rocket.chat/fuselage-hooks": "next", diff --git a/packages/uikit-playground/src/Components/Preview/Display/Surface/ContextualBarSurface.tsx b/packages/uikit-playground/src/Components/Preview/Display/Surface/ContextualBarSurface.tsx index abba859a9182..3e2af2a2dd53 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/Surface/ContextualBarSurface.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/Surface/ContextualBarSurface.tsx @@ -11,11 +11,10 @@ import { Margins, } from '@rocket.chat/fuselage'; import { Scrollbars } from 'rc-scrollbars'; -import { useLayoutSizes } from '@rocket.chat/ui-contexts'; import { ReactNode } from 'react'; const ContextualBarSurface = ({ children }: { children: ReactNode }) => ( - + {'Contextual Bar'} diff --git a/yarn.lock b/yarn.lock index b9d80c6a9b84..c09a0bf09916 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4182,7 +4182,7 @@ __metadata: languageName: node linkType: hard -"@lezer/highlight@npm:^1.0.0, @lezer/highlight@npm:^1.1.3, @lezer/highlight@npm:^1.1.6": +"@lezer/highlight@npm:^1.0.0, @lezer/highlight@npm:^1.1.3": version: 1.1.6 resolution: "@lezer/highlight@npm:1.1.6" dependencies: @@ -9027,7 +9027,7 @@ __metadata: "@codemirror/lang-javascript": ^6.1.9 "@codemirror/lang-json": ^6.0.1 "@codemirror/tooltip": ^0.19.16 - "@lezer/highlight": ^1.1.6 + "@lezer/highlight": ^1.0.0 "@rocket.chat/css-in-js": next "@rocket.chat/fuselage": next "@rocket.chat/fuselage-hooks": next From c91807b43281d5b416a855a5c4592cf68f5d92ea Mon Sep 17 00:00:00 2001 From: intVivek Date: Sun, 16 Jul 2023 14:24:01 +0530 Subject: [PATCH 21/50] fix(Uikit-playground): fix contextual bar --- .../FlowContainer/FlowContainer.tsx | 2 +- .../Components/FlowContainer/UIKitWrapper.tsx | 43 ------------------ .../UIKitWrapper/UIKitWrapper.scss | 7 +++ .../UIKitWrapper/UIKitWrapper.tsx | 45 +++++++++++++++++++ .../FlowContainer/UIKitWrapper/index.ts | 1 + .../Display/Surface/ContextualBarSurface.tsx | 7 ++- 6 files changed, 57 insertions(+), 48 deletions(-) delete mode 100644 packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper.tsx create mode 100644 packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/UIKitWrapper.scss create mode 100644 packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/UIKitWrapper.tsx create mode 100644 packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/index.ts diff --git a/packages/uikit-playground/src/Components/FlowContainer/FlowContainer.tsx b/packages/uikit-playground/src/Components/FlowContainer/FlowContainer.tsx index 9a2033ccfc05..00797817f874 100644 --- a/packages/uikit-playground/src/Components/FlowContainer/FlowContainer.tsx +++ b/packages/uikit-playground/src/Components/FlowContainer/FlowContainer.tsx @@ -11,7 +11,7 @@ import ReactFlow, { import 'reactflow/dist/style.css'; import { context, updateFlowEdgesAction } from '../../Context'; import ConnectionLine from './ConnectionLine'; -import UIKitWrapper from './UIKitWrapper'; +import UIKitWrapper from './UIKitWrapper/UIKitWrapper'; import { FlowParams, createNodesAndEdges } from './utils'; import ControlButton from './ControlButtons'; diff --git a/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper.tsx b/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper.tsx deleted file mode 100644 index c75208af5e7c..000000000000 --- a/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import { Box } from '@rocket.chat/fuselage'; -import { memo } from 'react'; -import { Handle, Position } from 'reactflow'; - -import RenderPayload from '../Preview/Display/RenderPayload/RenderPayload'; -import SurfaceRender from '../Preview/Display/Surface/SurfaceRender'; -import { ScreenType } from '../../Context/initialState'; - -const UIKitWrapper = ({ id, data }: { id: string; data: ScreenType }) => ( - - - - {data.payload.map((payload, index) => ( - - - - - ))} - - -); - -export default memo(UIKitWrapper); diff --git a/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/UIKitWrapper.scss b/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/UIKitWrapper.scss new file mode 100644 index 000000000000..cc3f56cc7990 --- /dev/null +++ b/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/UIKitWrapper.scss @@ -0,0 +1,7 @@ +.rc-scrollbars-view{ + position: relative !important; + overflow: hidden !important; + width: 100% !important; + z-index: 1000 !important; + margin: 0 !important; +} \ No newline at end of file diff --git a/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/UIKitWrapper.tsx b/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/UIKitWrapper.tsx new file mode 100644 index 000000000000..8c3e1277afa9 --- /dev/null +++ b/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/UIKitWrapper.tsx @@ -0,0 +1,45 @@ +import { Box } from '@rocket.chat/fuselage'; +import { memo } from 'react'; +import { Handle, Position } from 'reactflow'; +import './UIKitWrapper.scss'; + +import RenderPayload from '../../Preview/Display/RenderPayload/RenderPayload'; +import SurfaceRender from '../../Preview/Display/Surface/SurfaceRender'; +import { ScreenType } from '../../../Context/initialState'; + +const UIKitWrapper = ({ id, data }: { id: string; data: ScreenType }) => ( + + + + {data.payload.map((payload, index) => ( + + + + + + + ))} + + +); + +export default memo(UIKitWrapper); diff --git a/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/index.ts b/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/index.ts new file mode 100644 index 000000000000..82f4f03d69d3 --- /dev/null +++ b/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/index.ts @@ -0,0 +1 @@ +export {default} from './UIKitWrapper'; \ No newline at end of file diff --git a/packages/uikit-playground/src/Components/Preview/Display/Surface/ContextualBarSurface.tsx b/packages/uikit-playground/src/Components/Preview/Display/Surface/ContextualBarSurface.tsx index 3e2af2a2dd53..cd02667d0883 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/Surface/ContextualBarSurface.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/Surface/ContextualBarSurface.tsx @@ -1,3 +1,4 @@ +import { css } from '@rocket.chat/css-in-js'; import { Avatar, Box, @@ -11,7 +12,7 @@ import { Margins, } from '@rocket.chat/fuselage'; import { Scrollbars } from 'rc-scrollbars'; -import { ReactNode } from 'react'; +import { CSSProperties, ReactNode } from 'react'; const ContextualBarSurface = ({ children }: { children: ReactNode }) => ( @@ -32,7 +33,6 @@ const ContextualBarSurface = ({ children }: { children: ReactNode }) => ( flexShrink={1} flexDirection="column" flexGrow={1} - overflow="hidden" > ( width: '100%', height: '100%', flexGrow: 1, - willChange: 'transform', overflowY: 'hidden', }} renderThumbVertical={({ style, ...props }): JSX.Element => ( @@ -56,7 +55,7 @@ const ContextualBarSurface = ({ children }: { children: ReactNode }) => ( /> )} > - {children} +
{children}
From 69970380fe8a884dca872dd9f6a04cf9b19103f2 Mon Sep 17 00:00:00 2001 From: intVivek Date: Sun, 23 Jul 2023 21:20:18 +0530 Subject: [PATCH 22/50] refactor(uikit-playground): added useNodesAndEdges hook --- .../src/hooks/useNodesAndEdges.ts | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 packages/uikit-playground/src/hooks/useNodesAndEdges.ts diff --git a/packages/uikit-playground/src/hooks/useNodesAndEdges.ts b/packages/uikit-playground/src/hooks/useNodesAndEdges.ts new file mode 100644 index 000000000000..0e6126c1c00a --- /dev/null +++ b/packages/uikit-playground/src/hooks/useNodesAndEdges.ts @@ -0,0 +1,48 @@ +import { MarkerType } from 'reactflow'; +import { useContext, useMemo } from 'react'; +import { context } from '../Context'; +export function useNodesAndEdges() { + const { + state: { screens, projects, activeProject }, + } = useContext(context); + + const nodes = useMemo(() => { + const prevNodes = projects[activeProject].flowNodes; + const center = { x: window.innerWidth / 2, y: window.innerHeight / 2 }; + const activeScreens = projects[activeProject].screens.map( + (id) => screens[id] + ); + activeScreens.map((screen, i) => { + if (prevNodes.map((node) => node.id).includes(screen.id)) return; + + const degrees = i * (360 / 8); + const radians = degrees * (Math.PI / 180); + const x = 2500 * Math.cos(radians) + center.x; + const y = 2500 * Math.sin(radians) + center.y; + + prevNodes.push({ + id: screen.id, + type: 'custom', + position: { x, y }, + data: screen.id, + }); + }); + return prevNodes; + }, []); + + const edges = projects[activeProject].flowEdges; + const Viewport = projects[activeProject].viewport; + + return { nodes, edges, Viewport }; +} + +export const FlowParams = { + edgeType: 'smoothstep', + markerEnd: { + type: MarkerType.Arrow, + }, + style: { + strokeWidth: 2, + stroke: 'var(--RCPG-primary-color)', + }, +}; From 29c49a4c40a5e00c95561233da2cd2bea90bf3a2 Mon Sep 17 00:00:00 2001 From: intVivek Date: Sun, 23 Jul 2023 21:26:45 +0530 Subject: [PATCH 23/50] fix(uikit-playground): added psition save on reactflow --- packages/uikit-playground/src/App.tsx | 1 + .../FlowContainer/FlowContainer.tsx | 45 +++++++---- .../UIKitWrapper/UIKitWrapper.tsx | 77 ++++++++++--------- .../ProjectsList/ProjectsThumbnail.tsx | 1 - .../src/Context/action/index.ts | 5 +- .../action/updateNodesAndViewPortAction.ts | 19 +++++ .../src/Context/initialState.ts | 16 +++- .../uikit-playground/src/Context/reducer.ts | 50 +++++++----- .../src/Pages/FlowDiagram.tsx | 6 +- 9 files changed, 144 insertions(+), 76 deletions(-) create mode 100644 packages/uikit-playground/src/Context/action/updateNodesAndViewPortAction.ts diff --git a/packages/uikit-playground/src/App.tsx b/packages/uikit-playground/src/App.tsx index 69939708a984..7e60bf6e198c 100644 --- a/packages/uikit-playground/src/App.tsx +++ b/packages/uikit-playground/src/App.tsx @@ -51,6 +51,7 @@ function App() { }> } /> } /> + {/* } /> */} } /> {/* */} diff --git a/packages/uikit-playground/src/Components/FlowContainer/FlowContainer.tsx b/packages/uikit-playground/src/Components/FlowContainer/FlowContainer.tsx index 00797817f874..792bcf0f1c40 100644 --- a/packages/uikit-playground/src/Components/FlowContainer/FlowContainer.tsx +++ b/packages/uikit-playground/src/Components/FlowContainer/FlowContainer.tsx @@ -1,4 +1,4 @@ -import { useCallback, useContext, useEffect, useRef } from 'react'; +import { useCallback, useContext, useEffect, useRef, useState } from 'react'; import ReactFlow, { MiniMap, Background, @@ -6,38 +6,42 @@ import ReactFlow, { useEdgesState, addEdge, updateEdge, + Node, + Viewport, + ReactFlowInstance, + useReactFlow, } from 'reactflow'; import 'reactflow/dist/style.css'; import { context, updateFlowEdgesAction } from '../../Context'; import ConnectionLine from './ConnectionLine'; import UIKitWrapper from './UIKitWrapper/UIKitWrapper'; -import { FlowParams, createNodesAndEdges } from './utils'; +import { FlowParams } from './utils'; import ControlButton from './ControlButtons'; +import { useNodesAndEdges } from '../../hooks/useNodesAndEdges'; +import { updateNodesAndViewPortAction } from '../../Context/action/updateNodesAndViewPortAction'; const nodeTypes = { custom: UIKitWrapper, }; const FlowContainer = () => { - const { - state: { screens, projects, activeProject }, - dispatch, - } = useContext(context); + const { dispatch } = useContext(context); - const { nodes: initialNodes } = createNodesAndEdges( - projects[activeProject].screens.map((id) => screens[id]) - ); + const { + nodes: initialNodes, + edges: initialEdges, + Viewport, + } = useNodesAndEdges(); + const { setViewport } = useReactFlow(); const [nodes, , onNodesChange] = useNodesState(initialNodes); - const [edges, setEdges, onEdgesChange] = useEdgesState( - projects[activeProject].flowEdges - ); + const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges); + const [rfInstance, setRfInstance] = useState(); const edgeUpdateSuccessful = useRef(true); const onConnect = useCallback( (params) => { - window.console.log({ params }); if (params.source === params.target) return; const newEdge = { ...params, @@ -67,19 +71,34 @@ const FlowContainer = () => { edgeUpdateSuccessful.current = true; }, []); + const onNodeDragStop = () => { + if (!rfInstance?.toObject()) return; + const { nodes, viewport }: { nodes: Node[]; viewport: Viewport } = + rfInstance.toObject(); + dispatch(updateNodesAndViewPortAction({ nodes, viewport })); + }; + + const onInit = (instance: ReactFlowInstance) => { + setRfInstance(instance); + Viewport && setViewport(Viewport); + }; + return ( <> diff --git a/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/UIKitWrapper.tsx b/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/UIKitWrapper.tsx index 8c3e1277afa9..c22b14ca2f7a 100644 --- a/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/UIKitWrapper.tsx +++ b/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/UIKitWrapper.tsx @@ -1,45 +1,52 @@ import { Box } from '@rocket.chat/fuselage'; -import { memo } from 'react'; +import { memo, useContext } from 'react'; import { Handle, Position } from 'reactflow'; import './UIKitWrapper.scss'; import RenderPayload from '../../Preview/Display/RenderPayload/RenderPayload'; import SurfaceRender from '../../Preview/Display/Surface/SurfaceRender'; -import { ScreenType } from '../../../Context/initialState'; +import { idType } from '../../../Context/initialState'; +import { context } from '../../../Context'; -const UIKitWrapper = ({ id, data }: { id: string; data: ScreenType }) => ( - - - - {data.payload.map((payload, index) => ( - - - - +const UIKitWrapper = ({ id, data }: { id: string; data: idType }) => { + const { + state: { screens }, + } = useContext(context); + const { payload, surface } = screens[data]; + return ( + + + + {payload.map((payload, index) => ( + + + + + - - ))} - - -); + ))} + +
+ ); +}; export default memo(UIKitWrapper); diff --git a/packages/uikit-playground/src/Components/HomeContainer/ProjectsList/ProjectsThumbnail.tsx b/packages/uikit-playground/src/Components/HomeContainer/ProjectsList/ProjectsThumbnail.tsx index 6ce79e385ae6..a56ec47a7225 100644 --- a/packages/uikit-playground/src/Components/HomeContainer/ProjectsList/ProjectsThumbnail.tsx +++ b/packages/uikit-playground/src/Components/HomeContainer/ProjectsList/ProjectsThumbnail.tsx @@ -49,7 +49,6 @@ const ProjectsThumbnail = ({ }; const nameSaveHandler = () => { - window.console.log('nameSaveHandler'); if (!name.trim()) { setName(_name); return toast({ diff --git a/packages/uikit-playground/src/Context/action/index.ts b/packages/uikit-playground/src/Context/action/index.ts index 10fc34b0499f..3286d82b578f 100644 --- a/packages/uikit-playground/src/Context/action/index.ts +++ b/packages/uikit-playground/src/Context/action/index.ts @@ -14,13 +14,14 @@ export { createNewScreenAction } from './createNewScreenAction'; export { activeScreenAction } from './activeScreenAction'; export { duplicateScreenAction } from './duplicateScreenAction'; export { deleteScreenAction } from './deleteScreenAction'; -export {renameScreenAction} from './renameScreenAction'; +export { renameScreenAction } from './renameScreenAction'; export { createNewProjectAction } from './createNewProjectAction'; export { activeProjectAction } from './activeProjectAction'; export { duplicateProjectAction } from './duplicateProjectAction'; export { deleteProjectAction } from './deleteProjectAction'; export { renameProjectAction } from './renameProjectAction'; export { updateFlowEdgesAction } from './updateFlowEdgesAction'; +export { updateNodesAndViewPortAction } from './updateNodesAndViewPortAction'; export type { IsMobileAction } from './isMobileAction'; export type { IsTabletAction } from './isTabletAction'; @@ -45,4 +46,4 @@ export type { DuplicateProjectAction } from './duplicateProjectAction'; export type { DeleteProjectAction } from './deleteProjectAction'; export type { RenameProjectAction } from './renameProjectAction'; export type { UpdateFlowEdgesAction } from './updateFlowEdgesAction'; - +export type { UpdateNodesAndViewPortAction } from './updateNodesAndViewPortAction'; diff --git a/packages/uikit-playground/src/Context/action/updateNodesAndViewPortAction.ts b/packages/uikit-playground/src/Context/action/updateNodesAndViewPortAction.ts new file mode 100644 index 000000000000..93ca22396b14 --- /dev/null +++ b/packages/uikit-playground/src/Context/action/updateNodesAndViewPortAction.ts @@ -0,0 +1,19 @@ +import { Node, Viewport } from 'reactflow'; +import { ActionTypes } from '../reducer'; + +type PayloadType = { + nodes: Node[]; + viewport: Viewport; +}; + +export type UpdateNodesAndViewPortAction = { + type: ActionTypes.UpdateNodesAndViewPort; + payload: PayloadType; +}; + +export const updateNodesAndViewPortAction = ( + payload: PayloadType +): UpdateNodesAndViewPortAction => ({ + type: ActionTypes.UpdateNodesAndViewPort, + payload, +}); diff --git a/packages/uikit-playground/src/Context/initialState.ts b/packages/uikit-playground/src/Context/initialState.ts index 908080d2ac77..d2f58d922916 100644 --- a/packages/uikit-playground/src/Context/initialState.ts +++ b/packages/uikit-playground/src/Context/initialState.ts @@ -3,7 +3,7 @@ import type { LayoutBlock } from '@rocket.chat/ui-kit'; import { SurfaceOptions } from '../Components/Preview/Display/Surface/constant'; import getUniqueId from '../utils/getUniqueId'; import getDate from '../utils/getDate'; -import { Edge } from 'reactflow'; +import { Edge, Node, Viewport } from 'reactflow'; export type idType = string; @@ -36,7 +36,7 @@ export type actionPreviewType = { view?: ILayoutBlock[]; }; -export type ILayoutBlock = {actionId: string} & LayoutBlock; +export type ILayoutBlock = { actionId: string } & LayoutBlock; export type ScreenType = { payload: ILayoutBlock[]; @@ -52,7 +52,15 @@ export type ScreensType = { [key: idType]: ScreenType; }; -export type ProjectType = { id: idType; name: string; screens: idType[], date: string, flowEdges: Edge[]}; +export type ProjectType = { + id: idType; + name: string; + screens: idType[]; + date: string; + flowEdges: Edge[]; + flowNodes: Node[]; + viewport?: Viewport; +}; export type ProjectsType = { [key: idType]: ProjectType; @@ -95,6 +103,8 @@ export const initialState: initialStateType = { screens: [initialScreenId], date: getDate(), flowEdges: [], + flowNodes: [], + viewport: undefined, }, }, screens: { diff --git a/packages/uikit-playground/src/Context/reducer.ts b/packages/uikit-playground/src/Context/reducer.ts index 7694d08de30e..5e568dd8fb80 100644 --- a/packages/uikit-playground/src/Context/reducer.ts +++ b/packages/uikit-playground/src/Context/reducer.ts @@ -26,6 +26,7 @@ import { DeleteProjectAction, RenameProjectAction, UpdateFlowEdgesAction, + UpdateNodesAndViewPortAction, } from './action'; import getDate from '../utils/getDate'; @@ -52,7 +53,8 @@ type IAction = | DuplicateProjectAction | DeleteProjectAction | RenameProjectAction - | UpdateFlowEdgesAction; + | UpdateFlowEdgesAction + | UpdateNodesAndViewPortAction; export enum ActionTypes { IsMobile, @@ -78,6 +80,7 @@ export enum ActionTypes { DuplicateProject, RenameProject, UpdateFlowEdges, + UpdateNodesAndViewPort, } const reducer = (state: initialStateType, action: IAction) => { @@ -131,6 +134,7 @@ const reducer = (state: initialStateType, action: IAction) => { id, name: action?.payload || 'default', payload: [], + flowParams: {}, }, }, projects: { @@ -156,6 +160,7 @@ const reducer = (state: initialStateType, action: IAction) => { id, name: action?.payload.name || 'default', payload: state.screens[action.payload.id].payload, + flowParams: {}, }, }, projects: { @@ -254,26 +259,31 @@ const reducer = (state: initialStateType, action: IAction) => { }; } - case ActionTypes.DeleteProject: { - delete state.projects[action.payload]; - return { - ...state, - activeProject: '', - activeScreen: '', - } - } - case ActionTypes.RenameProject: { - state.projects[action.payload.id].name = action.payload.name; - return { ...state }; - } + case ActionTypes.DeleteProject: { + delete state.projects[action.payload]; + return { + ...state, + activeProject: '', + activeScreen: '', + }; + } + case ActionTypes.RenameProject: { + state.projects[action.payload.id].name = action.payload.name; + return { ...state }; + } - case ActionTypes.UpdateFlowEdges: { - let prevEdges = state.projects[activeProject].flowEdges; - prevEdges = [...prevEdges, action.payload] - window.console.log(prevEdges); - state.projects[activeProject].flowEdges = prevEdges; - return { ...state }; - } + case ActionTypes.UpdateFlowEdges: { + let prevEdges = state.projects[activeProject].flowEdges; + prevEdges = [...prevEdges, action.payload]; + state.projects[activeProject].flowEdges = prevEdges; + return { ...state }; + } + case ActionTypes.UpdateNodesAndViewPort: { + const { nodes, viewport } = action.payload; + state.projects[activeProject].flowNodes = nodes; + state.projects[activeProject].viewport = viewport; + return { ...state }; + } default: return state; } diff --git a/packages/uikit-playground/src/Pages/FlowDiagram.tsx b/packages/uikit-playground/src/Pages/FlowDiagram.tsx index 82b5471018b4..99167f3f8e52 100644 --- a/packages/uikit-playground/src/Pages/FlowDiagram.tsx +++ b/packages/uikit-playground/src/Pages/FlowDiagram.tsx @@ -1,11 +1,13 @@ import { Box } from '@rocket.chat/fuselage'; -import React from 'react'; import FlowContainer from '../Components/FlowContainer/FlowContainer'; +import { ReactFlowProvider } from 'reactflow'; const FlowDiagram = () => ( - + + + ); From 63dcfaed8acbe92134837718c12a913dfa685493 Mon Sep 17 00:00:00 2001 From: intVivek Date: Sun, 23 Jul 2023 21:57:54 +0530 Subject: [PATCH 24/50] chores(uikit-playground): fix lint warnings --- .../src/Components/CodeEditor/BlockEditor.tsx | 4 ++++ .../CodeEditor/Parser/parsePayload.ts | 6 +++--- .../Components/CodeEditor/PreviewEditor.tsx | 1 + .../src/Components/CodeEditor/index.tsx | 5 ++++- .../Components/ComponentSideBar/SliderBtn.tsx | 19 +++++++++---------- .../FlowContainer/ConnectionLine.tsx | 1 - .../FlowContainer/FlowContainer.tsx | 5 ++++- .../UIKitWrapper/UIKitWrapper.tsx | 4 ++-- .../HomeContainer/HomeContainer.tsx | 2 +- .../Display/Surface/ContextualBarSurface.tsx | 4 +--- .../Preview/Display/Surface/Surface.tsx | 2 ++ .../Routes/ProjectSpecificLayout.tsx | 1 + .../Components/ScreenThumbnail/Thumbnail.tsx | 2 +- .../uikit-playground/src/Context/index.tsx | 3 +-- .../uikit-playground/src/Pages/Playground.tsx | 3 +-- .../uikit-playground/src/hooks/useAuth.tsx | 13 +++++++------ .../src/hooks/useCodeMirror.ts | 1 + .../src/hooks/useNodesAndEdges.ts | 1 + packages/uikit-playground/src/module.d.ts | 4 ++-- .../src/utils/codePrettier.ts | 2 +- 20 files changed, 47 insertions(+), 36 deletions(-) diff --git a/packages/uikit-playground/src/Components/CodeEditor/BlockEditor.tsx b/packages/uikit-playground/src/Components/CodeEditor/BlockEditor.tsx index c1f834ba80fb..381cbe15ff1b 100644 --- a/packages/uikit-playground/src/Components/CodeEditor/BlockEditor.tsx +++ b/packages/uikit-playground/src/Components/CodeEditor/BlockEditor.tsx @@ -33,6 +33,7 @@ const BlockEditor = ({ extensions }: CodeMirrorProps) => { // do nothing } } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [changes?.value]); useEffect(() => { @@ -46,6 +47,7 @@ const BlockEditor = ({ extensions }: CodeMirrorProps) => { // do nothing } } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [debounceValue]); useEffect(() => { @@ -55,10 +57,12 @@ const BlockEditor = ({ extensions }: CodeMirrorProps) => { {} ); } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [screens[activeScreen]?.payload, activeScreen]); useEffect(() => { setValue(JSON.stringify(screens[activeScreen]?.payload, undefined, 4), {}); + // eslint-disable-next-line react-hooks/exhaustive-deps }, [activeScreen]); return ( diff --git a/packages/uikit-playground/src/Components/CodeEditor/Parser/parsePayload.ts b/packages/uikit-playground/src/Components/CodeEditor/Parser/parsePayload.ts index 114ec242009d..8a431bc05e15 100644 --- a/packages/uikit-playground/src/Components/CodeEditor/Parser/parsePayload.ts +++ b/packages/uikit-playground/src/Components/CodeEditor/Parser/parsePayload.ts @@ -1,9 +1,9 @@ -import type { Diagnostic } from '@codemirror/lint'; +// import type { Diagnostic } from '@codemirror/lint'; import type { EditorView } from 'codemirror'; const parsePayload = ( - head: any, - Diagnostic: Diagnostic[], + head: { from: number; to: number }, + // Diagnostic: Diagnostic[], view: EditorView ) => { const payload = JSON.parse( diff --git a/packages/uikit-playground/src/Components/CodeEditor/PreviewEditor.tsx b/packages/uikit-playground/src/Components/CodeEditor/PreviewEditor.tsx index 9584193f0f81..46b7cbe3eea3 100644 --- a/packages/uikit-playground/src/Components/CodeEditor/PreviewEditor.tsx +++ b/packages/uikit-playground/src/Components/CodeEditor/PreviewEditor.tsx @@ -20,6 +20,7 @@ const PreviewEditor = ({ extensions }: CodeMirrorProps) => { JSON.stringify(screens[activeScreen]?.actionPreview, undefined, 4), {} ); + // eslint-disable-next-line react-hooks/exhaustive-deps }, [screens[activeScreen]?.actionPreview]); return ( diff --git a/packages/uikit-playground/src/Components/CodeEditor/index.tsx b/packages/uikit-playground/src/Components/CodeEditor/index.tsx index e7a12ca2d296..067ddceb27ac 100644 --- a/packages/uikit-playground/src/Components/CodeEditor/index.tsx +++ b/packages/uikit-playground/src/Components/CodeEditor/index.tsx @@ -9,7 +9,7 @@ import useCodeMirror from '../../hooks/useCodeMirror'; import codePrettier from '../../utils/codePrettier'; type CodeMirrorProps = { - extensions?: Extension[], + extensions?: Extension[]; }; const CodeEditor = ({ extensions }: CodeMirrorProps) => { @@ -39,6 +39,7 @@ const CodeEditor = ({ extensions }: CodeMirrorProps) => { // do nothing } } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [changes?.value]); useEffect(() => { @@ -52,12 +53,14 @@ const CodeEditor = ({ extensions }: CodeMirrorProps) => { // do nothing } } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [debounceValue]); useEffect(() => { if (!screens[activeScreen].changedByEditor) { setValue(JSON.stringify(screens[activeScreen].payload, undefined, 4), {}); } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [screens[activeScreen].payload]); return ( diff --git a/packages/uikit-playground/src/Components/ComponentSideBar/SliderBtn.tsx b/packages/uikit-playground/src/Components/ComponentSideBar/SliderBtn.tsx index 0f13639581ac..52ba6d88d750 100644 --- a/packages/uikit-playground/src/Components/ComponentSideBar/SliderBtn.tsx +++ b/packages/uikit-playground/src/Components/ComponentSideBar/SliderBtn.tsx @@ -48,7 +48,6 @@ const SliderBtn: FC = () => { transition: var(--animation-default); `; - // eslint-disable-next-line no-nested-ternary const toggleStyle = !isMobile ? css` left: 0px; @@ -71,8 +70,8 @@ const SliderBtn: FC = () => { width={sideBarToggle ? '100%' : '130px'} paddingInlineStart={'20px'} height={'40px'} - display='flex' - alignItems='center' + display="flex" + alignItems="center" justifyContent={'space-between'} onClick={() => !sideBarToggle && dispatch(sidebarToggleAction(!sideBarToggle)) @@ -81,7 +80,7 @@ const SliderBtn: FC = () => { className={toggleStyle} > {isMobile && ( sideBarToggle && dispatch(sidebarToggleAction(!sideBarToggle)) } @@ -106,7 +105,7 @@ const SliderBtn: FC = () => { cursor: pointer; `} > - + )} diff --git a/packages/uikit-playground/src/Components/FlowContainer/ConnectionLine.tsx b/packages/uikit-playground/src/Components/FlowContainer/ConnectionLine.tsx index 97f7b1c39aa4..82fb979ff075 100644 --- a/packages/uikit-playground/src/Components/FlowContainer/ConnectionLine.tsx +++ b/packages/uikit-playground/src/Components/FlowContainer/ConnectionLine.tsx @@ -11,7 +11,6 @@ const ConnectionLine = ({ toY: number; toPosition: string; connectionLineType: string; - connectionLineStyle?: any; }) => ( { dispatch(updateFlowEdgesAction(newEdge)); setEdges((eds) => addEdge(newEdge, eds)); }, + // eslint-disable-next-line react-hooks/exhaustive-deps [setEdges] ); @@ -62,6 +63,7 @@ const FlowContainer = () => { const onEdgeUpdate = useCallback((oldEdge, newConnection) => { edgeUpdateSuccessful.current = true; setEdges((els) => updateEdge(oldEdge, newConnection, els)); + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const onEdgeUpdateEnd = useCallback((_, edge) => { @@ -69,6 +71,7 @@ const FlowContainer = () => { setEdges((eds) => eds.filter((e) => e.id !== edge.id)); } edgeUpdateSuccessful.current = true; + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const onNodeDragStop = () => { diff --git a/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/UIKitWrapper.tsx b/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/UIKitWrapper.tsx index c22b14ca2f7a..68f805f2d048 100644 --- a/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/UIKitWrapper.tsx +++ b/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/UIKitWrapper.tsx @@ -1,5 +1,5 @@ import { Box } from '@rocket.chat/fuselage'; -import { memo, useContext } from 'react'; +import { useContext } from 'react'; import { Handle, Position } from 'reactflow'; import './UIKitWrapper.scss'; @@ -49,4 +49,4 @@ const UIKitWrapper = ({ id, data }: { id: string; data: idType }) => { ); }; -export default memo(UIKitWrapper); +export default UIKitWrapper; diff --git a/packages/uikit-playground/src/Components/HomeContainer/HomeContainer.tsx b/packages/uikit-playground/src/Components/HomeContainer/HomeContainer.tsx index 92a65b7f461d..ad06830d4f18 100644 --- a/packages/uikit-playground/src/Components/HomeContainer/HomeContainer.tsx +++ b/packages/uikit-playground/src/Components/HomeContainer/HomeContainer.tsx @@ -1,4 +1,4 @@ -import { Box, Button, Label } from '@rocket.chat/fuselage'; +import { Box, Label } from '@rocket.chat/fuselage'; import ProjectsList from './ProjectsList/ProjectsList'; import { useContext } from 'react'; import { context, createNewProjectAction } from '../../Context'; diff --git a/packages/uikit-playground/src/Components/Preview/Display/Surface/ContextualBarSurface.tsx b/packages/uikit-playground/src/Components/Preview/Display/Surface/ContextualBarSurface.tsx index cd02667d0883..690badae81e3 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/Surface/ContextualBarSurface.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/Surface/ContextualBarSurface.tsx @@ -1,4 +1,3 @@ -import { css } from '@rocket.chat/css-in-js'; import { Avatar, Box, @@ -9,10 +8,9 @@ import { ContextualbarFooter, ContextualbarHeader, ContextualbarTitle, - Margins, } from '@rocket.chat/fuselage'; import { Scrollbars } from 'rc-scrollbars'; -import { CSSProperties, ReactNode } from 'react'; +import { ReactNode } from 'react'; const ContextualBarSurface = ({ children }: { children: ReactNode }) => ( diff --git a/packages/uikit-playground/src/Components/Preview/Display/Surface/Surface.tsx b/packages/uikit-playground/src/Components/Preview/Display/Surface/Surface.tsx index 6d5b82471a57..d4c135b37bd5 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/Surface/Surface.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/Surface/Surface.tsx @@ -46,6 +46,7 @@ const Surface: FC = () => { })), isChangeByDnd: false, }); + // eslint-disable-next-line react-hooks/exhaustive-deps }, [screens[activeScreen]?.payload]); useEffect(() => { @@ -57,6 +58,7 @@ const Surface: FC = () => { }) ); } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [uniqueBlocks]); const onDragEnd = ({ destination, source }: DropResult) => { diff --git a/packages/uikit-playground/src/Components/Routes/ProjectSpecificLayout.tsx b/packages/uikit-playground/src/Components/Routes/ProjectSpecificLayout.tsx index 68cd25a02048..150dd6faadec 100644 --- a/packages/uikit-playground/src/Components/Routes/ProjectSpecificLayout.tsx +++ b/packages/uikit-playground/src/Components/Routes/ProjectSpecificLayout.tsx @@ -16,6 +16,7 @@ export const ProjectSpecificLayout = () => { useEffect(() => { if (!projectId || !projects[projectId]) navigate(routes.home); else dispatch(activeProjectAction(projectId)); + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return <>{outlet}; diff --git a/packages/uikit-playground/src/Components/ScreenThumbnail/Thumbnail.tsx b/packages/uikit-playground/src/Components/ScreenThumbnail/Thumbnail.tsx index c3e104d9def2..c3c421d4e539 100644 --- a/packages/uikit-playground/src/Components/ScreenThumbnail/Thumbnail.tsx +++ b/packages/uikit-playground/src/Components/ScreenThumbnail/Thumbnail.tsx @@ -1,7 +1,7 @@ import { css } from '@rocket.chat/css-in-js'; import { Box } from '@rocket.chat/fuselage'; import type { ReactNode, ComponentProps } from 'react'; -import React, { useRef, useMemo, useState, useEffect } from 'react'; +import React, { useRef, useState, useEffect } from 'react'; interface ThumbnailProps { of: ReactNode; diff --git a/packages/uikit-playground/src/Context/index.tsx b/packages/uikit-playground/src/Context/index.tsx index ee4b960de789..89ccdee94ef4 100644 --- a/packages/uikit-playground/src/Context/index.tsx +++ b/packages/uikit-playground/src/Context/index.tsx @@ -1,9 +1,8 @@ +/* eslint-disable react-refresh/only-export-components */ import createCtx from './createCtx'; import { initialState } from './initialState'; import reducer from './reducer'; - export * from './action'; - const [context, Provider] = createCtx(reducer, initialState); export { context, Provider }; diff --git a/packages/uikit-playground/src/Pages/Playground.tsx b/packages/uikit-playground/src/Pages/Playground.tsx index 4dd4deee7e8d..1f365ab1d544 100644 --- a/packages/uikit-playground/src/Pages/Playground.tsx +++ b/packages/uikit-playground/src/Pages/Playground.tsx @@ -1,6 +1,5 @@ -/* eslint-disable react-hooks/exhaustive-deps */ import { Box } from '@rocket.chat/fuselage'; -import { useContext, type Fc } from 'react'; +import { useContext, type FC } from 'react'; import ComponentSideBar from '../Components/ComponentSideBar'; import CreateNewScreenContainer from '../Components/CreateNewScreen/CreateNewScreenContainer'; diff --git a/packages/uikit-playground/src/hooks/useAuth.tsx b/packages/uikit-playground/src/hooks/useAuth.tsx index e87c063c71a1..10f26376b673 100644 --- a/packages/uikit-playground/src/hooks/useAuth.tsx +++ b/packages/uikit-playground/src/hooks/useAuth.tsx @@ -1,22 +1,22 @@ -// ts-nocheck - +/* eslint-disable react-refresh/only-export-components */ import type { ReactNode } from 'react'; import { createContext, useContext, useMemo } from 'react'; import { useNavigate } from 'react-router-dom'; import { useLocalStorage } from './useLocalStorage'; +import { userType } from '../Context/initialState'; const AuthContext = createContext<{ - user?: any, - login?: (data: any) => Promise, - logout?: () => void, + user?: userType; + login?: (data: unknown) => Promise; + logout?: () => void; }>({}); export const AuthProvider = ({ children }: { children: ReactNode }) => { const [user, setUser] = useLocalStorage('user', null); const navigate = useNavigate(); - const login = async (data: any) => { + const login = async (data: unknown) => { setUser(data); navigate('/dashboard/profile', { replace: true }); }; @@ -32,6 +32,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => { login, logout, }), + // eslint-disable-next-line react-hooks/exhaustive-deps [user] ); diff --git a/packages/uikit-playground/src/hooks/useCodeMirror.ts b/packages/uikit-playground/src/hooks/useCodeMirror.ts index 8816f5f2991c..d4d67d3b8b20 100644 --- a/packages/uikit-playground/src/hooks/useCodeMirror.ts +++ b/packages/uikit-playground/src/hooks/useCodeMirror.ts @@ -73,6 +73,7 @@ export default function useCodeMirror(extensions?: Extension[], doc?: string) { }); return () => view.current?.destroy(); + // eslint-disable-next-line react-hooks/exhaustive-deps }, [element]); return { editor, changes, setValue }; diff --git a/packages/uikit-playground/src/hooks/useNodesAndEdges.ts b/packages/uikit-playground/src/hooks/useNodesAndEdges.ts index 0e6126c1c00a..1fd0f13d482b 100644 --- a/packages/uikit-playground/src/hooks/useNodesAndEdges.ts +++ b/packages/uikit-playground/src/hooks/useNodesAndEdges.ts @@ -28,6 +28,7 @@ export function useNodesAndEdges() { }); }); return prevNodes; + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const edges = projects[activeProject].flowEdges; diff --git a/packages/uikit-playground/src/module.d.ts b/packages/uikit-playground/src/module.d.ts index 65486d449683..4349c6c3bc1d 100644 --- a/packages/uikit-playground/src/module.d.ts +++ b/packages/uikit-playground/src/module.d.ts @@ -1,5 +1,5 @@ declare module '*.svg' { export const ReactComponent: React.SFC>; - const src: any; + const src: unknown; export default src; -} \ No newline at end of file +} diff --git a/packages/uikit-playground/src/utils/codePrettier.ts b/packages/uikit-playground/src/utils/codePrettier.ts index b1b455f8748a..0fda62bb93ba 100644 --- a/packages/uikit-playground/src/utils/codePrettier.ts +++ b/packages/uikit-playground/src/utils/codePrettier.ts @@ -1,7 +1,7 @@ import prettier from 'prettier'; import pluginBabel from 'prettier/parser-babel'; -const codePrettier = (code: string, cursor: any) => +const codePrettier = (code: string, cursor: number) => prettier.formatWithCursor(code, { parser: 'json', plugins: [pluginBabel], From 8147170ce8b6f360d61cd24091c7158b26a2dd0c Mon Sep 17 00:00:00 2001 From: intVivek Date: Fri, 28 Jul 2023 16:08:40 +0530 Subject: [PATCH 25/50] feat(uikit-playground): added prototype --- packages/uikit-playground/src/App.tsx | 3 +- .../ControlButtons/ControlButtons.tsx | 4 +- .../HomeContainer/HomeContainer.tsx | 1 + .../PrototypeRender/PrototypeRender.scss | 40 ++++++++++++ .../PrototypeRender/PrototypeRender.tsx | 63 +++++++++++++++++++ .../src/Components/PrototypeRender/index.ts | 1 + .../PtototypeContainer/PrototypeContainer.tsx | 40 ++++++++++++ .../Components/PtototypeContainer/index.ts | 1 + .../ScreenThumbnail/CreateNewScreenButton.tsx | 3 +- .../src/Components/Templates/Templates.tsx | 2 +- .../uikit-playground/src/Pages/Prototype.tsx | 12 ++++ .../uikit-playground/src/Routes/Routes.ts | 1 + 12 files changed, 167 insertions(+), 4 deletions(-) create mode 100644 packages/uikit-playground/src/Components/PrototypeRender/PrototypeRender.scss create mode 100644 packages/uikit-playground/src/Components/PrototypeRender/PrototypeRender.tsx create mode 100644 packages/uikit-playground/src/Components/PrototypeRender/index.ts create mode 100644 packages/uikit-playground/src/Components/PtototypeContainer/PrototypeContainer.tsx create mode 100644 packages/uikit-playground/src/Components/PtototypeContainer/index.ts create mode 100644 packages/uikit-playground/src/Pages/Prototype.tsx diff --git a/packages/uikit-playground/src/App.tsx b/packages/uikit-playground/src/App.tsx index 7e60bf6e198c..ed32f3c388fa 100644 --- a/packages/uikit-playground/src/App.tsx +++ b/packages/uikit-playground/src/App.tsx @@ -15,6 +15,7 @@ import { useMediaQueries } from '@rocket.chat/fuselage-hooks'; import { Box } from '@rocket.chat/fuselage'; import FlowDiagram from './Pages/FlowDiagram'; import { ProjectSpecificLayout } from './Components/Routes/ProjectSpecificLayout'; +import Prototype from './Pages/Prototype'; function App() { const { dispatch } = useContext(context); @@ -51,7 +52,7 @@ function App() { }> } /> } /> - {/* } /> */} + } /> } /> {/* */} diff --git a/packages/uikit-playground/src/Components/FlowContainer/ControlButtons/ControlButtons.tsx b/packages/uikit-playground/src/Components/FlowContainer/ControlButtons/ControlButtons.tsx index 63b6bb5811b4..39ef0beac8ed 100644 --- a/packages/uikit-playground/src/Components/FlowContainer/ControlButtons/ControlButtons.tsx +++ b/packages/uikit-playground/src/Components/FlowContainer/ControlButtons/ControlButtons.tsx @@ -13,7 +13,9 @@ const ControlButtons = () => { > - + navigate(`/${projectId}/${routes.prototype}`)} + > diff --git a/packages/uikit-playground/src/Components/HomeContainer/HomeContainer.tsx b/packages/uikit-playground/src/Components/HomeContainer/HomeContainer.tsx index ad06830d4f18..e6bf0e9274a7 100644 --- a/packages/uikit-playground/src/Components/HomeContainer/HomeContainer.tsx +++ b/packages/uikit-playground/src/Components/HomeContainer/HomeContainer.tsx @@ -27,6 +27,7 @@ const HomeContainer = () => { dispatch(createNewProjectAction())} /> diff --git a/packages/uikit-playground/src/Components/PrototypeRender/PrototypeRender.scss b/packages/uikit-playground/src/Components/PrototypeRender/PrototypeRender.scss new file mode 100644 index 000000000000..50197006c9e2 --- /dev/null +++ b/packages/uikit-playground/src/Components/PrototypeRender/PrototypeRender.scss @@ -0,0 +1,40 @@ +.rc-prototype-renderer { + background: white; + padding: 20px !important; + border-radius: 20px; + outline: 1px solid var(--default-border-color) !important; + + .rc-prototype_action{ + position: relative; + + &::after { + content: ''; + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background-color: var(--RCPG-tertary-color); + opacity: 0; + } + + &-glow { + &::after { + animation: glow 1s ease-out; + } + } + + + @keyframes glow { + 0% { + opacity: 0; + } + 2% { + opacity: 0.3; + } + 100% { + opacity: 0; + } + } + } +} \ No newline at end of file diff --git a/packages/uikit-playground/src/Components/PrototypeRender/PrototypeRender.tsx b/packages/uikit-playground/src/Components/PrototypeRender/PrototypeRender.tsx new file mode 100644 index 000000000000..e01f6d46148b --- /dev/null +++ b/packages/uikit-playground/src/Components/PrototypeRender/PrototypeRender.tsx @@ -0,0 +1,63 @@ +import './PrototypeRender.scss'; +import { Box } from '@rocket.chat/fuselage'; +import RenderPayload from '../Preview/Display/RenderPayload/RenderPayload'; +import SurfaceRender from '../Preview/Display/Surface/SurfaceRender'; +import { SurfaceOptions } from '../Preview/Display/Surface/constant'; +import { ILayoutBlock, idType } from '../../Context/initialState'; +import { Edge } from 'reactflow'; +import { css } from '@rocket.chat/css-in-js'; +import { useState } from 'react'; + +const PrototypeRender = ({ + payload, + surface, + flowEdges, + activeActions, + onSelectAction, +}: { + payload: ILayoutBlock[]; + surface: SurfaceOptions; + flowEdges: Edge[]; + activeActions: idType[]; + onSelectAction: (id: idType) => void; +}) => { + const [glowActive, setGlowActive] = useState(false); + const actionClickHandler = (id: idType) => { + const edge = flowEdges.find((edge) => edge.sourceHandle === id); + if (edge) return onSelectAction(edge.target); + + setGlowActive(true); + setTimeout(() => setGlowActive(false), 1000); + }; + return ( + + + {payload.map((action, id) => ( + actionClickHandler(action.actionId)}> + + + + + + + ))} + + + ); +}; + +export default PrototypeRender; diff --git a/packages/uikit-playground/src/Components/PrototypeRender/index.ts b/packages/uikit-playground/src/Components/PrototypeRender/index.ts new file mode 100644 index 000000000000..74e698a56b43 --- /dev/null +++ b/packages/uikit-playground/src/Components/PrototypeRender/index.ts @@ -0,0 +1 @@ +export { default } from './PrototypeRender'; diff --git a/packages/uikit-playground/src/Components/PtototypeContainer/PrototypeContainer.tsx b/packages/uikit-playground/src/Components/PtototypeContainer/PrototypeContainer.tsx new file mode 100644 index 000000000000..82003e2d0e0a --- /dev/null +++ b/packages/uikit-playground/src/Components/PtototypeContainer/PrototypeContainer.tsx @@ -0,0 +1,40 @@ +import { useContext, useMemo, useState } from 'react'; +import { context } from '../../Context'; +import { Box, Scrollable } from '@rocket.chat/fuselage'; +import PrototypeRender from '../PrototypeRender/PrototypeRender'; + +const PrototypeContainer = () => { + const { + state: { projects, activeProject, screens }, + } = useContext(context); + window.console.log(projects[activeProject].flowEdges); + const [currentScreenID, setCurrentScreenID] = useState( + projects[activeProject].screens[0] + ); + const { surface, payload } = screens[currentScreenID]; + + const activeActions = useMemo(() => { + return projects[activeProject]?.flowEdges.map((edge) => edge.sourceHandle); + }, [activeProject, projects]); + return ( + + + + + + ); +}; + +export default PrototypeContainer; diff --git a/packages/uikit-playground/src/Components/PtototypeContainer/index.ts b/packages/uikit-playground/src/Components/PtototypeContainer/index.ts new file mode 100644 index 000000000000..9b39511e5001 --- /dev/null +++ b/packages/uikit-playground/src/Components/PtototypeContainer/index.ts @@ -0,0 +1 @@ +export {default} from './PrototypeContainer'; \ No newline at end of file diff --git a/packages/uikit-playground/src/Components/ScreenThumbnail/CreateNewScreenButton.tsx b/packages/uikit-playground/src/Components/ScreenThumbnail/CreateNewScreenButton.tsx index 41981ab2d9ab..afcec9320406 100644 --- a/packages/uikit-playground/src/Components/ScreenThumbnail/CreateNewScreenButton.tsx +++ b/packages/uikit-playground/src/Components/ScreenThumbnail/CreateNewScreenButton.tsx @@ -4,6 +4,7 @@ import { ComponentProps } from 'react'; const CreateNewScreenButton = ({ size = '60px', + name = 'plus', ...props }: { size?: ComponentProps['size']; @@ -13,7 +14,7 @@ const CreateNewScreenButton = ({ { + {openCreateNewScreen && ( + - + > + {projects[activeProject]?.screens + .map((id) => screens[id]) + .map((screen, i) => ( + screens[id]) + .length <= 1 + } + /> + ))} + + + )}
); diff --git a/packages/uikit-playground/src/Components/FlowContainer/ControlButtons/ControlButtons.tsx b/packages/uikit-playground/src/Components/FlowContainer/ControlButtons/ControlButtons.tsx index 39ef0beac8ed..ecea95fdd067 100644 --- a/packages/uikit-playground/src/Components/FlowContainer/ControlButtons/ControlButtons.tsx +++ b/packages/uikit-playground/src/Components/FlowContainer/ControlButtons/ControlButtons.tsx @@ -1,25 +1,7 @@ -import { Icon } from '@rocket.chat/fuselage'; -import { useNavigate, useParams } from 'react-router-dom'; -import { Controls, ControlButton } from 'reactflow'; -import routes from '../../../Routes/Routes'; +import { Controls } from 'reactflow'; const ControlButtons = () => { - const navigate = useNavigate(); - const { projectId } = useParams(); - return ( - - navigate(`/${projectId}/${routes.project}`)} - > - - - navigate(`/${projectId}/${routes.prototype}`)} - > - - - - ); + return ; }; export default ControlButtons; diff --git a/packages/uikit-playground/src/Components/NavBar/NavBar.tsx b/packages/uikit-playground/src/Components/NavBar/NavBar.tsx index e29afdb31236..1ec75a6bc236 100644 --- a/packages/uikit-playground/src/Components/NavBar/NavBar.tsx +++ b/packages/uikit-playground/src/Components/NavBar/NavBar.tsx @@ -19,7 +19,7 @@ import RightNavBtn from './RightNavBtn'; const NabBar: FC = () => { const { - state: { isMobile, activeProject, screens, activeScreen }, + state: { isMobile, screens, activeScreen }, dispatch, } = useContext(context); const toast = useToastBarDispatch(); @@ -39,9 +39,27 @@ const NabBar: FC = () => { user-select: none; `} > - + {!isMobile && ( + + )} { `} > - - )} diff --git a/packages/uikit-playground/src/Components/Preview/Display/Surface/MessageSurface.tsx b/packages/uikit-playground/src/Components/Preview/Display/Surface/MessageSurface.tsx index 22a1da2d6ef3..ee429e3e2231 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/Surface/MessageSurface.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/Surface/MessageSurface.tsx @@ -5,24 +5,14 @@ const MessageSurface = ({ children }: { children: ReactNode }) => ( - Haylie George - @haylie.george + Vivek Srivastava + @vivek.srivastava Admin User Owner diff --git a/packages/uikit-playground/src/Components/Preview/Editor/EditorPanel.tsx b/packages/uikit-playground/src/Components/Preview/Editor/EditorPanel.tsx index 27a704b79764..c3cd23a22170 100644 --- a/packages/uikit-playground/src/Components/Preview/Editor/EditorPanel.tsx +++ b/packages/uikit-playground/src/Components/Preview/Editor/EditorPanel.tsx @@ -1,7 +1,7 @@ import { css } from '@rocket.chat/css-in-js'; import { Box } from '@rocket.chat/fuselage'; import type { FC } from 'react'; -import React, { useContext } from 'react'; +import { useContext } from 'react'; import { context, editorTabsToggleAction } from '../../../Context'; import ToggleTabs from '../../ToggleTabs'; @@ -10,20 +10,30 @@ import ActionPreviewEditor from './ActionPreviewEditor'; import FlowDiagram from '../../../Pages/FlowDiagram'; import PrototypeContainer from '../../PtototypeContainer/PrototypeContainer'; -const EditorPanel: FC = () => { - enum TabsItem { - ActionBlock, - ActionPreview, - FlowDiagram, - Prototype, - } +enum TabsItem { + ActionBlock, + ActionPreview, + FlowDiagram, + Prototype, +} - const tabsItem = { - [TabsItem.ActionBlock]: 'Action Block', - [TabsItem.ActionPreview]: 'Action Preview', - [TabsItem.FlowDiagram]: 'Flow Diagram', - [TabsItem.Prototype]: 'Prototype', - }; +const tabsItem = { + [TabsItem.ActionBlock]: { + name: 'Action Block', + Container: ActionBlockEditor, + }, + [TabsItem.ActionPreview]: { + name: 'Action Preview', + Container: ActionPreviewEditor, + }, + [TabsItem.FlowDiagram]: { + name: 'Flow Diagram', + Container: FlowDiagram, + }, + [TabsItem.Prototype]: { name: 'Prototype', Container: PrototypeContainer }, +} as const; + +const EditorPanel: FC = () => { const { state: { editorTabsToggle }, dispatch, @@ -33,30 +43,11 @@ const EditorPanel: FC = () => { dispatch(editorTabsToggleAction(index)); }; - const tabChangeStyle = () => { - switch (editorTabsToggle) { - case TabsItem.ActionBlock: - return css` - transition: 0.5s ease; - left: 0; - `; - case TabsItem.ActionPreview: - return css` - transition: 0.5s ease; - left: -100%; - `; - - case TabsItem.FlowDiagram: - return css` - transition: 0.5s ease; - left: -200%; - `; - case TabsItem.Prototype: - return css` - transition: 0.5s ease; - left: -300%; - `; - } + const tabChangeStyle = (index: number) => { + return css` + transition: 0.5s ease; + left: calc(-100% * ${index}); + `; }; return ( @@ -73,7 +64,7 @@ const EditorPanel: FC = () => { ]} > item.name)} onChange={toggleTabsHandler} selectedTab={editorTabsToggle} /> @@ -89,12 +80,17 @@ const EditorPanel: FC = () => { height={'100%'} display={'flex'} borderBlockStart="var(--default-border)" - className={tabChangeStyle()} + className={tabChangeStyle(editorTabsToggle)} > - - - - + {Object.values(tabsItem).map(({ Container }, index) => ( + <> + {index === editorTabsToggle ? ( + + ) : ( + + )} + + ))}
diff --git a/packages/uikit-playground/src/Components/Preview/NavPanel/NavPanel.tsx b/packages/uikit-playground/src/Components/Preview/NavPanel/NavPanel.tsx index 8b65e4af52ce..118ae175048b 100644 --- a/packages/uikit-playground/src/Components/Preview/NavPanel/NavPanel.tsx +++ b/packages/uikit-playground/src/Components/Preview/NavPanel/NavPanel.tsx @@ -3,44 +3,62 @@ import { Box, Button } from '@rocket.chat/fuselage'; import type { FC } from 'react'; import React, { useContext } from 'react'; -import { context, previewTabsToggleAction, templatesToggleAction } from '../../../Context'; +import { + context, + previewTabsToggleAction, + templatesToggleAction, +} from '../../../Context'; import SurfaceSelect from '../../SurfaceSelect'; import ToggleTabs from '../../ToggleTabs'; const NavPanel: FC = () => { - const { - state: { isMobile, isTablet, previewTabsToggle }, - dispatch, - } = useContext(context); + const { + state: { isMobile, isTablet, previewTabsToggle }, + dispatch, + } = useContext(context); - const toggleTabsHandler = (index: number) => { - dispatch(previewTabsToggleAction(index)); - }; + const toggleTabsHandler = (index: number) => { + dispatch(previewTabsToggleAction(index)); + }; - const tabsItem: string[] = ['Preview', 'Editor']; - return ( - - - {!isMobile && } - - - {isTablet && } - - ); + const tabsItem: string[] = ['Preview', 'Editor']; + return ( + + {!isMobile && ( + + + + + )} + {isTablet && ( + + )} + + ); }; export default NavPanel; diff --git a/packages/uikit-playground/src/Components/Preview/SplitPlaneContainer/SplitPlaneContainer.tsx b/packages/uikit-playground/src/Components/Preview/SplitPlaneContainer/SplitPlaneContainer.tsx index 50596f94c0ef..592da9d2b0e0 100644 --- a/packages/uikit-playground/src/Components/Preview/SplitPlaneContainer/SplitPlaneContainer.tsx +++ b/packages/uikit-playground/src/Components/Preview/SplitPlaneContainer/SplitPlaneContainer.tsx @@ -1,6 +1,6 @@ import './splitPlane.css'; import type { FC } from 'react'; -import React, { useEffect, useContext } from 'react'; +import { useEffect, useContext } from 'react'; import SplitPane from 'react-split-pane'; import { context, previewTabsToggleAction } from '../../../Context'; @@ -8,8 +8,8 @@ import Display from '../Display'; import EditorPanel from '../Editor'; type PreviewSizeType = { - blockSize: number, - inlineSize: number, + blockSize: number; + inlineSize: number; }; const SplitPlaneContainer: FC<{ PreviewSize: PreviewSizeType }> = ({ PreviewSize, @@ -25,8 +25,8 @@ const SplitPlaneContainer: FC<{ PreviewSize: PreviewSizeType }> = ({ const splitPaneProps = { defaultSize: PreviewSize.inlineSize * 0.5, - minSize: 500, - maxSize: PreviewSize.inlineSize - 300, + minSize: 300, + maxSize: PreviewSize.inlineSize - 350, allowResize: !isTablet, }; diff --git a/packages/uikit-playground/src/Components/PrototypeRender/PrototypeRender.scss b/packages/uikit-playground/src/Components/PrototypeRender/PrototypeRender.scss index beb188367494..84731b4f01ae 100644 --- a/packages/uikit-playground/src/Components/PrototypeRender/PrototypeRender.scss +++ b/packages/uikit-playground/src/Components/PrototypeRender/PrototypeRender.scss @@ -1,9 +1,6 @@ .rc-prototype-renderer { background: white; padding: 20px !important; - border-radius: 20px; - max-width: 800px !important; - outline: 1px solid var(--default-border-color) !important; .rc-prototype_action{ position: relative; diff --git a/packages/uikit-playground/src/Components/PtototypeContainer/PrototypeContainer.tsx b/packages/uikit-playground/src/Components/PtototypeContainer/PrototypeContainer.tsx index 35cc9b855525..2cddaa055600 100644 --- a/packages/uikit-playground/src/Components/PtototypeContainer/PrototypeContainer.tsx +++ b/packages/uikit-playground/src/Components/PtototypeContainer/PrototypeContainer.tsx @@ -24,13 +24,7 @@ const PrototypeContainer = () => { return ( - + ( - + {templates && templates.map((template, i) =>
)} diff --git a/packages/uikit-playground/src/Components/Templates/Templates.tsx b/packages/uikit-playground/src/Components/Templates/Templates.tsx index d6fcc939d672..35b734f38e05 100644 --- a/packages/uikit-playground/src/Components/Templates/Templates.tsx +++ b/packages/uikit-playground/src/Components/Templates/Templates.tsx @@ -33,6 +33,7 @@ const Templates: FC = () => { >
)} diff --git a/packages/uikit-playground/src/Components/DropDown/DropDown.tsx b/packages/uikit-playground/src/Components/DropDown/DropDown.tsx index cc4580576a1f..ff5648b93185 100644 --- a/packages/uikit-playground/src/Components/DropDown/DropDown.tsx +++ b/packages/uikit-playground/src/Components/DropDown/DropDown.tsx @@ -5,7 +5,7 @@ import Items from './Items'; import type { Item, ItemBranch } from './types'; interface DropDownProps { - readonly BlocksTree: Item, + readonly BlocksTree: Item; } const DropDown = ({ BlocksTree }: DropDownProps) => { @@ -23,7 +23,7 @@ const DropDown = ({ BlocksTree }: DropDownProps) => { ); return ( - + {BlocksTree.map((branch: ItemBranch, i: number) => ( {recursiveComponentTree(branch, layer)} ))} diff --git a/packages/uikit-playground/src/Components/DropDown/Items.tsx b/packages/uikit-playground/src/Components/DropDown/Items.tsx index 84eca2f88e8b..18eb6a10dcc5 100644 --- a/packages/uikit-playground/src/Components/DropDown/Items.tsx +++ b/packages/uikit-playground/src/Components/DropDown/Items.tsx @@ -1,6 +1,6 @@ import { css } from '@rocket.chat/css-in-js'; import { Box, Label, Chevron } from '@rocket.chat/fuselage'; -import React, { useState, useContext } from 'react'; +import { useState, useContext } from 'react'; import { context, updatePayloadAction } from '../../Context'; import ItemsIcon from './ItemsIcon'; @@ -18,8 +18,8 @@ const Items = ({ label, children, layer, payload }: ItemProps) => { payload && dispatch( updatePayloadAction({ - payload: [ - ...state.screens[state.activeScreen].payload, + blocks: [ + ...state.screens[state.activeScreen].payload.blocks, { actionId: getUniqueId(), ...payload[0] }, ], changedByEditor: false, diff --git a/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/UIKitWrapper.tsx b/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/UIKitWrapper.tsx index 8e2885ca4bff..7e29f065c684 100644 --- a/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/UIKitWrapper.tsx +++ b/packages/uikit-playground/src/Components/FlowContainer/UIKitWrapper/UIKitWrapper.tsx @@ -13,7 +13,7 @@ const UIKitWrapper = ({ id, data }: { id: string; data: idType }) => { state: { screens }, } = useContext(context); if (!screens[data]) return null; - const { payload, surface } = screens[data]; + const { blocks, surface } = screens[data].payload; return ( { id={`${id}`} /> - {payload.map((payload, index) => ( + {blocks.map((block, index) => ( - + diff --git a/packages/uikit-playground/src/Components/HomeContainer/ProjectsList/ProjectsList.tsx b/packages/uikit-playground/src/Components/HomeContainer/ProjectsList/ProjectsList.tsx index cd1490d26e9b..c767f406ad4e 100644 --- a/packages/uikit-playground/src/Components/HomeContainer/ProjectsList/ProjectsList.tsx +++ b/packages/uikit-playground/src/Components/HomeContainer/ProjectsList/ProjectsList.tsx @@ -24,7 +24,7 @@ const ProjectsList = () => { id={project.id} name={project.name} date={project.date} - payload={screens[project.screens[0]].payload} + blocks={screens[project.screens[0]].payload.blocks} /> ))} diff --git a/packages/uikit-playground/src/Components/HomeContainer/ProjectsList/ProjectsThumbnail.tsx b/packages/uikit-playground/src/Components/HomeContainer/ProjectsList/ProjectsThumbnail.tsx index 9fe35ebd4cf4..78cc6dc43e9a 100644 --- a/packages/uikit-playground/src/Components/HomeContainer/ProjectsList/ProjectsThumbnail.tsx +++ b/packages/uikit-playground/src/Components/HomeContainer/ProjectsList/ProjectsThumbnail.tsx @@ -22,12 +22,12 @@ const ProjectsThumbnail = ({ id, name: _name, date, - payload, + blocks, }: { id: string; name: string; date: string; - payload: ILayoutBlock[]; + blocks: ILayoutBlock[]; }) => { const [name, setName] = useState(_name); const navigate = useNavigate(); @@ -80,7 +80,7 @@ const ProjectsThumbnail = ({ height="260px" padding="30px" > - + e.stopPropagation()}> { onClick={() => { dispatch( updatePayloadAction({ - payload: [], + blocks: [], changedByEditor: false, }) ); diff --git a/packages/uikit-playground/src/Components/NavBar/RightNavBtn.tsx b/packages/uikit-playground/src/Components/NavBar/RightNavBtn.tsx index 6dc4c2cfb8c4..f032662001e9 100644 --- a/packages/uikit-playground/src/Components/NavBar/RightNavBtn.tsx +++ b/packages/uikit-playground/src/Components/NavBar/RightNavBtn.tsx @@ -6,17 +6,18 @@ import { context, navMenuToggleAction } from '../../Context'; import BurgerIcon from './BurgerIcon'; const RightNavBtn: FC = () => { - const { - state: { isMobile }, - dispatch, - } = useContext(context); + const { state, dispatch } = useContext(context); return ( isMobile && dispatch(navMenuToggleAction(true))} + mie="15px" + onClick={() => state.isMobile && dispatch(navMenuToggleAction(true))} > - {isMobile ? : } + {state.isMobile ? ( + + ) : ( + + )} ); }; diff --git a/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/DeleteElementBtn.tsx b/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/DeleteElementBtn.tsx index fc9fbfa43820..7dafb4982edf 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/DeleteElementBtn.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/DeleteElementBtn.tsx @@ -1,6 +1,5 @@ -/* eslint-disable @typescript-eslint/ban-ts-comment */ import { Icon } from '@rocket.chat/fuselage'; -import React, { useContext } from 'react'; +import { useContext } from 'react'; import { context, updatePayloadAction } from '../../../../Context'; @@ -9,11 +8,10 @@ const Display = ({ elementIndex }: { elementIndex: number }) => { const deleteElement = () => { const { screens, activeScreen } = state; - // @ts-ignore - const payload = [...screens[activeScreen].payload]; - payload.splice(elementIndex, 1); + const blocks = [...screens[activeScreen].payload.blocks]; + blocks.splice(elementIndex, 1); dispatch( - updatePayloadAction({ payload: [...payload], changedByEditor: false }) + updatePayloadAction({ blocks: [...blocks], changedByEditor: false }) ); }; return ( diff --git a/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/RenderPayload.tsx b/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/RenderPayload.tsx index 9a7f5cf78ad2..a4449e75386a 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/RenderPayload.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/RenderPayload/RenderPayload.tsx @@ -9,18 +9,18 @@ import { SurfaceOptions } from '../Surface/constant'; import { ILayoutBlock } from '../../../../Context/initialState'; const RenderPayload = ({ - payload, - surface = 1, + blocks, + surface = SurfaceOptions.Message, }: { index?: number; - payload: ILayoutBlock[]; + blocks: ILayoutBlock[]; surface?: number; }) => ( <> - {SurfaceOptions.Message === surface && uiKitMessage(payload)} - {SurfaceOptions.Banner === surface && uiKitBanner(payload)} - {SurfaceOptions.Modal === surface && uiKitModal(payload)} - {SurfaceOptions.ContextualBar === surface && uiKitContextualBar(payload)} + {SurfaceOptions.Message === surface && uiKitMessage(blocks)} + {SurfaceOptions.Banner === surface && uiKitBanner(blocks)} + {SurfaceOptions.Modal === surface && uiKitModal(blocks)} + {SurfaceOptions.ContextualBar === surface && uiKitContextualBar(blocks)} ); diff --git a/packages/uikit-playground/src/Components/Preview/Display/Surface/Surface.tsx b/packages/uikit-playground/src/Components/Preview/Display/Surface/Surface.tsx index d4c135b37bd5..801062b98bae 100644 --- a/packages/uikit-playground/src/Components/Preview/Display/Surface/Surface.tsx +++ b/packages/uikit-playground/src/Components/Preview/Display/Surface/Surface.tsx @@ -25,7 +25,7 @@ const Surface: FC = () => { block: Block[]; isChangeByDnd: boolean; }>({ - block: screens[activeScreen]?.payload.map((block, i) => ({ + block: screens[activeScreen]?.payload?.blocks?.map((block, i) => ({ id: `${i}`, payload: block, })), @@ -34,26 +34,26 @@ const Surface: FC = () => { const preview = generateActionPreview({ type: 'Action Block', data: {}, - surface: screens[activeScreen]?.surface, - payload: screens[activeScreen]?.payload, + surface: screens[activeScreen]?.payload.surface, + blocks: screens[activeScreen]?.payload.blocks, user: user, }); useEffect(() => { setUniqueBlocks({ - block: screens[activeScreen]?.payload.map((block, i) => ({ + block: screens[activeScreen]?.payload?.blocks?.map((block, i) => ({ id: `${i}`, payload: block, })), isChangeByDnd: false, }); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [screens[activeScreen]?.payload]); + }, [screens[activeScreen]?.payload.blocks]); useEffect(() => { if (uniqueBlocks.isChangeByDnd) { dispatch( updatePayloadAction({ - payload: uniqueBlocks.block.map((block) => block.payload), + blocks: uniqueBlocks.block.map((block) => block.payload), changedByEditor: false, }) ); @@ -89,7 +89,7 @@ const Surface: FC = () => { appId: 'core', }} > - + = ({ +const SplitPlaneContainer: FC<{ PreviewSize: Partial }> = ({ PreviewSize, }) => { const { diff --git a/packages/uikit-playground/src/Components/PrototypeRender/PrototypeRender.tsx b/packages/uikit-playground/src/Components/PrototypeRender/PrototypeRender.tsx index 706bab6cd909..283b3ddd2ab3 100644 --- a/packages/uikit-playground/src/Components/PrototypeRender/PrototypeRender.tsx +++ b/packages/uikit-playground/src/Components/PrototypeRender/PrototypeRender.tsx @@ -9,13 +9,13 @@ import { css } from '@rocket.chat/css-in-js'; import { useRef, useState } from 'react'; const PrototypeRender = ({ - payload, + blocks, surface, flowEdges, activeActions, onSelectAction, }: { - payload: ILayoutBlock[]; + blocks: ILayoutBlock[]; surface: SurfaceOptions; flowEdges: Edge[]; activeActions: idType[]; @@ -41,7 +41,7 @@ const PrototypeRender = ({ return ( - {payload.map((action, id) => ( + {blocks.map((action, id) => ( )} - + ))} diff --git a/packages/uikit-playground/src/Components/PtototypeContainer/PrototypeContainer.tsx b/packages/uikit-playground/src/Components/PtototypeContainer/PrototypeContainer.tsx index 2cddaa055600..1017645ac050 100644 --- a/packages/uikit-playground/src/Components/PtototypeContainer/PrototypeContainer.tsx +++ b/packages/uikit-playground/src/Components/PtototypeContainer/PrototypeContainer.tsx @@ -19,15 +19,16 @@ const PrototypeContainer = () => { if (!projects[activeProject].screens.length) return null; - const { surface, payload } = - screens[currentScreenID] || screens[projects[activeProject].screens[0]]; + const { surface, blocks } = + screens[currentScreenID]?.payload || + screens[projects[activeProject].screens[0]].payload; return ( { return ( { - dispatch(surfaceAction(parseInt(e))); + dispatch(surfaceAction(parseInt(`${e}`))); }} /> ); diff --git a/packages/uikit-playground/src/Context/action/updatePayloadAction.ts b/packages/uikit-playground/src/Context/action/updatePayloadAction.ts index e82d2626e4a9..ab4e219f1936 100644 --- a/packages/uikit-playground/src/Context/action/updatePayloadAction.ts +++ b/packages/uikit-playground/src/Context/action/updatePayloadAction.ts @@ -1,9 +1,11 @@ +import { SurfaceOptions } from '../../Components/Preview/Display/Surface/constant'; import { ILayoutBlock } from '../initialState'; import { ActionTypes } from '../reducer'; type PayloadType = { blocks: ILayoutBlock[]; changedByEditor?: boolean; + surface?: SurfaceOptions; }; export type UpdatePayloadAction = { diff --git a/packages/uikit-playground/src/Context/initialState.ts b/packages/uikit-playground/src/Context/initialState.ts index 5ea29ab9165b..610b45f20414 100644 --- a/packages/uikit-playground/src/Context/initialState.ts +++ b/packages/uikit-playground/src/Context/initialState.ts @@ -114,8 +114,8 @@ export const initialState: initialStateType = { screens: { [initialScreenId]: { payload: { - blocks: [], surface: SurfaceOptions.Message, + blocks: [], }, id: initialScreenId, name: 'Untitled Screen', diff --git a/packages/uikit-playground/src/Context/reducer.ts b/packages/uikit-playground/src/Context/reducer.ts index 42eae4f68c43..af111090f527 100644 --- a/packages/uikit-playground/src/Context/reducer.ts +++ b/packages/uikit-playground/src/Context/reducer.ts @@ -110,6 +110,8 @@ const reducer = (state: initialStateType, action: IAction) => { } case ActionTypes.UpdatePayload: { state.screens[activeScreen].payload.blocks = action?.payload?.blocks; + if (action?.payload?.surface) + state.screens[activeScreen].payload.surface = action?.payload?.surface; state.screens[activeScreen].changedByEditor = action?.payload?.changedByEditor === undefined; state.projects[activeProject].flowEdges = filterEdges( @@ -143,8 +145,8 @@ const reducer = (state: initialStateType, action: IAction) => { id, name: action?.payload || 'Untitled Screen', payload: { - blocks: [], surface: SurfaceOptions.Message, + blocks: [], }, date: getDate(), actionPreview: {}, @@ -248,8 +250,8 @@ const reducer = (state: initialStateType, action: IAction) => { name: 'Untitled Screen', date: getDate(), payload: { - blocks: [], surface: SurfaceOptions.Message, + blocks: [], }, actionPreview: {}, }, @@ -294,6 +296,9 @@ const reducer = (state: initialStateType, action: IAction) => { } case ActionTypes.DeleteProject: { + window.console.log(state.projects[action.payload]?.screens); + const screensIds = state.projects[action.payload]?.screens; + screensIds?.map((id) => delete state.screens[id]); delete state.projects[action.payload]; return { ...state, diff --git a/packages/uikit-playground/src/hooks/useCodeMirror.ts b/packages/uikit-playground/src/hooks/useCodeMirror.ts index d4d67d3b8b20..4622fc262bec 100644 --- a/packages/uikit-playground/src/hooks/useCodeMirror.ts +++ b/packages/uikit-playground/src/hooks/useCodeMirror.ts @@ -3,7 +3,7 @@ import type { Extension } from '@codemirror/state'; import { EditorView } from 'codemirror'; import { useCallback, useEffect, useState, useRef } from 'react'; -type changes = { +export type ICodeMirrorChanges = { value: string; isDispatch: boolean; cursor?: number; @@ -12,7 +12,7 @@ type changes = { export default function useCodeMirror(extensions?: Extension[], doc?: string) { const view = useRef(); const [element, setElement] = useState(); - const [changes, setChanges] = useState({ + const [changes, setChanges] = useState({ value: '[]', isDispatch: true, cursor: 0, diff --git a/packages/uikit-playground/src/hooks/useFormatCodeMirrorValue.ts b/packages/uikit-playground/src/hooks/useFormatCodeMirrorValue.ts new file mode 100644 index 000000000000..e781c8eb94a7 --- /dev/null +++ b/packages/uikit-playground/src/hooks/useFormatCodeMirrorValue.ts @@ -0,0 +1,36 @@ +import { useEffect } from 'react'; +import codePrettier from '../utils/codePrettier'; +import { IPayload } from '../Context/initialState'; +import json5 from 'json5'; +import { ICodeMirrorChanges } from './useCodeMirror'; + +// Todo: needs to make it more strict +function isILayoutblock(obj: object): obj is IPayload { + return obj && typeof obj === 'object' && 'surface' in obj && 'blocks' in obj; +} + +const useFormatCodeMirrorValue = ( + callback: ( + parsedCode: IPayload, + prettierCode: ReturnType + ) => void, + changes: ICodeMirrorChanges +) => { + useEffect(() => { + if (changes?.isDispatch) return; + + try { + const parsedCode = json5.parse(changes.value); + if (!isILayoutblock(parsedCode)) + throw new Error('Please enter a valid LayoutBlock'); + const prettierCode = codePrettier(changes.value, changes.cursor || 0); + callback(parsedCode, prettierCode); + } catch (e) { + // do nothing + } + + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [changes]); +}; + +export default useFormatCodeMirrorValue; From 35c0cba8d21d1f31dfce7c29b966ae6962fa4fe3 Mon Sep 17 00:00:00 2001 From: Vivek Srivastava Date: Mon, 21 Aug 2023 17:34:35 +0530 Subject: [PATCH 41/50] chores(uikit-playground): fix editor on screen change --- .../src/Components/CodeEditor/BlockEditor.tsx | 5 +++++ packages/uikit-playground/src/index.css | 2 ++ 2 files changed, 7 insertions(+) diff --git a/packages/uikit-playground/src/Components/CodeEditor/BlockEditor.tsx b/packages/uikit-playground/src/Components/CodeEditor/BlockEditor.tsx index 2f76faed9e98..15e3f7dcc856 100644 --- a/packages/uikit-playground/src/Components/CodeEditor/BlockEditor.tsx +++ b/packages/uikit-playground/src/Components/CodeEditor/BlockEditor.tsx @@ -1,3 +1,4 @@ +/* eslint-disable react-hooks/exhaustive-deps */ import type { Extension } from '@codemirror/state'; import { Box } from '@rocket.chat/fuselage'; import { useDebouncedValue } from '@rocket.chat/fuselage-hooks'; @@ -53,6 +54,10 @@ const BlockEditor = ({ extensions }: CodeMirrorProps) => { activeScreen, ]); + useEffect(() => { + setValue(intendCode(screens[activeScreen]?.payload), {}); + }, [activeScreen]); + return ( <> diff --git a/packages/uikit-playground/src/index.css b/packages/uikit-playground/src/index.css index d20d4290e40a..a37f1dfde11b 100644 --- a/packages/uikit-playground/src/index.css +++ b/packages/uikit-playground/src/index.css @@ -1,3 +1,5 @@ +@import url('./_global.css'); + body,html { width: 100%; height: 100%; margin: 0; From c9eafb84fe11e863dcbf1d265d4f921a615190ce Mon Sep 17 00:00:00 2001 From: Vivek Srivastava Date: Mon, 21 Aug 2023 17:49:09 +0530 Subject: [PATCH 42/50] chores(uikit-playground): fix build --- .../CodeEditor/Extensions/payloadLinter.ts | 2 +- .../ComponentSideBar/ScrollableSideBar.tsx | 1 - .../Components/ComponentSideBar/SideBar.tsx | 4 +-- .../Components/ComponentSideBar/SliderBtn.tsx | 2 +- .../Draggable/DraggableListItem.tsx | 1 - .../src/Components/DropDown/DropDown.tsx | 2 +- .../src/Components/DropDown/ItemsIcon.tsx | 13 ++++---- .../NavBar/BurgerIcon/BurgerIcon.tsx | 2 +- .../src/Components/NavBar/BurgerIcon/Line.tsx | 15 ++++----- .../Components/NavBar/BurgerIcon/Wrapper.tsx | 33 +++++++++---------- .../src/Components/NavBar/Divider.tsx | 3 +- .../src/Components/NavBar/Logo.tsx | 11 +++---- .../src/Components/NavBar/RightNavBtn.tsx | 2 +- .../Preview/Display/Surface/BannerSurface.tsx | 1 - .../Preview/Display/Surface/ModalSurface.tsx | 1 - .../Preview/Display/Surface/SurfaceRender.tsx | 1 - .../Preview/Editor/ActionBlockEditor.tsx | 3 +- .../Preview/Editor/ActionPreviewEditor.tsx | 3 +- .../Components/Preview/NavPanel/NavPanel.tsx | 2 +- .../src/Components/Preview/Preview.tsx | 4 +-- .../SplitPlaneContainer.tsx | 4 +-- .../src/Components/Preview/Wrapper.tsx | 6 ++-- .../Templates/Container/Container.tsx | 1 - .../Templates/Container/Section.tsx | 1 - .../src/Components/Templates/Templates.tsx | 2 +- .../src/Components/navMenu/Menu/Wrapper.tsx | 17 +++++----- .../src/Pages/SignInSignUp.tsx | 1 - 27 files changed, 61 insertions(+), 77 deletions(-) diff --git a/packages/uikit-playground/src/Components/CodeEditor/Extensions/payloadLinter.ts b/packages/uikit-playground/src/Components/CodeEditor/Extensions/payloadLinter.ts index e6a2b8168998..5eccf262f23f 100644 --- a/packages/uikit-playground/src/Components/CodeEditor/Extensions/payloadLinter.ts +++ b/packages/uikit-playground/src/Components/CodeEditor/Extensions/payloadLinter.ts @@ -55,7 +55,7 @@ const payloadLinter = linter((view: EditorView) => { }); return diagnostics; } - if (head.name === 'ObjectExpression') parsePayload(head, diagnostics, view); + if (head.name === 'ObjectExpression') parsePayload(head, view); head = head.nextSibling; } while (head); diff --git a/packages/uikit-playground/src/Components/ComponentSideBar/ScrollableSideBar.tsx b/packages/uikit-playground/src/Components/ComponentSideBar/ScrollableSideBar.tsx index e614f458f1c9..1d0a1bf318c0 100644 --- a/packages/uikit-playground/src/Components/ComponentSideBar/ScrollableSideBar.tsx +++ b/packages/uikit-playground/src/Components/ComponentSideBar/ScrollableSideBar.tsx @@ -1,7 +1,6 @@ import { css } from '@rocket.chat/css-in-js'; import { Scrollable, Box } from '@rocket.chat/fuselage'; import type { FC } from 'react'; -import React from 'react'; import BlocksTree from '../../Payload/actionBlock/BlocksTree'; import DropDown from '../DropDown'; diff --git a/packages/uikit-playground/src/Components/ComponentSideBar/SideBar.tsx b/packages/uikit-playground/src/Components/ComponentSideBar/SideBar.tsx index ef58fbc732b1..8deae40dffa7 100644 --- a/packages/uikit-playground/src/Components/ComponentSideBar/SideBar.tsx +++ b/packages/uikit-playground/src/Components/ComponentSideBar/SideBar.tsx @@ -1,7 +1,7 @@ import { css } from '@rocket.chat/css-in-js'; import { Box } from '@rocket.chat/fuselage'; import type { FC } from 'react'; -import React, { useEffect, useContext } from 'react'; +import { useEffect, useContext } from 'react'; import { context, sidebarToggleAction } from '../../Context'; import ScrollableSideBar from './ScrollableSideBar'; @@ -33,7 +33,7 @@ const SideBar: FC = () => { height={'100%'} display={'flex'} zIndex={4} - bg='#fff' + bg="#fff" className={[slide]} > diff --git a/packages/uikit-playground/src/Components/ComponentSideBar/SliderBtn.tsx b/packages/uikit-playground/src/Components/ComponentSideBar/SliderBtn.tsx index 52ba6d88d750..6d1e7982bc0c 100644 --- a/packages/uikit-playground/src/Components/ComponentSideBar/SliderBtn.tsx +++ b/packages/uikit-playground/src/Components/ComponentSideBar/SliderBtn.tsx @@ -1,7 +1,7 @@ import { css } from '@rocket.chat/css-in-js'; import { Box, Label } from '@rocket.chat/fuselage'; import type { FC } from 'react'; -import React, { useContext } from 'react'; +import { useContext } from 'react'; import { context, sidebarToggleAction } from '../../Context'; diff --git a/packages/uikit-playground/src/Components/Draggable/DraggableListItem.tsx b/packages/uikit-playground/src/Components/Draggable/DraggableListItem.tsx index a26b2d62deb8..1660ee4b4cb1 100644 --- a/packages/uikit-playground/src/Components/Draggable/DraggableListItem.tsx +++ b/packages/uikit-playground/src/Components/Draggable/DraggableListItem.tsx @@ -1,4 +1,3 @@ -import * as React from 'react'; import { Draggable } from 'react-beautiful-dnd'; import DeleteElementBtn from '../Preview/Display/UiKitElementWrapper/DeleteElementBtn'; diff --git a/packages/uikit-playground/src/Components/DropDown/DropDown.tsx b/packages/uikit-playground/src/Components/DropDown/DropDown.tsx index ff5648b93185..8377a96c8a99 100644 --- a/packages/uikit-playground/src/Components/DropDown/DropDown.tsx +++ b/packages/uikit-playground/src/Components/DropDown/DropDown.tsx @@ -1,5 +1,5 @@ import { Box } from '@rocket.chat/fuselage'; -import React, { Fragment } from 'react'; +import { Fragment } from 'react'; import Items from './Items'; import type { Item, ItemBranch } from './types'; diff --git a/packages/uikit-playground/src/Components/DropDown/ItemsIcon.tsx b/packages/uikit-playground/src/Components/DropDown/ItemsIcon.tsx index 1bd1554c6b84..fb74ae397113 100644 --- a/packages/uikit-playground/src/Components/DropDown/ItemsIcon.tsx +++ b/packages/uikit-playground/src/Components/DropDown/ItemsIcon.tsx @@ -1,25 +1,24 @@ import { Icon } from '@rocket.chat/fuselage'; -import React from 'react'; const ItemsIcon = ({ layer, lastNode, hover, }: { - layer: number, - lastNode: boolean, - hover: boolean, + layer: number; + lastNode: boolean; + hover: boolean; }) => { const selectIcon = (layer: number, hover: boolean) => { if (layer === 1) { return ( - + ); } if (lastNode) { - return ; + return ; } - return ; + return ; }; return <>{selectIcon(layer, hover)}; }; diff --git a/packages/uikit-playground/src/Components/NavBar/BurgerIcon/BurgerIcon.tsx b/packages/uikit-playground/src/Components/NavBar/BurgerIcon/BurgerIcon.tsx index 4c1409153c01..af02130ca4e0 100644 --- a/packages/uikit-playground/src/Components/NavBar/BurgerIcon/BurgerIcon.tsx +++ b/packages/uikit-playground/src/Components/NavBar/BurgerIcon/BurgerIcon.tsx @@ -1,6 +1,6 @@ import { usePrefersReducedMotion } from '@rocket.chat/fuselage-hooks'; import type { ReactElement, ReactNode } from 'react'; -import React, { useContext } from 'react'; +import { useContext } from 'react'; import { context } from '../../../Context'; import Line from './Line'; diff --git a/packages/uikit-playground/src/Components/NavBar/BurgerIcon/Line.tsx b/packages/uikit-playground/src/Components/NavBar/BurgerIcon/Line.tsx index 30c22f53d05b..64eb886b2967 100644 --- a/packages/uikit-playground/src/Components/NavBar/BurgerIcon/Line.tsx +++ b/packages/uikit-playground/src/Components/NavBar/BurgerIcon/Line.tsx @@ -1,14 +1,13 @@ import { css } from '@rocket.chat/css-in-js'; import { Box } from '@rocket.chat/fuselage'; import type { ReactElement } from 'react'; -import React from 'react'; const Line = ({ animated, moved, }: { - animated: boolean, - moved?: boolean, + animated: boolean; + moved?: boolean; }): ReactElement => { const animatedStyle = animated ? css` @@ -40,12 +39,12 @@ const Line = ({ return (