mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
1. Switch control and CodeMirror control UI improvements for read-only and disabled states.
2. If a form input value changes to null, pass it as an empty string in URL params. 3. Use server_type instead of type from the server info.
This commit is contained in:
committed by
Akshay Joshi
parent
48a5143485
commit
dc8ab7cd2a
@@ -14,7 +14,7 @@ import PropTypes from 'prop-types';
|
||||
import CustomPropTypes from '../custom_prop_types';
|
||||
|
||||
/* React wrapper for CodeMirror */
|
||||
export default function CodeMirror({currEditor, name, value, options, events, className}) {
|
||||
export default function CodeMirror({currEditor, name, value, options, events, readonly, disabled, className}) {
|
||||
const taRef = useRef();
|
||||
const editor = useRef();
|
||||
const cmWrapper = useRef();
|
||||
@@ -40,6 +40,24 @@ export default function CodeMirror({currEditor, name, value, options, events, cl
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(()=>{
|
||||
if(editor.current) {
|
||||
if(disabled) {
|
||||
cmWrapper.current.classList.add('cm_disabled');
|
||||
editor.current.setOption('readOnly', 'nocursor');
|
||||
} else if(readonly) {
|
||||
cmWrapper.current.classList.add('cm_disabled');
|
||||
editor.current.addKeyMap({'Tab': false});
|
||||
editor.current.addKeyMap({'Shift-Tab': false});
|
||||
} else {
|
||||
cmWrapper.current.classList.remove('cm_disabled');
|
||||
editor.current.setOption('readOnly', false);
|
||||
editor.current.removeKeyMap('Tab');
|
||||
editor.current.removeKeyMap('Shift-Tab');
|
||||
}
|
||||
}
|
||||
}, [readonly, disabled]);
|
||||
|
||||
useMemo(() => {
|
||||
if(editor.current) {
|
||||
if(value != editor.current.getValue()) {
|
||||
@@ -68,5 +86,7 @@ CodeMirror.propTypes = {
|
||||
options: PropTypes.object,
|
||||
change: PropTypes.func,
|
||||
events: PropTypes.object,
|
||||
readonly: PropTypes.bool,
|
||||
disabled: PropTypes.bool,
|
||||
className: CustomPropTypes.className,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user