mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2024-11-22 08:46:39 -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:
parent
48a5143485
commit
dc8ab7cd2a
@ -457,7 +457,7 @@ export default class TriggerSchema extends BaseUISchema {
|
|||||||
type: 'sql', mode: ['create', 'edit'], deps: ['tfunction'],
|
type: 'sql', mode: ['create', 'edit'], deps: ['tfunction'],
|
||||||
isFullTab: true,
|
isFullTab: true,
|
||||||
visible: true,
|
visible: true,
|
||||||
readonly: (state) => {
|
disabled: (state) => {
|
||||||
// We will enable it only when EDB PPAS and trigger function is
|
// We will enable it only when EDB PPAS and trigger function is
|
||||||
// set to Inline EDB-SPL
|
// set to Inline EDB-SPL
|
||||||
var tfunction = state.tfunction,
|
var tfunction = state.tfunction,
|
||||||
|
@ -165,7 +165,7 @@ export function getNodeView(nodeType, treeNodeInfo, actionType, itemNodeData, fo
|
|||||||
const viewHelperProps = {
|
const viewHelperProps = {
|
||||||
mode: actionType,
|
mode: actionType,
|
||||||
serverInfo: serverInfo ? {
|
serverInfo: serverInfo ? {
|
||||||
type: serverInfo.type,
|
type: serverInfo.server_type,
|
||||||
version: serverInfo.version,
|
version: serverInfo.version,
|
||||||
}: undefined,
|
}: undefined,
|
||||||
inCatalog: inCatalog,
|
inCatalog: inCatalog,
|
||||||
|
@ -130,6 +130,10 @@ function getChangedData(topSchema, viewHelperProps, sessData, stringify=false) {
|
|||||||
if(stringify && (_.isArray(change) || _.isObject(change))) {
|
if(stringify && (_.isArray(change) || _.isObject(change))) {
|
||||||
change = JSON.stringify(change);
|
change = JSON.stringify(change);
|
||||||
}
|
}
|
||||||
|
/* Null values are not passed in URL params, pass it as an empty string */
|
||||||
|
if(_.isNull(change)) {
|
||||||
|
change = '';
|
||||||
|
}
|
||||||
return levelChanges[id] = change;
|
return levelChanges[id] = change;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -30,6 +30,11 @@ basicSettings = createMuiTheme(basicSettings, {
|
|||||||
shape: {
|
shape: {
|
||||||
borderRadius: 4,
|
borderRadius: 4,
|
||||||
},
|
},
|
||||||
|
palette: {
|
||||||
|
action: {
|
||||||
|
disabledOpacity: 0.32,
|
||||||
|
}
|
||||||
|
},
|
||||||
overrides: {
|
overrides: {
|
||||||
MuiTabs: {
|
MuiTabs: {
|
||||||
root: {
|
root: {
|
||||||
@ -196,6 +201,9 @@ basicSettings = createMuiTheme(basicSettings, {
|
|||||||
},
|
},
|
||||||
MuiTab: {
|
MuiTab: {
|
||||||
textColor: 'inherit',
|
textColor: 'inherit',
|
||||||
|
},
|
||||||
|
MuiCheckbox: {
|
||||||
|
disableTouchRipple: true,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -272,6 +280,9 @@ function getFinalTheme(baseTheme) {
|
|||||||
MuiIconButton: {
|
MuiIconButton: {
|
||||||
root: {
|
root: {
|
||||||
color: baseTheme.palette.text.primary,
|
color: baseTheme.palette.text.primary,
|
||||||
|
'&$disabled': {
|
||||||
|
color: 'abc',
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
MuiAccordion: {
|
MuiAccordion: {
|
||||||
@ -291,16 +302,33 @@ function getFinalTheme(baseTheme) {
|
|||||||
height: 28,
|
height: 28,
|
||||||
padding: '7px 12px',
|
padding: '7px 12px',
|
||||||
},
|
},
|
||||||
|
colorPrimary: {
|
||||||
|
'&$disabled': {
|
||||||
|
color: 'abc',
|
||||||
|
}
|
||||||
|
},
|
||||||
switchBase: {
|
switchBase: {
|
||||||
padding: baseTheme.spacing(0.5),
|
padding: baseTheme.spacing(0.5),
|
||||||
|
'&$disabled': {
|
||||||
|
color: 'abc',
|
||||||
|
'& + .MuiSwitch-track': {
|
||||||
|
opacity: baseTheme.palette.action.disabledOpacity,
|
||||||
|
}
|
||||||
|
},
|
||||||
'&.Mui-checked': {
|
'&.Mui-checked': {
|
||||||
color: baseTheme.palette.success.main,
|
color: baseTheme.palette.success.main,
|
||||||
transform: 'translateX(24px)',
|
transform: 'translateX(24px)',
|
||||||
|
'& .MuiSwitch-thumb': {
|
||||||
|
border: 0
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'&.Mui-checked + .MuiSwitch-track': {
|
'&.Mui-checked + .MuiSwitch-track': {
|
||||||
backgroundColor: baseTheme.palette.success.light,
|
backgroundColor: baseTheme.palette.success.light,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
thumb: {
|
||||||
|
border: '1px solid ' + baseTheme.otherVars.inputBorderColor
|
||||||
|
}
|
||||||
},
|
},
|
||||||
MuiCheckbox: {
|
MuiCheckbox: {
|
||||||
root: {
|
root: {
|
||||||
|
@ -14,7 +14,7 @@ import PropTypes from 'prop-types';
|
|||||||
import CustomPropTypes from '../custom_prop_types';
|
import CustomPropTypes from '../custom_prop_types';
|
||||||
|
|
||||||
/* React wrapper for CodeMirror */
|
/* 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 taRef = useRef();
|
||||||
const editor = useRef();
|
const editor = useRef();
|
||||||
const cmWrapper = 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(() => {
|
useMemo(() => {
|
||||||
if(editor.current) {
|
if(editor.current) {
|
||||||
if(value != editor.current.getValue()) {
|
if(value != editor.current.getValue()) {
|
||||||
@ -68,5 +86,7 @@ CodeMirror.propTypes = {
|
|||||||
options: PropTypes.object,
|
options: PropTypes.object,
|
||||||
change: PropTypes.func,
|
change: PropTypes.func,
|
||||||
events: PropTypes.object,
|
events: PropTypes.object,
|
||||||
|
readonly: PropTypes.bool,
|
||||||
|
disabled: PropTypes.bool,
|
||||||
className: CustomPropTypes.className,
|
className: CustomPropTypes.className,
|
||||||
};
|
};
|
||||||
|
@ -76,6 +76,12 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
display: 'flex',
|
display: 'flex',
|
||||||
backgroundColor: theme.otherVars.borderColor,
|
backgroundColor: theme.otherVars.borderColor,
|
||||||
padding: theme.spacing(1),
|
padding: theme.spacing(1),
|
||||||
|
},
|
||||||
|
readOnlySwitch: {
|
||||||
|
opacity: 0.75,
|
||||||
|
'& .MuiSwitch-track': {
|
||||||
|
opacity: theme.palette.action.disabledOpacity,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -139,16 +145,10 @@ FormInput.propTypes = {
|
|||||||
testcid: PropTypes.any,
|
testcid: PropTypes.any,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function InputSQL({value, options, onChange, readonly, className, ...props}) {
|
export function InputSQL({value, options, onChange, className, ...props}) {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const editor = useRef();
|
const editor = useRef();
|
||||||
|
|
||||||
useEffect(()=>{
|
|
||||||
if(editor.current) {
|
|
||||||
editor.current.setOption('readOnly', readonly);
|
|
||||||
}
|
|
||||||
}, [readonly]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CodeMirror
|
<CodeMirror
|
||||||
currEditor={(obj)=>editor.current=obj}
|
currEditor={(obj)=>editor.current=obj}
|
||||||
@ -413,6 +413,7 @@ FormInputFileSelect.propTypes = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function InputSwitch({cid, helpid, value, onChange, readonly, controlProps, ...props}) {
|
export function InputSwitch({cid, helpid, value, onChange, readonly, controlProps, ...props}) {
|
||||||
|
const classes = useStyles();
|
||||||
return (
|
return (
|
||||||
<Switch color="primary"
|
<Switch color="primary"
|
||||||
checked={Boolean(value)}
|
checked={Boolean(value)}
|
||||||
@ -425,6 +426,7 @@ export function InputSwitch({cid, helpid, value, onChange, readonly, controlProp
|
|||||||
}}
|
}}
|
||||||
{...controlProps}
|
{...controlProps}
|
||||||
{...props}
|
{...props}
|
||||||
|
className={(readonly || props.disabled) ? classes.readOnlySwitch : null}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -434,6 +436,7 @@ InputSwitch.propTypes = {
|
|||||||
value: PropTypes.any,
|
value: PropTypes.any,
|
||||||
onChange: PropTypes.func,
|
onChange: PropTypes.func,
|
||||||
readonly: PropTypes.bool,
|
readonly: PropTypes.bool,
|
||||||
|
disabled: PropTypes.bool,
|
||||||
controlProps: PropTypes.object,
|
controlProps: PropTypes.object,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,7 +19,16 @@ describe('CodeMirror', ()=>{
|
|||||||
let cmInstance, options={
|
let cmInstance, options={
|
||||||
lineNumbers: true,
|
lineNumbers: true,
|
||||||
mode: 'text/x-pgsql',
|
mode: 'text/x-pgsql',
|
||||||
}, cmObj = jasmine.createSpyObj('cmObj', {'getValue':()=>'', 'setValue': ()=>{}, 'refresh': ()=>{}});
|
},
|
||||||
|
cmObj = jasmine.createSpyObj('cmObj', {
|
||||||
|
'getValue':()=>'',
|
||||||
|
'setValue': ()=>{},
|
||||||
|
'refresh': ()=>{},
|
||||||
|
'setOption': ()=>{},
|
||||||
|
'removeKeyMap': ()=>{},
|
||||||
|
'addKeyMap': ()=>{},
|
||||||
|
'getWrapperElement': document.createElement('div'),
|
||||||
|
});
|
||||||
beforeEach(()=>{
|
beforeEach(()=>{
|
||||||
jasmineEnzyme();
|
jasmineEnzyme();
|
||||||
spyOn(OrigCodeMirror, 'fromTextArea').and.returnValue(cmObj);
|
spyOn(OrigCodeMirror, 'fromTextArea').and.returnValue(cmObj);
|
||||||
|
Loading…
Reference in New Issue
Block a user