mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-10 08:04:36 -06:00
- Focus on first tab and first element on reset. - Move formErr to state context.
This commit is contained in:
parent
ae49b556ce
commit
d62fba024b
@ -237,7 +237,7 @@ DataGridHeader.propTypes = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function DataGridView({
|
export default function DataGridView({
|
||||||
value, viewHelperProps, formErr, schema, accessPath, dataDispatch, containerClassName,
|
value, viewHelperProps, schema, accessPath, dataDispatch, containerClassName,
|
||||||
fixedRows, ...props}) {
|
fixedRows, ...props}) {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const stateUtils = useContext(StateUtilsContext);
|
const stateUtils = useContext(StateUtilsContext);
|
||||||
@ -473,7 +473,7 @@ export default function DataGridView({
|
|||||||
<DataTableRow row={row} totalRows={rows.length} isResizing={isResizing}
|
<DataTableRow row={row} totalRows={rows.length} isResizing={isResizing}
|
||||||
schema={schemaRef.current} schemaRef={schemaRef} accessPath={accessPath.concat([row.index])} />
|
schema={schemaRef.current} schemaRef={schemaRef} accessPath={accessPath.concat([row.index])} />
|
||||||
{props.canEdit && row.isExpanded &&
|
{props.canEdit && row.isExpanded &&
|
||||||
<FormView value={row.original} viewHelperProps={viewHelperProps} formErr={formErr} dataDispatch={dataDispatch}
|
<FormView value={row.original} viewHelperProps={viewHelperProps} dataDispatch={dataDispatch}
|
||||||
schema={schemaRef.current} accessPath={accessPath.concat([row.index])} isNested={true} className={classes.expandedForm}
|
schema={schemaRef.current} accessPath={accessPath.concat([row.index])} isNested={true} className={classes.expandedForm}
|
||||||
isDataGridForm={true}/>
|
isDataGridForm={true}/>
|
||||||
}
|
}
|
||||||
@ -490,7 +490,6 @@ DataGridView.propTypes = {
|
|||||||
label: PropTypes.string,
|
label: PropTypes.string,
|
||||||
value: PropTypes.array,
|
value: PropTypes.array,
|
||||||
viewHelperProps: PropTypes.object,
|
viewHelperProps: PropTypes.object,
|
||||||
formErr: PropTypes.object,
|
|
||||||
schema: CustomPropTypes.schemaUI,
|
schema: CustomPropTypes.schemaUI,
|
||||||
accessPath: PropTypes.array.isRequired,
|
accessPath: PropTypes.array.isRequired,
|
||||||
dataDispatch: PropTypes.func,
|
dataDispatch: PropTypes.func,
|
||||||
|
@ -12,7 +12,7 @@ import _ from 'lodash';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import { MappedFormControl } from './MappedControl';
|
import { MappedFormControl } from './MappedControl';
|
||||||
import { SCHEMA_STATE_ACTIONS } from '.';
|
import { SCHEMA_STATE_ACTIONS, StateUtilsContext } from '.';
|
||||||
import { evalFunc } from 'sources/utils';
|
import { evalFunc } from 'sources/utils';
|
||||||
import CustomPropTypes from '../custom_prop_types';
|
import CustomPropTypes from '../custom_prop_types';
|
||||||
import { DepListenerContext } from './DepListener';
|
import { DepListenerContext } from './DepListener';
|
||||||
@ -20,8 +20,9 @@ import { getFieldMetaData } from './FormView';
|
|||||||
import FieldSet from '../components/FieldSet';
|
import FieldSet from '../components/FieldSet';
|
||||||
|
|
||||||
export default function FieldSetView({
|
export default function FieldSetView({
|
||||||
value, formErr, schema={}, viewHelperProps, accessPath, dataDispatch, controlClassName, isDataGridForm=false, label, visible}) {
|
value, schema={}, viewHelperProps, accessPath, dataDispatch, controlClassName, isDataGridForm=false, label, visible}) {
|
||||||
const depListener = useContext(DepListenerContext);
|
const depListener = useContext(DepListenerContext);
|
||||||
|
const stateUtils = useContext(StateUtilsContext);
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
/* Calculate the fields which depends on the current field */
|
/* Calculate the fields which depends on the current field */
|
||||||
@ -52,7 +53,7 @@ export default function FieldSetView({
|
|||||||
|
|
||||||
if(modeSupported) {
|
if(modeSupported) {
|
||||||
/* Its a form control */
|
/* Its a form control */
|
||||||
const hasError = field.id == formErr.name;
|
const hasError = field.id == stateUtils?.formErr.name;
|
||||||
/* When there is a change, the dependent values can change
|
/* When there is a change, the dependent values can change
|
||||||
* lets pass the new changes to dependent and get the new values
|
* lets pass the new changes to dependent and get the new values
|
||||||
* from there as well.
|
* from there as well.
|
||||||
@ -104,7 +105,6 @@ export default function FieldSetView({
|
|||||||
|
|
||||||
FieldSetView.propTypes = {
|
FieldSetView.propTypes = {
|
||||||
value: PropTypes.any,
|
value: PropTypes.any,
|
||||||
formErr: PropTypes.object,
|
|
||||||
schema: CustomPropTypes.schemaUI.isRequired,
|
schema: CustomPropTypes.schemaUI.isRequired,
|
||||||
viewHelperProps: PropTypes.object,
|
viewHelperProps: PropTypes.object,
|
||||||
isDataGridForm: PropTypes.bool,
|
isDataGridForm: PropTypes.bool,
|
||||||
|
@ -16,7 +16,7 @@ import clsx from 'clsx';
|
|||||||
import { MappedFormControl } from './MappedControl';
|
import { MappedFormControl } from './MappedControl';
|
||||||
import TabPanel from '../components/TabPanel';
|
import TabPanel from '../components/TabPanel';
|
||||||
import DataGridView from './DataGridView';
|
import DataGridView from './DataGridView';
|
||||||
import { SCHEMA_STATE_ACTIONS } from '.';
|
import { SCHEMA_STATE_ACTIONS, StateUtilsContext } from '.';
|
||||||
import { InputSQL } from '../components/FormComponents';
|
import { InputSQL } from '../components/FormComponents';
|
||||||
import gettext from 'sources/gettext';
|
import gettext from 'sources/gettext';
|
||||||
import { evalFunc } from 'sources/utils';
|
import { evalFunc } from 'sources/utils';
|
||||||
@ -131,7 +131,7 @@ export function getFieldMetaData(field, schema, value, viewHelperProps, onlyMode
|
|||||||
|
|
||||||
/* The first component of schema view form */
|
/* The first component of schema view form */
|
||||||
export default function FormView({
|
export default function FormView({
|
||||||
value, formErr, schema={}, viewHelperProps, isNested=false, accessPath, dataDispatch, hasSQLTab,
|
value, schema={}, viewHelperProps, isNested=false, accessPath, dataDispatch, hasSQLTab,
|
||||||
getSQLValue, onTabChange, firstEleRef, className, isDataGridForm=false, isTabView=true, visible}) {
|
getSQLValue, onTabChange, firstEleRef, className, isDataGridForm=false, isTabView=true, visible}) {
|
||||||
let defaultTab = 'General';
|
let defaultTab = 'General';
|
||||||
let tabs = {};
|
let tabs = {};
|
||||||
@ -144,6 +144,7 @@ export default function FormView({
|
|||||||
const depListener = useContext(DepListenerContext);
|
const depListener = useContext(DepListenerContext);
|
||||||
let groupLabels = {};
|
let groupLabels = {};
|
||||||
const schemaRef = useRef(schema);
|
const schemaRef = useRef(schema);
|
||||||
|
const stateUtils = useContext(StateUtilsContext);
|
||||||
|
|
||||||
let isOnScreen = useOnScreen(formRef);
|
let isOnScreen = useOnScreen(formRef);
|
||||||
if(isOnScreen) {
|
if(isOnScreen) {
|
||||||
@ -182,6 +183,11 @@ export default function FormView({
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
/* Upon reset, set the tab to first */
|
||||||
|
useEffect(()=>{
|
||||||
|
setTabValue(0);
|
||||||
|
}, [stateUtils.formResetKey]);
|
||||||
|
|
||||||
let fullTabs = [];
|
let fullTabs = [];
|
||||||
|
|
||||||
/* Prepare the array of components based on the types */
|
/* Prepare the array of components based on the types */
|
||||||
@ -204,7 +210,7 @@ export default function FormView({
|
|||||||
field.schema.top = schema;
|
field.schema.top = schema;
|
||||||
}
|
}
|
||||||
tabs[group].push(
|
tabs[group].push(
|
||||||
<FormView key={`nested${tabs[group].length}`} value={value} viewHelperProps={viewHelperProps} formErr={formErr}
|
<FormView key={`nested${tabs[group].length}`} value={value} viewHelperProps={viewHelperProps}
|
||||||
schema={field.schema} accessPath={accessPath} dataDispatch={dataDispatch} isNested={true} isDataGridForm={isDataGridForm}
|
schema={field.schema} accessPath={accessPath} dataDispatch={dataDispatch} isNested={true} isDataGridForm={isDataGridForm}
|
||||||
{...field} visible={visible}/>
|
{...field} visible={visible}/>
|
||||||
);
|
);
|
||||||
@ -216,7 +222,7 @@ export default function FormView({
|
|||||||
field.schema.top = schema;
|
field.schema.top = schema;
|
||||||
}
|
}
|
||||||
tabs[group].push(
|
tabs[group].push(
|
||||||
<FieldSetView key={`nested${tabs[group].length}`} value={value} viewHelperProps={viewHelperProps} formErr={formErr}
|
<FieldSetView key={`nested${tabs[group].length}`} value={value} viewHelperProps={viewHelperProps}
|
||||||
schema={field.schema} accessPath={accessPath} dataDispatch={dataDispatch} isNested={true} isDataGridForm={isDataGridForm}
|
schema={field.schema} accessPath={accessPath} dataDispatch={dataDispatch} isNested={true} isDataGridForm={isDataGridForm}
|
||||||
controlClassName={classes.controlRow}
|
controlClassName={classes.controlRow}
|
||||||
{...field} visible={visible}/>
|
{...field} visible={visible}/>
|
||||||
@ -239,7 +245,7 @@ export default function FormView({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const props = {
|
const props = {
|
||||||
key: field.id, value: value[field.id], viewHelperProps: viewHelperProps, formErr: formErr,
|
key: field.id, value: value[field.id], viewHelperProps: viewHelperProps,
|
||||||
schema: field.schema, accessPath: accessPath.concat(field.id), dataDispatch: dataDispatch,
|
schema: field.schema, accessPath: accessPath.concat(field.id), dataDispatch: dataDispatch,
|
||||||
containerClassName: classes.controlRow, ...field, canAdd: canAdd, canEdit: canEdit, canDelete: canDelete,
|
containerClassName: classes.controlRow, ...field, canAdd: canAdd, canEdit: canEdit, canDelete: canDelete,
|
||||||
visible: visible, canAddRow: canAddRow,
|
visible: visible, canAddRow: canAddRow,
|
||||||
@ -257,7 +263,7 @@ export default function FormView({
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Its a form control */
|
/* Its a form control */
|
||||||
const hasError = _.isEqual(accessPath.concat(field.id), formErr.name);
|
const hasError = _.isEqual(accessPath.concat(field.id), stateUtils.formErr.name);
|
||||||
/* When there is a change, the dependent values can change
|
/* When there is a change, the dependent values can change
|
||||||
* lets pass the new changes to dependent and get the new values
|
* lets pass the new changes to dependent and get the new values
|
||||||
* from there as well.
|
* from there as well.
|
||||||
@ -311,13 +317,15 @@ export default function FormView({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let finalTabs = _.pickBy(tabs, (v, tabName)=>schemaRef.current.filterGroups.indexOf(tabName) <= -1);
|
||||||
|
|
||||||
/* Add the SQL tab if required */
|
/* Add the SQL tab if required */
|
||||||
let sqlTabActive = false;
|
let sqlTabActive = false;
|
||||||
let sqlTabName = gettext('SQL');
|
let sqlTabName = gettext('SQL');
|
||||||
if(hasSQLTab) {
|
if(hasSQLTab) {
|
||||||
sqlTabActive = (Object.keys(tabs).length === tabValue);
|
sqlTabActive = (Object.keys(finalTabs).length === tabValue);
|
||||||
/* Re-render and fetch the SQL tab when it is active */
|
/* Re-render and fetch the SQL tab when it is active */
|
||||||
tabs[sqlTabName] = [
|
finalTabs[sqlTabName] = [
|
||||||
useMemo(()=><SQLTab key="sqltab" active={sqlTabActive} getSQLValue={getSQLValue} />, [sqlTabActive, value]),
|
useMemo(()=><SQLTab key="sqltab" active={sqlTabActive} getSQLValue={getSQLValue} />, [sqlTabActive, value]),
|
||||||
];
|
];
|
||||||
tabsClassname[sqlTabName] = classes.fullSpace;
|
tabsClassname[sqlTabName] = classes.fullSpace;
|
||||||
@ -337,7 +345,6 @@ export default function FormView({
|
|||||||
return <></>;
|
return <></>;
|
||||||
}
|
}
|
||||||
|
|
||||||
let finalTabs = _.pickBy(tabs, (v, tabName)=>schemaRef.current.filterGroups.indexOf(tabName) <= -1);
|
|
||||||
if(isTabView) {
|
if(isTabView) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -384,7 +391,6 @@ export default function FormView({
|
|||||||
|
|
||||||
FormView.propTypes = {
|
FormView.propTypes = {
|
||||||
value: PropTypes.any,
|
value: PropTypes.any,
|
||||||
formErr: PropTypes.object,
|
|
||||||
schema: CustomPropTypes.schemaUI.isRequired,
|
schema: CustomPropTypes.schemaUI.isRequired,
|
||||||
viewHelperProps: PropTypes.object,
|
viewHelperProps: PropTypes.object,
|
||||||
isNested: PropTypes.bool,
|
isNested: PropTypes.bool,
|
||||||
|
@ -408,6 +408,7 @@ function SchemaDialogView({
|
|||||||
const [loaderText, setLoaderText] = useState('');
|
const [loaderText, setLoaderText] = useState('');
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [formReady, setFormReady] = useState(false);
|
const [formReady, setFormReady] = useState(false);
|
||||||
|
const [formResetKey, setFormResetKey] = useState(0);
|
||||||
const firstEleRef = useRef();
|
const firstEleRef = useRef();
|
||||||
const isNew = schema.isNew(schema.origData);
|
const isNew = schema.isNew(schema.origData);
|
||||||
|
|
||||||
@ -512,6 +513,8 @@ function SchemaDialogView({
|
|||||||
|
|
||||||
const onResetClick = ()=>{
|
const onResetClick = ()=>{
|
||||||
const resetIt = ()=>{
|
const resetIt = ()=>{
|
||||||
|
firstEleRef.current && firstEleRef.current.focus();
|
||||||
|
setFormResetKey((prev)=>prev+1);
|
||||||
sessDispatch({
|
sessDispatch({
|
||||||
type: SCHEMA_STATE_ACTIONS.INIT,
|
type: SCHEMA_STATE_ACTIONS.INIT,
|
||||||
payload: schema.origData,
|
payload: schema.origData,
|
||||||
@ -638,8 +641,10 @@ function SchemaDialogView({
|
|||||||
value: data,
|
value: data,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}), []);
|
formResetKey: formResetKey,
|
||||||
|
formErr: formErr,
|
||||||
|
}), [formResetKey, formErr]);
|
||||||
|
|
||||||
/* I am Groot */
|
/* I am Groot */
|
||||||
return (
|
return (
|
||||||
@ -648,7 +653,7 @@ function SchemaDialogView({
|
|||||||
<Box className={classes.root}>
|
<Box className={classes.root}>
|
||||||
<Box className={classes.form}>
|
<Box className={classes.form}>
|
||||||
<Loader message={loaderText}/>
|
<Loader message={loaderText}/>
|
||||||
<FormView value={sessData} viewHelperProps={viewHelperProps} formErr={formErr}
|
<FormView value={sessData} viewHelperProps={viewHelperProps}
|
||||||
schema={schema} accessPath={[]} dataDispatch={sessDispatchWithListener}
|
schema={schema} accessPath={[]} dataDispatch={sessDispatchWithListener}
|
||||||
hasSQLTab={props.hasSQL} getSQLValue={getSQLValue} firstEleRef={firstEleRef} isTabView={isTabView} />
|
hasSQLTab={props.hasSQL} getSQLValue={getSQLValue} firstEleRef={firstEleRef} isTabView={isTabView} />
|
||||||
<FormFooterMessage type={MESSAGE_TYPE.ERROR} message={formErr.message}
|
<FormFooterMessage type={MESSAGE_TYPE.ERROR} message={formErr.message}
|
||||||
@ -783,7 +788,6 @@ function SchemaPropertiesView({
|
|||||||
viewHelperProps={viewHelperProps}
|
viewHelperProps={viewHelperProps}
|
||||||
schema={field.schema}
|
schema={field.schema}
|
||||||
accessPath={[]}
|
accessPath={[]}
|
||||||
formErr={{}}
|
|
||||||
controlClassName={classes.controlRow}
|
controlClassName={classes.controlRow}
|
||||||
{...field}
|
{...field}
|
||||||
visible={visible}
|
visible={visible}
|
||||||
|
Loading…
Reference in New Issue
Block a user