mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 03:53:57 +00:00
load wizard from shell window
This commit is contained in:
@@ -21,4 +21,8 @@ export default class ScriptWriter {
|
|||||||
copyStream(sourceVar, targetVar) {
|
copyStream(sourceVar, targetVar) {
|
||||||
this.put(`await dbgateApi.copyStream(${sourceVar}, ${targetVar});`);
|
this.put(`await dbgateApi.copyStream(${sourceVar}, ${targetVar});`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
comment(s) {
|
||||||
|
this.put(`// ${s}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 script = new ScriptWriter();
|
||||||
|
|
||||||
const [sourceConnection, sourceDriver] = await getConnection(
|
const [sourceConnection, sourceDriver] = await getConnection(
|
||||||
@@ -135,6 +135,10 @@ export default async function createImpExpScript(values) {
|
|||||||
script.copyStream(sourceVar, targetVar);
|
script.copyStream(sourceVar, targetVar);
|
||||||
script.put();
|
script.put();
|
||||||
}
|
}
|
||||||
|
if (addEditorInfo) {
|
||||||
|
script.comment('@ImportExportConfigurator');
|
||||||
|
script.comment(JSON.stringify(values));
|
||||||
|
}
|
||||||
return script.s;
|
return script.s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export default function ImportExportModal({ modalState, initialValues }) {
|
|||||||
initialScript: code,
|
initialScript: code,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
// modalState.close();
|
modalState.close();
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<ModalBase modalState={modalState}>
|
<ModalBase modalState={modalState}>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ToolbarButton from '../widgets/ToolbarButton';
|
import ToolbarButton from '../widgets/ToolbarButton';
|
||||||
|
|
||||||
export default function ShellToolbar({ execute, cancel, busy}) {
|
export default function ShellToolbar({ execute, cancel, busy, edit, editAvailable }) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ToolbarButton disabled={busy} onClick={execute} icon="fas fa-play">
|
<ToolbarButton disabled={busy} onClick={execute} icon="fas fa-play">
|
||||||
@@ -10,6 +10,9 @@ export default function ShellToolbar({ execute, cancel, busy}) {
|
|||||||
<ToolbarButton disabled={!busy} onClick={cancel} icon="fas fa-times">
|
<ToolbarButton disabled={!busy} onClick={cancel} icon="fas fa-times">
|
||||||
Cancel
|
Cancel
|
||||||
</ToolbarButton>
|
</ToolbarButton>
|
||||||
|
<ToolbarButton disabled={!editAvailable} onClick={edit} icon="fas fa-edit">
|
||||||
|
Show wizard
|
||||||
|
</ToolbarButton>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import sqlFormatter from 'sql-formatter';
|
|||||||
import JavaScriptEditor from '../sqleditor/JavaScriptEditor';
|
import JavaScriptEditor from '../sqleditor/JavaScriptEditor';
|
||||||
import ShellToolbar from '../query/ShellToolbar';
|
import ShellToolbar from '../query/ShellToolbar';
|
||||||
import RunnerOutputPane from '../query/RunnerOutputPane';
|
import RunnerOutputPane from '../query/RunnerOutputPane';
|
||||||
|
import useShowModal from '../modals/showModal';
|
||||||
|
import ImportExportModal from '../modals/ImportExportModal';
|
||||||
|
|
||||||
export default function ShellTab({
|
export default function ShellTab({
|
||||||
tabid,
|
tabid,
|
||||||
@@ -35,6 +37,7 @@ export default function ShellTab({
|
|||||||
const [shellText, setShellText] = React.useState(() => localStorage.getItem(localStorageKey) || initialScript || '');
|
const [shellText, setShellText] = React.useState(() => localStorage.getItem(localStorageKey) || initialScript || '');
|
||||||
const shellTextRef = React.useRef(shellText);
|
const shellTextRef = React.useRef(shellText);
|
||||||
const [busy, setBusy] = React.useState(false);
|
const [busy, setBusy] = React.useState(false);
|
||||||
|
const showModal = useShowModal();
|
||||||
|
|
||||||
const saveToStorage = React.useCallback(() => localStorage.setItem(localStorageKey, shellTextRef.current), [
|
const saveToStorage = React.useCallback(() => localStorage.setItem(localStorageKey, shellTextRef.current), [
|
||||||
localStorageKey,
|
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) => (
|
||||||
|
<ImportExportModal modalState={modalState} initialValues={JSON.parse(jsonTextMatch[1])} />
|
||||||
|
));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<VerticalSplitter>
|
<VerticalSplitter>
|
||||||
@@ -129,13 +143,19 @@ export default function ShellTab({
|
|||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
editorRef={editorRef}
|
editorRef={editorRef}
|
||||||
/>
|
/>
|
||||||
<RunnerOutputPane runnerId={runnerId} executeNumber={executeNumber}/>
|
<RunnerOutputPane runnerId={runnerId} executeNumber={executeNumber} />
|
||||||
</VerticalSplitter>
|
</VerticalSplitter>
|
||||||
{toolbarPortalRef &&
|
{toolbarPortalRef &&
|
||||||
toolbarPortalRef.current &&
|
toolbarPortalRef.current &&
|
||||||
tabVisible &&
|
tabVisible &&
|
||||||
ReactDOM.createPortal(
|
ReactDOM.createPortal(
|
||||||
<ShellToolbar execute={handleExecute} busy={busy} cancel={handleCancel} />,
|
<ShellToolbar
|
||||||
|
execute={handleExecute}
|
||||||
|
busy={busy}
|
||||||
|
cancel={handleCancel}
|
||||||
|
edit={handleEdit}
|
||||||
|
editAvailable={configRegex.test(shellText || '')}
|
||||||
|
/>,
|
||||||
toolbarPortalRef.current
|
toolbarPortalRef.current
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in New Issue
Block a user