Stability and bug fixes for the react schema view framework.

This commit is contained in:
Aditya Toshniwal 2021-09-01 17:20:37 +05:30 committed by Akshay Joshi
parent 74cec6594e
commit f7b8969c72
5 changed files with 24 additions and 41 deletions

View File

@ -161,12 +161,12 @@ export default class ColumnSchema extends BaseUISchema {
id: 'is_primary_key', label: gettext('Primary key?'),
cell: 'switch', type: 'switch', minWidth: 100, deps:['name'],
visible: ()=>{
return !_.isUndefined(
this.nodeInfo['table'] || this.nodeInfo['view'] ||
this.nodeInfo['mview']
return obj.top?.nodeInfo && _.isUndefined(
obj.top.nodeInfo['table'] || obj.top.nodeInfo['view'] ||
obj.top?.nodeInfo['mview']
);
},
disabled: (state)=>{
readonly: (state)=>{
// Disable it, when one of this:
// - Primary key already exist
// - Table is a partitioned table
@ -208,9 +208,10 @@ export default class ColumnSchema extends BaseUISchema {
// If table is partitioned table then disable
if(
'is_partitioned' in obj.top.origData
obj.top && (
'is_partitioned' in obj.top.origData
&& obj.top.origData['is_partitioned']
&& obj.getServerVersion() < 11000
&& obj.getServerVersion() < 11000)
) {
return false;
}
@ -384,7 +385,7 @@ export default class ColumnSchema extends BaseUISchema {
type: 'switch', minWidth: 80,
group: gettext('Constraints'), editable: this.editableCheckForTable,
deps: ['colconstype'],
disabled: (state) => {
readonly: (state) => {
return obj.inSchemaWithColumnCheck(state);
}, depChange:(state)=>{
if (state.colconstype == 'i') {

View File

@ -158,7 +158,7 @@ export default class VacuumSettingsSchema extends BaseUISchema {
type: 'collection',
fixedRows: this.toastTableVars,
editable: function(state) {
return state.isNew();
return obj.isNew(state);
},
canEdit: false, canAdd: false, canDelete: false, group: gettext('TOAST table'),
schema: this.vacuumToastTableObj,

View File

@ -24,7 +24,7 @@ import _ from 'lodash';
import gettext from 'sources/gettext';
import { SCHEMA_STATE_ACTIONS, StateUtilsContext } from '.';
import FormView from './FormView';
import FormView, { getFieldMetaData } from './FormView';
import { confirmDeleteRow } from '../helpers/legacyConnector';
import CustomPropTypes from 'sources/custom_prop_types';
import { evalFunc } from 'sources/utils';
@ -81,6 +81,7 @@ const useStyles = makeStyles((theme)=>({
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
textAlign: 'center',
},
tableCellHeader: {
fontWeight: theme.typography.fontWeightBold,
@ -335,43 +336,21 @@ export default function DataGridView({
/* Make sure to take the latest field info from schema */
field = _.find(schemaRef.current.fields, (f)=>f.id==field.id) || field;
let {visible, editable, readonly, ..._field} = field;
let {editable} = getFieldMetaData(field, schemaRef.current, row.original || {}, viewHelperProps);
let verInLimit = (_.isUndefined(viewHelperProps.serverInfo) ? true :
((_.isUndefined(field.server_type) ? true :
(viewHelperProps.serverInfo.type in field.server_type)) &&
(_.isUndefined(field.min_version) ? true :
(viewHelperProps.serverInfo.version >= field.min_version)) &&
(_.isUndefined(field.max_version) ? true :
(viewHelperProps.serverInfo.version <= field.max_version))));
let _readonly = viewHelperProps.inCatalog || (viewHelperProps.mode == 'properties');
if(!_readonly) {
_readonly = evalFunc(schemaRef.current, readonly, row.original || {});
}
visible = _.isUndefined(visible) ? true : visible;
let _visible = true;
if(visible) {
_visible = evalFunc(schemaRef.current, visible, row.original || {});
}
_visible = _visible && verInLimit;
editable = _.isUndefined(editable) ? true : editable;
editable = evalFunc(schemaRef.current, editable, row.original || {});
if(_.isUndefined(_field.cell)) {
console.error('cell is required ', _field);
if(_.isUndefined(field.cell)) {
console.error('cell is required ', field);
}
return <MappedCellControl rowIndex={row.index} value={value}
row={row.original} {..._field}
readonly={_readonly}
disabled={!editable}
visible={_visible}
row={row.original} {...field}
readonly={!editable}
disabled={false}
visible={true}
onCellChange={(value)=>{
dataDispatch({
type: SCHEMA_STATE_ACTIONS.SET_VALUE,
path: accessPath.concat([row.index, _field.id]),
path: accessPath.concat([row.index, field.id]),
value: value,
});
}}

View File

@ -81,6 +81,7 @@ export function getFieldMetaData(field, schema, value, viewHelperProps, onlyMode
readonly: false,
disabled: false,
visible: true,
editable: true,
canAdd: true,
canEdit: false,
canDelete: true,
@ -99,7 +100,7 @@ export function getFieldMetaData(field, schema, value, viewHelperProps, onlyMode
return retData;
}
let {visible, disabled, readonly} = field;
let {visible, disabled, readonly, editable} = field;
let verInLimit = (_.isUndefined(viewHelperProps.serverInfo) ? true :
((_.isUndefined(field.server_type) ? true :
@ -120,6 +121,7 @@ export function getFieldMetaData(field, schema, value, viewHelperProps, onlyMode
retData.visible = Boolean(_visible);
retData.disabled = Boolean(evalFunc(schema, disabled, value));
retData.editable = evalFunc(schema, _.isUndefined(editable) ? true : editable, value);
let {canAdd, canEdit, canDelete, canAddRow } = field;
retData.canAdd = _.isUndefined(canAdd) ? retData.canAdd : evalFunc(schema, canAdd, value);

View File

@ -314,6 +314,7 @@ export const InputText = forwardRef(({
};
let finalValue = (_.isNull(value) || _.isUndefined(value)) ? '' : value;
if(controlProps?.formatter) {
finalValue = controlProps.formatter.fromRaw(finalValue);
}
@ -350,7 +351,7 @@ InputText.propTypes = {
readonly: PropTypes.bool,
disabled: PropTypes.bool,
maxlength: PropTypes.number,
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
value: PropTypes.any,
onChange: PropTypes.func,
controlProps: PropTypes.object,
type: PropTypes.string,