2022-03-21 13:29:26 +05:30
|
|
|
// /////////////////////////////////////////////////////////////
|
|
|
|
|
// //
|
|
|
|
|
// // pgAdmin 4 - PostgreSQL Tools
|
|
|
|
|
// //
|
|
|
|
|
// // Copyright (C) 2013 - 2022, The pgAdmin Development Team
|
|
|
|
|
// // This software is released under the PostgreSQL Licence
|
|
|
|
|
// //
|
|
|
|
|
// //////////////////////////////////////////////////////////////
|
|
|
|
|
|
2022-03-23 13:28:35 +05:30
|
|
|
import gettext from 'sources/gettext';
|
2022-03-21 13:29:26 +05:30
|
|
|
import * as React from 'react';
|
2022-03-23 13:28:35 +05:30
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
import { Directory} from 'react-aspen';
|
|
|
|
|
import { Tree } from '../../../../static/js/tree/tree';
|
2022-03-21 13:29:26 +05:30
|
|
|
import { ManagePreferenceTreeNodes } from '../../../../static/js/tree/preference_nodes';
|
|
|
|
|
import pgAdmin from 'sources/pgadmin';
|
2023-01-02 10:51:13 +05:30
|
|
|
import { FileTreeX, TreeModelX } from '../../../../static/js/components/PgTree';
|
2022-03-21 13:29:26 +05:30
|
|
|
|
|
|
|
|
|
2022-03-23 13:28:35 +05:30
|
|
|
export default function PreferencesTree({ pgBrowser, data }) {
|
|
|
|
|
const pTreeModelX = React.useRef();
|
|
|
|
|
const onReadyRef = React.useRef();
|
|
|
|
|
const [loaded, setLoaded] = React.useState(false);
|
|
|
|
|
|
|
|
|
|
const MOUNT_POINT = '/preferences';
|
2022-03-21 13:29:26 +05:30
|
|
|
|
2022-03-23 13:28:35 +05:30
|
|
|
React.useEffect(() => {
|
|
|
|
|
setLoaded(false);
|
2022-03-21 13:29:26 +05:30
|
|
|
|
2022-03-23 13:28:35 +05:30
|
|
|
// Setup host
|
|
|
|
|
let ptree = new ManagePreferenceTreeNodes(data);
|
|
|
|
|
// Init Tree with the Tree Parent node '/browser'
|
|
|
|
|
ptree.init(MOUNT_POINT);
|
2022-03-21 13:29:26 +05:30
|
|
|
|
2022-03-23 13:28:35 +05:30
|
|
|
const host = {
|
|
|
|
|
pathStyle: 'unix',
|
|
|
|
|
getItems: (path) => {
|
|
|
|
|
return ptree.readNode(path);
|
2023-01-02 10:51:13 +05:30
|
|
|
|
2022-03-23 13:28:35 +05:30
|
|
|
},
|
|
|
|
|
sortComparator: (a, b) => {
|
|
|
|
|
// No nee to sort Query tool options.
|
2022-03-24 16:08:13 +05:30
|
|
|
if (a._parent && a._parent._fileName == gettext('Query Tool')) return 0;
|
2022-03-23 13:28:35 +05:30
|
|
|
// Sort alphabetically
|
|
|
|
|
if (a.constructor === b.constructor) {
|
|
|
|
|
return pgAdmin.natural_sort(a.fileName, b.fileName);
|
|
|
|
|
}
|
|
|
|
|
let retval = 0;
|
|
|
|
|
if (a.constructor === Directory) {
|
|
|
|
|
retval = -1;
|
|
|
|
|
} else if (b.constructor === Directory) {
|
|
|
|
|
retval = 1;
|
|
|
|
|
}
|
|
|
|
|
return retval;
|
|
|
|
|
},
|
|
|
|
|
};
|
2022-03-21 13:29:26 +05:30
|
|
|
|
2022-03-23 13:28:35 +05:30
|
|
|
pTreeModelX.current = new TreeModelX(host, MOUNT_POINT);
|
|
|
|
|
onReadyRef.current = function onReady(handler) {
|
|
|
|
|
// Initialize preferences Tree
|
|
|
|
|
pgBrowser.ptree = new Tree(handler, ptree, pgBrowser, 'preferences');
|
|
|
|
|
// Expand directoy on loading.
|
|
|
|
|
pTreeModelX.current.root._children.forEach((_d)=> {
|
|
|
|
|
_d.root.expandDirectory(_d);
|
|
|
|
|
});
|
2023-01-02 10:51:13 +05:30
|
|
|
|
2022-03-23 13:28:35 +05:30
|
|
|
return true;
|
|
|
|
|
};
|
2022-03-21 13:29:26 +05:30
|
|
|
|
2022-03-23 13:28:35 +05:30
|
|
|
pTreeModelX.current.root.ensureLoaded().then(() => {
|
|
|
|
|
setLoaded(true);
|
|
|
|
|
});
|
|
|
|
|
}, [data]);
|
2022-03-21 13:29:26 +05:30
|
|
|
|
2022-03-23 13:28:35 +05:30
|
|
|
if (!loaded || _.isUndefined(pTreeModelX.current) || _.isUndefined(onReadyRef.current)) {
|
|
|
|
|
return (gettext('Loading...'));
|
|
|
|
|
}
|
|
|
|
|
return (<FileTreeX model={pTreeModelX.current} height={'100%'} onReady={onReadyRef.current} />);
|
|
|
|
|
}
|
2022-03-21 13:29:26 +05:30
|
|
|
|
2022-03-23 13:28:35 +05:30
|
|
|
PreferencesTree.propTypes = {
|
|
|
|
|
pgBrowser: PropTypes.any,
|
|
|
|
|
data: PropTypes.array,
|
|
|
|
|
ptree: PropTypes.any,
|
2023-01-02 10:51:13 +05:30
|
|
|
};
|