1. Make Unlogged switch in table as read only.

2. Fix a console warning when saving node data.

Fixes #6778
pull/61/head
Aditya Toshniwal 2021-09-28 17:48:09 +05:30 committed by Akshay Joshi
parent 787a441343
commit 08706ba6b2
4 changed files with 23 additions and 9 deletions

View File

@ -708,7 +708,7 @@ export default class TableSchema extends BaseUISchema {
},{
id: 'relpersistence', label: gettext('Unlogged?'), cell: 'switch',
type: 'switch', mode: ['properties', 'create', 'edit'],
disabled: obj.inSchemaWithModelCheck,
readonly: obj.inSchemaWithModelCheck,
group: 'advanced',
},{
id: 'conname', label: gettext('Primary key'), cell: 'text',

View File

@ -36,6 +36,7 @@ import { parseApiError } from '../api_instance';
import DepListener, {DepListenerContext} from './DepListener';
import FieldSetView from './FieldSetView';
import DataGridView from './DataGridView';
import { useIsMounted } from '../custom_hooks';
const useDialogStyles = makeStyles((theme)=>({
root: {
@ -451,6 +452,7 @@ function SchemaDialogView({
const [formResetKey, setFormResetKey] = useState(0);
const firstEleRef = useRef();
const isNew = schema.isNew(schema.origData);
const checkIsMounted = useIsMounted();
const depListenerObj = useRef(new DepListener());
/* The session data */
@ -538,7 +540,7 @@ function SchemaDialogView({
setLoaderText('');
}
/* Clear the focus timeout it unmounted */
/* Clear the focus timeout if unmounted */
return ()=>clearTimeout(focusTimeout);
}, []);
@ -625,8 +627,10 @@ function SchemaDialogView({
message: parseApiError(err),
});
}).finally(()=>{
setSaving(false);
setLoaderText('');
if(checkIsMounted()) {
setSaving(false);
setLoaderText('');
}
});
};
@ -787,20 +791,18 @@ function SchemaPropertiesView({
let groupLabels = {};
const [origData, setOrigData] = useState({});
const [loaderText, setLoaderText] = useState('');
const checkIsMounted = useIsMounted();
useEffect(()=>{
let unmounted = false;
setLoaderText('Loading...');
getInitData().then((data)=>{
data = data || {};
schema.initialise(data);
if(!unmounted) {
if(checkIsMounted()) {
setOrigData(data || {});
setLoaderText('');
}
});
return ()=>unmounted=true;
}, [getInitData]);
let fullTabs = [];

View File

@ -305,6 +305,9 @@ function getFinalTheme(baseTheme) {
colorPrimary: {
'&$disabled': {
color: 'abc',
'& + .MuiSwitch-track': {
backgroundColor: 'abc',
}
}
},
switchBase: {

View File

@ -1,4 +1,4 @@
import {useRef, useEffect, useState} from 'react';
import {useRef, useEffect, useState, useCallback} from 'react';
/* React hook for setInterval */
export function useInterval(callback, delay) {
@ -57,3 +57,12 @@ export function useOnScreen(ref) {
return isIntersecting;
}
export function useIsMounted() {
const ref = useRef(true);
useEffect(() => {
return () => {
ref.current = false;
};
}, []);
return useCallback(() => ref.current, []);
}