mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 11:03:57 +00:00
submit action - run with enter
This commit is contained in:
@@ -12,10 +12,19 @@ export default function ChangeDownloadUrlModal({ modalState, url = '', onConfirm
|
|||||||
// React.useEffect(() => {
|
// React.useEffect(() => {
|
||||||
// if (textFieldRef.current) textFieldRef.current.focus();
|
// if (textFieldRef.current) textFieldRef.current.focus();
|
||||||
// }, [textFieldRef.current]);
|
// }, [textFieldRef.current]);
|
||||||
const handleSubmit = async (values) => {
|
|
||||||
|
// const handleSubmit = () => async (values) => {
|
||||||
|
// onConfirm(values.url);
|
||||||
|
// modalState.close();
|
||||||
|
// };
|
||||||
|
|
||||||
|
const handleSubmit = React.useCallback(
|
||||||
|
async (values) => {
|
||||||
onConfirm(values.url);
|
onConfirm(values.url);
|
||||||
modalState.close();
|
modalState.close();
|
||||||
};
|
},
|
||||||
|
[modalState, onConfirm]
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<ModalBase modalState={modalState}>
|
<ModalBase modalState={modalState}>
|
||||||
<ModalHeader modalState={modalState}>Download imported file from web</ModalHeader>
|
<ModalHeader modalState={modalState}>Download imported file from web</ModalHeader>
|
||||||
|
|||||||
@@ -3,14 +3,17 @@ import ModalBase from './ModalBase';
|
|||||||
import FormStyledButton from '../widgets/FormStyledButton';
|
import FormStyledButton from '../widgets/FormStyledButton';
|
||||||
import ModalFooter from './ModalFooter';
|
import ModalFooter from './ModalFooter';
|
||||||
import ModalContent from './ModalContent';
|
import ModalContent from './ModalContent';
|
||||||
|
import { FormSubmit } from '../utility/forms';
|
||||||
|
import { FormProvider } from '../utility/FormProvider';
|
||||||
|
|
||||||
export default function ConfirmModal({ message, modalState, onConfirm }) {
|
export default function ConfirmModal({ message, modalState, onConfirm }) {
|
||||||
return (
|
return (
|
||||||
|
<FormProvider>
|
||||||
<ModalBase modalState={modalState}>
|
<ModalBase modalState={modalState}>
|
||||||
<ModalContent>{message}</ModalContent>
|
<ModalContent>{message}</ModalContent>
|
||||||
|
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<FormStyledButton
|
<FormSubmit
|
||||||
value="OK"
|
value="OK"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
modalState.close();
|
modalState.close();
|
||||||
@@ -20,5 +23,6 @@ export default function ConfirmModal({ message, modalState, onConfirm }) {
|
|||||||
<FormStyledButton type="button" value="Close" onClick={modalState.close} />
|
<FormStyledButton type="button" value="Close" onClick={modalState.close} />
|
||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
</ModalBase>
|
</ModalBase>
|
||||||
|
</FormProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ export default function ModalBase({ modalState, children, isFlex = false, fullSc
|
|||||||
overlayClassName="RactModalOverlay"
|
overlayClassName="RactModalOverlay"
|
||||||
fullScreen={fullScreen}
|
fullScreen={fullScreen}
|
||||||
isFlex={isFlex}
|
isFlex={isFlex}
|
||||||
|
ariaHideApp={false}
|
||||||
// style={{
|
// style={{
|
||||||
// overlay: {
|
// overlay: {
|
||||||
// backgroundColor: '#000',
|
// backgroundColor: '#000',
|
||||||
|
|||||||
@@ -1,9 +1,26 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import keycodes from './keycodes';
|
||||||
|
|
||||||
const FormContext = React.createContext(null);
|
const FormContext = React.createContext(null);
|
||||||
|
|
||||||
export function FormProvider({ children, initialValues }) {
|
export function FormProvider({ children, initialValues = {} }) {
|
||||||
const [values, setValues] = React.useState(initialValues);
|
const [values, setValues] = React.useState(initialValues);
|
||||||
|
const [submitAction, setSubmitAction] = React.useState(null);
|
||||||
|
const handleEnter = React.useCallback(
|
||||||
|
(e) => {
|
||||||
|
if (e.keyCode == keycodes.enter && submitAction && submitAction.action) {
|
||||||
|
e.preventDefault();
|
||||||
|
submitAction.action(values);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[submitAction, values]
|
||||||
|
);
|
||||||
|
React.useEffect(() => {
|
||||||
|
document.addEventListener('keyup', handleEnter);
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('keyup', handleEnter);
|
||||||
|
};
|
||||||
|
}, [handleEnter]);
|
||||||
const setFieldValue = React.useCallback(
|
const setFieldValue = React.useCallback(
|
||||||
(field, value) =>
|
(field, value) =>
|
||||||
setValues((v) => ({
|
setValues((v) => ({
|
||||||
@@ -16,6 +33,7 @@ export function FormProvider({ children, initialValues }) {
|
|||||||
values,
|
values,
|
||||||
setValues,
|
setValues,
|
||||||
setFieldValue,
|
setFieldValue,
|
||||||
|
setSubmitAction,
|
||||||
};
|
};
|
||||||
return <FormContext.Provider value={provider}>{children}</FormContext.Provider>;
|
return <FormContext.Provider value={provider}>{children}</FormContext.Provider>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,7 +106,10 @@ export function FormSelectField({ label, name, children = null, ...other }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function FormSubmit({ onClick, value, ...other }) {
|
export function FormSubmit({ onClick, value, ...other }) {
|
||||||
const { values } = useForm();
|
const { values, setSubmitAction } = useForm();
|
||||||
|
React.useEffect(() => {
|
||||||
|
setSubmitAction({ action: onClick });
|
||||||
|
}, [onClick]);
|
||||||
return <FormStyledButton type="submit" value={value} onClick={() => onClick(values)} {...other} />;
|
return <FormStyledButton type="submit" value={value} onClick={() => onClick(values)} {...other} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,9 @@ function ConnectionList() {
|
|||||||
|
|
||||||
<WidgetsInnerContainer>
|
<WidgetsInnerContainer>
|
||||||
<AppObjectList
|
<AppObjectList
|
||||||
list={connectionsWithStatus}
|
list={_.sortBy(connectionsWithStatus, ({ displayName, server }) =>
|
||||||
|
(displayName || server || '').toUpperCase()
|
||||||
|
)}
|
||||||
AppObjectComponent={ConnectionAppObject}
|
AppObjectComponent={ConnectionAppObject}
|
||||||
// makeAppObj={connectionAppObject({ boldCurrentDatabase: true })}
|
// makeAppObj={connectionAppObject({ boldCurrentDatabase: true })}
|
||||||
SubItems={SubDatabaseList}
|
SubItems={SubDatabaseList}
|
||||||
|
|||||||
Reference in New Issue
Block a user