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

Function getNodeAjaxOptions

web/pgadmin/browser/static/js/node_ajax.js:83–136  ·  view source on GitHub ↗
(url, nodeObj, treeNodeInfo, itemNodeData, params={}, transform=(data)=>data)

Source from the content-addressed store, hash-verified

81 * The options are cached for performance reasons.
82 */
83export function getNodeAjaxOptions(url, nodeObj, treeNodeInfo, itemNodeData, params={}, transform=(data)=>data) {
84 let otherParams = {
85 urlWithId: false,
86 jumpAfterNode: null,
87 useCache: true,
88 customGenerateUrl: null,
89 ...params
90 };
91 return new Promise((resolve, reject)=>{
92 const api = getApiInstance();
93 let fullUrl = '';
94 if(url) {
95 if(otherParams.customGenerateUrl) {
96 fullUrl = otherParams.customGenerateUrl.call(
97 nodeObj, treeNodeInfo, url, itemNodeData, otherParams.urlWithId, otherParams.jumpAfterNode
98 );
99 } else {
100 fullUrl = generateNodeUrl.call(
101 nodeObj, treeNodeInfo, url, itemNodeData, otherParams.urlWithId, otherParams.jumpAfterNode
102 );
103 }
104 }
105
106 if (url) {
107 let cacheNode = pgAdmin.Browser.Nodes[otherParams.cacheNode] || nodeObj;
108 let cacheLevel = otherParams.cacheLevel || cacheNode.cache_level(treeNodeInfo, otherParams.urlWithId);
109 /*
110 * We needs to check, if we have already cached data for this url.
111 * If yes - use that, and do not bother about fetching it again,
112 * and use it.
113 */
114 let data = cacheNode.cache(nodeObj.type + '#' + url, treeNodeInfo, cacheLevel);
115
116 if (_.isUndefined(data) || _.isNull(data)) {
117 api.get(fullUrl, {
118 params: otherParams.urlParams,
119 }).then((res)=>{
120 data = res.data;
121 if(res.data.data) {
122 data = res.data.data;
123 }
124 otherParams.useCache && cacheNode.cache(nodeObj.type + '#' + url, treeNodeInfo, cacheLevel, data);
125 resolve(transform(data));
126 }).catch((err)=>{
127 reject(err instanceof Error ? err : Error('Something went wrong'));
128 });
129 } else {
130 // To fetch only options from cache, we do not need time from 'at'
131 // attribute but only options.
132 resolve(transform(data.data || []));
133 }
134 }
135 });
136}
137
138/* Get the nodes list based on current selected node id */
139export function getNodeListById(nodeObj, treeNodeInfo, itemNodeData, params={}, filter=()=>true, postTransform=(res)=>res) {

Callers 15

getNodeVariableSchemaFunction · 0.90
tableVacuumRowsFunction · 0.90
toastTableVacuumRowsFunction · 0.90
pga_job.jsFile · 0.90
language.jsFile · 0.90
c_typesFunction · 0.90
icu_localeFunction · 0.90
builtin_localeFunction · 0.90
database.jsFile · 0.90
dbms_job.jsFile · 0.90
dbms_program.jsFile · 0.90
event_trigger.jsFile · 0.90

Calls 3

getApiInstanceFunction · 0.85
transformFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected