diff --git a/packages/web/src/modals/ConfirmSqlModal.js b/packages/web/src/modals/ConfirmSqlModal.js index 195ca01c6..97695ec59 100644 --- a/packages/web/src/modals/ConfirmSqlModal.js +++ b/packages/web/src/modals/ConfirmSqlModal.js @@ -1,12 +1,14 @@ import React from 'react'; import axios from '../utility/axios'; import ModalBase from './ModalBase'; -import { FormRow, FormButton, FormTextField, FormSelectField, FormSubmit } from '../utility/forms'; +import { FormRow, FormButtonRow, FormTextField, FormSelectField, FormSubmit } from '../utility/forms'; +import FormStyledButton from '../widgets/FormStyledButton'; import { TextField } from '../utility/inputs'; import { Formik, Form } from 'formik'; import SqlEditor from '../sqleditor/SqlEditor'; // import FormikForm from '../utility/FormikForm'; import styled from 'styled-components'; +import keycodes from '../utility/keycodes'; const SqlWrapper = styled.div` position: relative; @@ -15,24 +17,30 @@ const SqlWrapper = styled.div` `; export default function ConfirmSqlModal({ modalState, sql, engine, onConfirm }) { + const handleKeyDown = (data, hash, keyString, keyCode, event) => { + if (keyCode == keycodes.enter) { + event.preventDefault(); + modalState.close(); + onConfirm(); + } + }; return (

Save changes

- + - - + { modalState.close(); onConfirm(); }} /> - - + +
); } diff --git a/packages/web/src/modals/ConnectionModal.js b/packages/web/src/modals/ConnectionModal.js index af16e0a45..827d87477 100644 --- a/packages/web/src/modals/ConnectionModal.js +++ b/packages/web/src/modals/ConnectionModal.js @@ -1,7 +1,7 @@ import React from 'react'; import axios from '../utility/axios'; import ModalBase from './ModalBase'; -import { FormRow, FormButton, FormTextField, FormSelectField, FormSubmit } from '../utility/forms'; +import { FormButtonRow, FormButton, FormTextField, FormSelectField, FormSubmit } from '../utility/forms'; import { TextField } from '../utility/inputs'; import { Formik, Form } from 'formik'; // import FormikForm from '../utility/FormikForm'; @@ -37,10 +37,10 @@ export default function ConnectionModal({ modalState, connection = undefined }) - + - +
Connect result: {sqlConnectResult}
diff --git a/packages/web/src/modals/ModalBase.js b/packages/web/src/modals/ModalBase.js index dad9d4b89..00f3b09fb 100644 --- a/packages/web/src/modals/ModalBase.js +++ b/packages/web/src/modals/ModalBase.js @@ -27,6 +27,7 @@ const StyledModal = styled(Modal)` padding: 20px; width: 50%; + max-width: 900px; margin: auto; margin-top: 15vh; `; diff --git a/packages/web/src/modals/SaveSqlFileModal.js b/packages/web/src/modals/SaveSqlFileModal.js index ca24f4d46..af23a5195 100644 --- a/packages/web/src/modals/SaveSqlFileModal.js +++ b/packages/web/src/modals/SaveSqlFileModal.js @@ -1,7 +1,7 @@ import React from 'react'; import axios from '../utility/axios'; import ModalBase from './ModalBase'; -import { FormRow, FormButton, FormTextField, FormSelectField, FormSubmit } from '../utility/forms'; +import { FormButtonRow, FormButton, FormTextField, FormSelectField, FormSubmit } from '../utility/forms'; import { TextField } from '../utility/inputs'; import { Formik, Form } from 'formik'; import { useSetSavedSqlFiles } from '../utility/globalState'; @@ -28,9 +28,9 @@ export default function SaveSqlFileModal({ storageKey, modalState, name, onSave
- + - + diff --git a/packages/web/src/sqleditor/SqlEditor.js b/packages/web/src/sqleditor/SqlEditor.js index 881681760..cd7ffb8a0 100644 --- a/packages/web/src/sqleditor/SqlEditor.js +++ b/packages/web/src/sqleditor/SqlEditor.js @@ -25,6 +25,7 @@ export default function SqlEditor({ tabVisible = false, onKeyDown = undefined, editorRef = undefined, + focusOnCreate = false, }) { const [containerRef, { height, width }] = useDimensions(); const ownEditorRef = React.useRef(null); @@ -32,8 +33,9 @@ export default function SqlEditor({ const currentEditorRef = editorRef || ownEditorRef; React.useEffect(() => { - if (tabVisible && currentEditorRef.current && currentEditorRef.current.editor) currentEditorRef.current.editor.focus(); - }, [tabVisible]); + if ((tabVisible || focusOnCreate) && currentEditorRef.current && currentEditorRef.current.editor) + currentEditorRef.current.editor.focus(); + }, [tabVisible, focusOnCreate]); React.useEffect(() => { if (onKeyDown && currentEditorRef.current) { diff --git a/packages/web/src/utility/forms.js b/packages/web/src/utility/forms.js index 5c5da280e..555c225f8 100644 --- a/packages/web/src/utility/forms.js +++ b/packages/web/src/utility/forms.js @@ -2,12 +2,19 @@ import React from 'react'; import styled from 'styled-components'; import { TextField, SelectField } from './inputs'; import { Field, useFormikContext } from 'formik'; +import FormStyledButton from '../widgets/FormStyledButton'; export const FormRow = styled.div` display: flex; margin: 10px; `; +export const FormButtonRow = styled.div` + display: flex; + // justify-content: flex-end; + margin: 10px; +`; + export const FormLabel = styled.div` width: 10vw; font-weight: bold; @@ -40,10 +47,10 @@ export function FormSelectField({ label, children, ...other }) { } export function FormSubmit({ text }) { - return ; + return ; } export function FormButton({ text, onClick, ...other }) { const { values } = useFormikContext(); - return onClick(values)} {...other} />; + return onClick(values)} {...other} />; } diff --git a/packages/web/src/widgets/FormStyledButton.js b/packages/web/src/widgets/FormStyledButton.js new file mode 100644 index 000000000..8c4a30a6b --- /dev/null +++ b/packages/web/src/widgets/FormStyledButton.js @@ -0,0 +1,61 @@ +// @ts-nocheck +import React from 'react'; +import styled from 'styled-components'; +import theme from '../theme'; + +const ButtonInput = styled.input` + // height: ${theme.toolBar.height - 5}px; + border: 1px solid #2e6da4; + padding: 5px; + margin: 2px; + width: 100px; + //background-color: #777; + background-color: #337ab7; + // border-color: #2e6da4; + color: white; + border-radius: 2px; + + ${(props) => + !props.disabled && + ` + &:hover { + background-color: #286090; + } + + &:active:hover { + background-color: #204d74; + } + `} + + ${(props) => + props.disabled && + ` + background-color: #ccc; + color: gray; + `} + +`; + +export default function FormStyledButton({ + onClick = undefined, + type = 'button', + value, + disabled = undefined, + ...other +}) { + return ( + { + if (!disabled && onClick) onClick(); + } + : undefined + } + disabled={disabled} + value={value} + {...other} + /> + ); +}