diff --git a/packages/web/src/impexp/ScriptWriter.js b/packages/web/src/impexp/ScriptWriter.js index 93640436..cf459d2e 100644 --- a/packages/web/src/impexp/ScriptWriter.js +++ b/packages/web/src/impexp/ScriptWriter.js @@ -21,4 +21,8 @@ export default class ScriptWriter { copyStream(sourceVar, targetVar) { this.put(`await dbgateApi.copyStream(${sourceVar}, ${targetVar});`); } + + comment(s) { + this.put(`// ${s}`); + } } diff --git a/packages/web/src/impexp/createImpExpScript.js b/packages/web/src/impexp/createImpExpScript.js index 2fb2a948..6b8c1d9b 100644 --- a/packages/web/src/impexp/createImpExpScript.js +++ b/packages/web/src/impexp/createImpExpScript.js @@ -108,7 +108,7 @@ function getTargetExpr(sourceName, values, targetConnection, targetDriver) { } } -export default async function createImpExpScript(values) { +export default async function createImpExpScript(values, addEditorInfo = true) { const script = new ScriptWriter(); const [sourceConnection, sourceDriver] = await getConnection( @@ -135,6 +135,10 @@ export default async function createImpExpScript(values) { script.copyStream(sourceVar, targetVar); script.put(); } + if (addEditorInfo) { + script.comment('@ImportExportConfigurator'); + script.comment(JSON.stringify(values)); + } return script.s; } diff --git a/packages/web/src/modals/ImportExportModal.js b/packages/web/src/modals/ImportExportModal.js index d1050e4b..ba7fe450 100644 --- a/packages/web/src/modals/ImportExportModal.js +++ b/packages/web/src/modals/ImportExportModal.js @@ -28,7 +28,7 @@ export default function ImportExportModal({ modalState, initialValues }) { initialScript: code, }, }); - // modalState.close(); + modalState.close(); }; return ( diff --git a/packages/web/src/query/ShellToolbar.js b/packages/web/src/query/ShellToolbar.js index f3a54c61..00177a32 100644 --- a/packages/web/src/query/ShellToolbar.js +++ b/packages/web/src/query/ShellToolbar.js @@ -1,7 +1,7 @@ import React from 'react'; import ToolbarButton from '../widgets/ToolbarButton'; -export default function ShellToolbar({ execute, cancel, busy}) { +export default function ShellToolbar({ execute, cancel, busy, edit, editAvailable }) { return ( <> @@ -10,6 +10,9 @@ export default function ShellToolbar({ execute, cancel, busy}) { Cancel + + Show wizard + ); } diff --git a/packages/web/src/tabs/ShellTab.js b/packages/web/src/tabs/ShellTab.js index 72e6de3a..d4018d96 100644 --- a/packages/web/src/tabs/ShellTab.js +++ b/packages/web/src/tabs/ShellTab.js @@ -21,6 +21,8 @@ import sqlFormatter from 'sql-formatter'; import JavaScriptEditor from '../sqleditor/JavaScriptEditor'; import ShellToolbar from '../query/ShellToolbar'; import RunnerOutputPane from '../query/RunnerOutputPane'; +import useShowModal from '../modals/showModal'; +import ImportExportModal from '../modals/ImportExportModal'; export default function ShellTab({ tabid, @@ -35,6 +37,7 @@ export default function ShellTab({ const [shellText, setShellText] = React.useState(() => localStorage.getItem(localStorageKey) || initialScript || ''); const shellTextRef = React.useRef(shellText); const [busy, setBusy] = React.useState(false); + const showModal = useShowModal(); const saveToStorage = React.useCallback(() => localStorage.setItem(localStorageKey, shellTextRef.current), [ localStorageKey, @@ -119,6 +122,17 @@ export default function ShellTab({ } }; + const configRegex = /\s*\/\/\s*@ImportExportConfigurator\s*\n\s*\/\/\s*(\{[^\n]+\})\n/; + + const handleEdit = () => { + const jsonTextMatch = shellText.match(configRegex); + if (jsonTextMatch) { + showModal((modalState) => ( + + )); + } + }; + return ( <> @@ -129,13 +143,19 @@ export default function ShellTab({ onKeyDown={handleKeyDown} editorRef={editorRef} /> - + {toolbarPortalRef && toolbarPortalRef.current && tabVisible && ReactDOM.createPortal( - , + , toolbarPortalRef.current )}