mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 13:53:59 +00:00
better connection dialog
This commit is contained in:
@@ -76,7 +76,7 @@ const connectionAppObject = (flags) => (
|
|||||||
if (openedConnections.includes(_id)) {
|
if (openedConnections.includes(_id)) {
|
||||||
if (!status) statusIcon = 'icon loading';
|
if (!status) statusIcon = 'icon loading';
|
||||||
else if (status.name == 'pending') statusIcon = 'icon loading';
|
else if (status.name == 'pending') statusIcon = 'icon loading';
|
||||||
else if (status.name == 'ok') statusIcon = 'img green-ok';
|
else if (status.name == 'ok') statusIcon = 'img ok';
|
||||||
else statusIcon = 'img error';
|
else statusIcon = 'img error';
|
||||||
if (status && status.name == 'error') {
|
if (status && status.name == 'error') {
|
||||||
statusTitle = status.message;
|
statusTitle = status.message;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ const iconNames = {
|
|||||||
'icon chevron-down': 'mdi mdi-chevron-down',
|
'icon chevron-down': 'mdi mdi-chevron-down',
|
||||||
'icon plugin': 'mdi mdi-toy-brick',
|
'icon plugin': 'mdi mdi-toy-brick',
|
||||||
|
|
||||||
'img green-ok': 'mdi mdi-check-circle color-green-8',
|
'img ok': 'mdi mdi-check-circle color-green-8',
|
||||||
'img alert': 'mdi mdi-alert-circle color-blue-6',
|
'img alert': 'mdi mdi-alert-circle color-blue-6',
|
||||||
'img error': 'mdi mdi-close-circle color-red-7',
|
'img error': 'mdi mdi-close-circle color-red-7',
|
||||||
// 'img statusbar-ok': 'mdi mdi-check-circle color-on-statusbar-green',
|
// 'img statusbar-ok': 'mdi mdi-check-circle color-on-statusbar-green',
|
||||||
|
|||||||
@@ -8,22 +8,34 @@ import ModalHeader from './ModalHeader';
|
|||||||
import ModalFooter from './ModalFooter';
|
import ModalFooter from './ModalFooter';
|
||||||
import ModalContent from './ModalContent';
|
import ModalContent from './ModalContent';
|
||||||
import useExtensions from '../utility/useExtensions';
|
import useExtensions from '../utility/useExtensions';
|
||||||
|
import LoadingInfo from '../widgets/LoadingInfo';
|
||||||
|
import { FontIcon } from '../icons';
|
||||||
// import FormikForm from '../utility/FormikForm';
|
// import FormikForm from '../utility/FormikForm';
|
||||||
|
|
||||||
export default function ConnectionModal({ modalState, connection = undefined }) {
|
export default function ConnectionModal({ modalState, connection = undefined }) {
|
||||||
const [sqlConnectResult, setSqlConnectResult] = React.useState('Not connected');
|
const [sqlConnectResult, setSqlConnectResult] = React.useState(null);
|
||||||
const extensions = useExtensions();
|
const extensions = useExtensions();
|
||||||
|
const [isTesting, setIsTesting] = React.useState(false);
|
||||||
|
const testIdRef = React.useRef(0);
|
||||||
|
|
||||||
const handleTest = async (values) => {
|
const handleTest = async (values) => {
|
||||||
|
setIsTesting(true);
|
||||||
|
testIdRef.current += 1;
|
||||||
|
const testid = testIdRef.current;
|
||||||
const resp = await axios.post('connections/test', values);
|
const resp = await axios.post('connections/test', values);
|
||||||
const { error, version } = resp.data;
|
if (testIdRef.current != testid) return;
|
||||||
|
|
||||||
setSqlConnectResult(error || version);
|
setIsTesting(false);
|
||||||
|
setSqlConnectResult(resp.data);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCancel = async () => {
|
||||||
|
testIdRef.current += 1; // invalidate current test
|
||||||
|
setIsTesting(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = async (values) => {
|
const handleSubmit = async (values) => {
|
||||||
const resp = await axios.post('connections/save', values);
|
axios.post('connections/save', values);
|
||||||
|
|
||||||
modalState.close();
|
modalState.close();
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
@@ -46,13 +58,28 @@ export default function ConnectionModal({ modalState, connection = undefined })
|
|||||||
<FormTextField label="Server" name="server" />
|
<FormTextField label="Server" name="server" />
|
||||||
<FormTextField label="Port" name="port" />
|
<FormTextField label="Port" name="port" />
|
||||||
<FormTextField label="User" name="user" />
|
<FormTextField label="User" name="user" />
|
||||||
<FormTextField label="Password" name="password" />
|
<FormTextField label="Password" name="password" type="password" />
|
||||||
<FormTextField label="Display name" name="displayName" />
|
<FormTextField label="Display name" name="displayName" />
|
||||||
<div>Connect result: {sqlConnectResult}</div>
|
{!isTesting && sqlConnectResult && sqlConnectResult.msgtype == 'connected' && (
|
||||||
|
<div>
|
||||||
|
Connected: <FontIcon icon="img ok" /> {sqlConnectResult.version}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{!isTesting && sqlConnectResult && sqlConnectResult.msgtype == 'error' && (
|
||||||
|
<div>
|
||||||
|
Connect failed: <FontIcon icon="img error" /> {sqlConnectResult.error}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{isTesting && <LoadingInfo message="Testing connection" />}
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
|
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
|
{isTesting ? (
|
||||||
|
<FormButton text="Cancel" onClick={handleCancel} />
|
||||||
|
) : (
|
||||||
<FormButton text="Test" onClick={handleTest} />
|
<FormButton text="Test" onClick={handleTest} />
|
||||||
|
)}
|
||||||
|
|
||||||
<FormSubmit text="Save" />
|
<FormSubmit text="Save" />
|
||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
</Form>
|
</Form>
|
||||||
|
|||||||
Reference in New Issue
Block a user