MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / ObjectExplorer

Function ObjectExplorer

web/pgadmin/static/js/tree/ObjectExplorer/index.jsx:103–207  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

101}
102
103export default function ObjectExplorer() {
104 const [contextPos, setContextPos] = React.useState(null);
105 const pgAdmin = usePgAdmin();
106 const contextMenuItems = pgAdmin.Browser.BrowserContextMenu;
107 const [treeModelLoaded, setTreeModelLoaded] = useState(false);
108 const treeModelXRef = useRef();
109 const MOUNT_POINT = '/browser';
110 const mtree = useMemo(()=>new ManageTreeNodes(), []);
111
112 useEffect(()=>{
113 // Init Tree with the Tree Parent node '/browser'
114 mtree.init(MOUNT_POINT);
115
116 const host = {
117 pathStyle: 'unix',
118 getItems: async (path) => {
119 return mtree.readNode(path);
120 },
121 sortComparator: (a, b) => {
122 // No nee to sort columns
123 if (a._metadata && a._metadata.data._type == 'column') return 0;
124 // Sort alphabetically
125 if (a.constructor === b.constructor) {
126 return pgAdmin.natural_sort(a.fileName, b.fileName);
127 }
128 let retval = 0;
129 if (a.constructor === Directory) {
130 retval = -1;
131 } else if (b.constructor === Directory) {
132 retval = 1;
133 }
134 return retval;
135 },
136 };
137
138 treeModelXRef.current = new TreeModelX(host, MOUNT_POINT);
139
140 treeModelXRef.current.root.ensureLoaded().then(()=>{
141 setTreeModelLoaded(true);
142 });
143 }, []);
144
145 const itemHandle = function onReady(handler) {
146 pgAdmin.Browser.tree = new Tree(handler, mtree, pgAdmin.Browser);
147 postTreeReady(pgAdmin.Browser);
148 };
149 // Create Node
150 const create = async (parentPath, _data) => {
151 try {
152 const _node_path = parentPath + '/' + _data.id;
153 return mtree.addNode(parentPath, _node_path, _data);
154 } catch {
155 return null; // or throw error as you see fit
156 }
157 };
158
159 // Remove Node
160 const remove = async (path, _removeOnlyChild) => {

Callers

nothing calls this directly

Calls 4

usePgAdminFunction · 0.90
ensureLoadedMethod · 0.80
selectMethod · 0.80
initMethod · 0.45

Tested by

no test coverage detected