From 537c423e06fe10429af0faa26bddcaeb324e0e05 Mon Sep 17 00:00:00 2001 From: arpitnath Date: Wed, 9 Aug 2023 19:32:38 +0530 Subject: [PATCH] fixes: copy/paste --- frontend/src/Editor/EditorKeyHooks.jsx | 2 ++ frontend/src/_helpers/appUtils.js | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/frontend/src/Editor/EditorKeyHooks.jsx b/frontend/src/Editor/EditorKeyHooks.jsx index 1f9b6cb797..df79bf779b 100644 --- a/frontend/src/Editor/EditorKeyHooks.jsx +++ b/frontend/src/Editor/EditorKeyHooks.jsx @@ -10,6 +10,7 @@ export const EditorKeyHooks = ({ removeMultipleComponents, }) => { const handleHotKeysCallback = (key) => { + console.log('---arpit-- hotkeys', { key }); switch (key) { case 'Escape': handleEditorEscapeKeyPress(); @@ -18,6 +19,7 @@ export const EditorKeyHooks = ({ removeMultipleComponents(); break; case 'KeyD': + console.log('---arpit-- paste component'); cloneComponents(); break; case 'KeyC': diff --git a/frontend/src/_helpers/appUtils.js b/frontend/src/_helpers/appUtils.js index c3c21b7cd5..75faf228c4 100644 --- a/frontend/src/_helpers/appUtils.js +++ b/frontend/src/_helpers/appUtils.js @@ -575,7 +575,7 @@ function executeActionWithDebounce(_ref, event, mode, customVariables) { } case 'switch-page': { - _ref.switchPage(event.pageId, resolveReferences(event.queryParams, getCurrentState(), [], customVariables)); // arpit [switchPage] + _ref.switchPage(event.pageId, resolveReferences(event.queryParams, getCurrentState(), [], customVariables)); return Promise.resolve(); } } @@ -601,7 +601,7 @@ export async function onEvent(_ref, eventName, options, mode = 'edit') { }, }, }); - runQuery(_ref, queryId, queryName, true, mode, parameters); //arpit [runQuery] + runQuery(_ref, queryId, queryName, true, mode, parameters); } if (eventName === 'onCalendarEventSelect') { @@ -1314,7 +1314,8 @@ const updateNewComponents = (pageId, appDefinition, newComponents, updateAppDefi ); newAppDefinition.pages[pageId].components[newComponent.id] = newComponent; }); - updateAppDefinition(newAppDefinition, { addComponents: true }); + + updateAppDefinition(newAppDefinition, { componentDefinitionChanged: true }); }; export const cloneComponents = ( @@ -1352,13 +1353,13 @@ export const cloneComponents = ( isCut, }; } + if (isCloning) { addComponents(currentPageId, appDefinition, updateAppDefinition, undefined, newComponentObj); toast.success('Component cloned succesfully'); } else if (isCut) { navigator.clipboard.writeText(JSON.stringify(newComponentObj)); - removeSelectedComponent(currentPageId, newDefinition, selectedComponents); - updateAppDefinition(newDefinition); + removeSelectedComponent(currentPageId, newDefinition, selectedComponents, updateAppDefinition); } else { navigator.clipboard.writeText(JSON.stringify(newComponentObj)); toast.success('Component copied succesfully'); @@ -1430,7 +1431,6 @@ const updateComponentLayout = (components, parentId, isCut = false) => { }; export const addComponents = (pageId, appDefinition, appDefinitionChanged, parentId = undefined, newComponentObj) => { - console.log({ pageId, newComponentObj }); const finalComponents = []; let parentComponent = undefined; const { isCloning, isCut, newComponents: pastedComponent = [] } = newComponentObj;