From 53a5e49ea52ba7cb2d99d0169b2b1c4c9af73c92 Mon Sep 17 00:00:00 2001 From: Nikhil Mohite Date: Tue, 10 Oct 2023 14:56:42 +0530 Subject: [PATCH] Fetch database objects after opening the backup dialog. #6799 --- .../static/js/SchemaView/MappedControl.jsx | 2 +- .../static/js/components/FormComponents.jsx | 21 +++++++++- web/pgadmin/tools/backup/static/js/backup.js | 39 +++++++++++-------- .../tools/backup/static/js/backup.ui.js | 3 +- 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/web/pgadmin/static/js/SchemaView/MappedControl.jsx b/web/pgadmin/static/js/SchemaView/MappedControl.jsx index 0e1421fe3ec..17e4ea387c8 100644 --- a/web/pgadmin/static/js/SchemaView/MappedControl.jsx +++ b/web/pgadmin/static/js/SchemaView/MappedControl.jsx @@ -116,7 +116,7 @@ MappedFormControlBase.propTypes = { onClick: PropTypes.func, withContainer: PropTypes.bool, controlGridBasis: PropTypes.number, - treeData: PropTypes.array, + treeData: PropTypes.oneOfType([PropTypes.array, PropTypes.instanceOf(Promise), PropTypes.func]), }; /* Control mapping for grid cell view */ diff --git a/web/pgadmin/static/js/components/FormComponents.jsx b/web/pgadmin/static/js/components/FormComponents.jsx index 7d7117dc338..67247a55744 100644 --- a/web/pgadmin/static/js/components/FormComponents.jsx +++ b/web/pgadmin/static/js/components/FormComponents.jsx @@ -44,6 +44,7 @@ import { showFileManager } from '../helpers/showFileManager'; import { withColorPicker } from '../helpers/withColorPicker'; import { useWindowSize } from '../custom_hooks'; import PgTreeView from '../PgTreeView'; +import Loader from 'sources/components/Loader'; const useStyles = makeStyles((theme) => ({ @@ -1278,12 +1279,28 @@ FormButton.propTypes = { }; export function InputTree({hasCheckbox, treeData, onChange, ...props}){ - return ; + const [[finalData, isLoading], setFinalData] = useState([[], true]); + + useEffect(() => { + let tdata = treeData, umounted = false; + if (typeof treeData === 'function') { + tdata = treeData(); + } + setFinalData([[], true]); + Promise.resolve(tdata) + .then((res) => { + if(!umounted){ + setFinalData([res, false]); + } + }); + return () => umounted = true; + }, []); + return <>{isLoading ? : }; } InputTree.propTypes = { hasCheckbox: PropTypes.bool, - treeData: PropTypes.array, + treeData: PropTypes.oneOfType([PropTypes.array, PropTypes.instanceOf(Promise), PropTypes.func]), onChange: PropTypes.func, selectionChange: PropTypes.func, }; diff --git a/web/pgadmin/tools/backup/static/js/backup.js b/web/pgadmin/tools/backup/static/js/backup.js index 2ab19a66470..9323fe0491b 100644 --- a/web/pgadmin/tools/backup/static/js/backup.js +++ b/web/pgadmin/tools/backup/static/js/backup.js @@ -255,26 +255,20 @@ define([ }); } - api({ - url: backup_obj_url, - method: 'GET' - }).then((response)=> { - let objects = response.data.data; - let schema = that.getUISchema(treeItem, 'backup_objects', objects); - panel.title(gettext(`Backup (${pgBrowser.Nodes[data._type].label}: ${data.label})`)); - panel.focus(); + let schema = that.getUISchema(treeItem, 'backup_objects', backup_obj_url); + panel.title(gettext(`Backup (${pgBrowser.Nodes[data._type].label}: ${data.label})`)); + panel.focus(); - let typeOfDialog = 'backup_objects', - serverIdentifier = that.retrieveServerIdentifier(), - extraData = that.setExtraParameters(typeOfDialog); + let typeOfDialog = 'backup_objects', + serverIdentifier = that.retrieveServerIdentifier(), + extraData = that.setExtraParameters(typeOfDialog); - that.showBackupDialog(schema, treeItem, j, data, panel, typeOfDialog, serverIdentifier, extraData); - }); + that.showBackupDialog(schema, treeItem, j, data, panel, typeOfDialog, serverIdentifier, extraData); }); }, - getUISchema: function(treeItem, backupType, objects) { + getUISchema: function(treeItem, backupType, backup_obj_url) { let treeNodeInfo = pgBrowser.tree.getTreeNodeHierarchy(treeItem); const selectedNode = pgBrowser.tree.selected(); let itemNodeData = pgBrowser.tree.findNodeByDomElement(selectedNode).getData(); @@ -289,12 +283,25 @@ define([ encoding: ()=>getNodeAjaxOptions('get_encodings', pgBrowser.Nodes['database'], treeNodeInfo, itemNodeData, { cacheNode: 'database', cacheLevel: 'server', - }), + }) }, treeNodeInfo, pgBrowser, backupType, - objects + { + objects: () => { + return new Promise((resolve, reject)=>{ + let api = getApiInstance(); + api({ + url: backup_obj_url, + method: 'GET' + }).then((response)=> { + resolve(response.data.data); + }).catch((err)=>{ + reject(err); + }); + }); + }} ); }, getGlobalUISchema: function(treeItem) { diff --git a/web/pgadmin/tools/backup/static/js/backup.ui.js b/web/pgadmin/tools/backup/static/js/backup.ui.js index 6ed30a7590a..d54018356fe 100644 --- a/web/pgadmin/tools/backup/static/js/backup.ui.js +++ b/web/pgadmin/tools/backup/static/js/backup.ui.js @@ -430,8 +430,7 @@ export default class BackupSchema extends BaseUISchema { role: null, ...fieldOptions, }; - - this.treeData = objects; + this.treeData = objects?.objects; this.treeNodeInfo = treeNodeInfo; this.pgBrowser = pgBrowser; this.backupType = backupType;