mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
load wizard from shell window
This commit is contained in:
parent
8425fc46a7
commit
694e76b654
@ -21,4 +21,8 @@ export default class ScriptWriter {
|
||||
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 [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;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ export default function ImportExportModal({ modalState, initialValues }) {
|
||||
initialScript: code,
|
||||
},
|
||||
});
|
||||
// modalState.close();
|
||||
modalState.close();
|
||||
};
|
||||
return (
|
||||
<ModalBase modalState={modalState}>
|
||||
|
@ -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 (
|
||||
<>
|
||||
<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">
|
||||
Cancel
|
||||
</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 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) => (
|
||||
<ImportExportModal modalState={modalState} initialValues={JSON.parse(jsonTextMatch[1])} />
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<VerticalSplitter>
|
||||
@ -129,13 +143,19 @@ export default function ShellTab({
|
||||
onKeyDown={handleKeyDown}
|
||||
editorRef={editorRef}
|
||||
/>
|
||||
<RunnerOutputPane runnerId={runnerId} executeNumber={executeNumber}/>
|
||||
<RunnerOutputPane runnerId={runnerId} executeNumber={executeNumber} />
|
||||
</VerticalSplitter>
|
||||
{toolbarPortalRef &&
|
||||
toolbarPortalRef.current &&
|
||||
tabVisible &&
|
||||
ReactDOM.createPortal(
|
||||
<ShellToolbar execute={handleExecute} busy={busy} cancel={handleCancel} />,
|
||||
<ShellToolbar
|
||||
execute={handleExecute}
|
||||
busy={busy}
|
||||
cancel={handleCancel}
|
||||
edit={handleEdit}
|
||||
editAvailable={configRegex.test(shellText || '')}
|
||||
/>,
|
||||
toolbarPortalRef.current
|
||||
)}
|
||||
</>
|
||||
|
Loading…
Reference in New Issue
Block a user