From 08706ba6b278d22b8ca01d72d07152eb9f8c598c Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Tue, 28 Sep 2021 17:48:09 +0530 Subject: [PATCH] 1. Make Unlogged switch in table as read only. 2. Fix a console warning when saving node data. Fixes #6778 --- .../schemas/tables/static/js/table.ui.js | 2 +- web/pgadmin/static/js/SchemaView/index.jsx | 16 +++++++++------- web/pgadmin/static/js/Theme/index.jsx | 3 +++ web/pgadmin/static/js/custom_hooks.js | 11 ++++++++++- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.ui.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.ui.js index 9ea434ab9..46e300238 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.ui.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.ui.js @@ -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', diff --git a/web/pgadmin/static/js/SchemaView/index.jsx b/web/pgadmin/static/js/SchemaView/index.jsx index eea308fc0..62d3ec3e9 100644 --- a/web/pgadmin/static/js/SchemaView/index.jsx +++ b/web/pgadmin/static/js/SchemaView/index.jsx @@ -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 = []; diff --git a/web/pgadmin/static/js/Theme/index.jsx b/web/pgadmin/static/js/Theme/index.jsx index f24d3c63a..784b8840d 100644 --- a/web/pgadmin/static/js/Theme/index.jsx +++ b/web/pgadmin/static/js/Theme/index.jsx @@ -305,6 +305,9 @@ function getFinalTheme(baseTheme) { colorPrimary: { '&$disabled': { color: 'abc', + '& + .MuiSwitch-track': { + backgroundColor: 'abc', + } } }, switchBase: { diff --git a/web/pgadmin/static/js/custom_hooks.js b/web/pgadmin/static/js/custom_hooks.js index 4eb28d4c0..ac9cf91f3 100644 --- a/web/pgadmin/static/js/custom_hooks.js +++ b/web/pgadmin/static/js/custom_hooks.js @@ -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, []); +}