mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 23:45:59 +00:00
sql code formatter
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
"react-scripts": "3.3.0",
|
||||
"resize-observer-polyfill": "^1.5.1",
|
||||
"socket.io-client": "^2.3.0",
|
||||
"sql-formatter": "^2.3.3",
|
||||
"styled-components": "^4.4.1",
|
||||
"uuid": "^3.4.0"
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import ToolbarButton from '../widgets/ToolbarButton';
|
||||
|
||||
export default function QueryToolbar({ execute, cancel, isDatabaseDefined, busy, save }) {
|
||||
export default function QueryToolbar({ execute, cancel, isDatabaseDefined, busy, save, format }) {
|
||||
return (
|
||||
<>
|
||||
<ToolbarButton disabled={!isDatabaseDefined || busy} onClick={execute} icon="fas fa-play">
|
||||
@@ -13,6 +13,9 @@ export default function QueryToolbar({ execute, cancel, isDatabaseDefined, busy,
|
||||
<ToolbarButton onClick={save} icon="fas fa-save">
|
||||
Save
|
||||
</ToolbarButton>
|
||||
<ToolbarButton onClick={format} icon="fas fa-code">
|
||||
Format
|
||||
</ToolbarButton>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import { changeTab } from '../utility/common';
|
||||
import useSocket from '../utility/SocketProvider';
|
||||
import SaveSqlFileModal from '../modals/SaveSqlFileModal';
|
||||
import useModalState from '../modals/useModalState';
|
||||
import sqlFormatter from 'sql-formatter';
|
||||
|
||||
export default function QueryTab({ tabid, conid, database, tabVisible, toolbarPortalRef, initialScript, storageKey }) {
|
||||
const localStorageKey = storageKey || `sql_${tabid}`;
|
||||
@@ -121,6 +122,11 @@ export default function QueryTab({ tabid, conid, database, tabVisible, toolbarPo
|
||||
}
|
||||
};
|
||||
|
||||
const handleFormatCode = () => {
|
||||
editorRef.current.editor.setValue(sqlFormatter.format(editorRef.current.editor.getValue()));
|
||||
editorRef.current.editor.clearSelection();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<VerticalSplitter>
|
||||
@@ -151,6 +157,7 @@ export default function QueryTab({ tabid, conid, database, tabVisible, toolbarPo
|
||||
execute={handleExecute}
|
||||
busy={busy}
|
||||
cancel={handleCancel}
|
||||
format={handleFormatCode}
|
||||
save={saveSqlFileModalState.open}
|
||||
/>,
|
||||
toolbarPortalRef.current
|
||||
|
||||
@@ -7115,7 +7115,7 @@ lodash.uniq@^4.5.0:
|
||||
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
|
||||
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=
|
||||
|
||||
"lodash@>=3.5 <5", lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.5:
|
||||
"lodash@>=3.5 <5", lodash@^4.16.0, lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.5:
|
||||
version "4.17.15"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
|
||||
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
|
||||
@@ -10584,6 +10584,13 @@ sprintf-js@~1.0.2:
|
||||
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
|
||||
integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=
|
||||
|
||||
sql-formatter@^2.3.3:
|
||||
version "2.3.3"
|
||||
resolved "https://registry.yarnpkg.com/sql-formatter/-/sql-formatter-2.3.3.tgz#910ef484fbb988a5e510bea4161157e3b80b2f62"
|
||||
integrity sha512-m6pqVXwsm9GkCHC/+gdPvNowI7PNoVTT6OZMWKwXJoP2MvfntfhcfyliIf4/QX6t+DirSJ6XDSiSS70YvZ87Lw==
|
||||
dependencies:
|
||||
lodash "^4.16.0"
|
||||
|
||||
sqlstring@2.3.1:
|
||||
version "2.3.1"
|
||||
resolved "https://registry.yarnpkg.com/sqlstring/-/sqlstring-2.3.1.tgz#475393ff9e91479aea62dcaf0ca3d14983a7fb40"
|
||||
|
||||
Reference in New Issue
Block a user