Skip to content

Commit

Permalink
'vnameOptions' can be a Promise function too, hence - taken care accr…
Browse files Browse the repository at this point in the history
…odingly.
  • Loading branch information
asheshv committed Sep 12, 2024
1 parent 3bfa2cb commit 274f2e0
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions web/pgadmin/browser/server_groups/servers/static/js/variable.ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function getNodeVariableSchema(nodeObj, treeNodeInfo, itemNodeData, hasDa
keys.push('role');
}
return new VariableSchema(
()=>getNodeAjaxOptions('vopts', nodeObj, treeNodeInfo, itemNodeData, null, (vars)=>{
() => getNodeAjaxOptions('vopts', nodeObj, treeNodeInfo, itemNodeData, null, (vars)=>{
let res = [];
_.each(vars, function(v) {
res.push({
Expand All @@ -38,8 +38,8 @@ export function getNodeVariableSchema(nodeObj, treeNodeInfo, itemNodeData, hasDa

return res;
}),
()=>getNodeListByName('database', treeNodeInfo, itemNodeData),
()=>getNodeListByName('role', treeNodeInfo, itemNodeData),
() => getNodeListByName('database', treeNodeInfo, itemNodeData),
() => getNodeListByName('role', treeNodeInfo, itemNodeData),
keys
);
}
Expand All @@ -60,18 +60,26 @@ export default class VariableSchema extends BaseUISchema {
this.keys = keys;
this.allReadOnly = false;

this.setVarTypes(this.vnameOptions);
setTimeout(() => this.setVarTypes(vnameOptions), 0);
}

setAllReadOnly(isReadOnly) {
this.allReadOnly = isReadOnly;
}

setVarTypes(options) {
options.forEach((option)=>{
this.varTypes[option.value] = {
...option,
};
let optPromise = options;

if (typeof options === 'function') {
optPromise = options();
}

Promise.resolve(optPromise).then((res) => {
res.forEach((option) => {
this.varTypes[option.value] = {
...option,
};
});
});
}

Expand Down Expand Up @@ -164,7 +172,7 @@ export default class VariableSchema extends BaseUISchema {
{
id: 'value', label: gettext('Value'), type: 'text',
deps: ['name'], editable: !obj.allReadOnly,
depChange: (state, source)=>{
depChange: (state, source) => {
if(source[source.length-1] == 'name') {
let variable = obj.varTypes[state.name];
if(variable.vartype === 'bool'){
Expand All @@ -182,14 +190,15 @@ export default class VariableSchema extends BaseUISchema {
return obj.getValueFieldProps(variable);
}
},
{id: 'database', label: gettext('Database'), type: 'text',
{
id: 'database', label: gettext('Database'), type: 'text',
cell: ()=>({cell: 'select', options: obj.databaseOptions }),
},
{id: 'role', label: gettext('Role'), type: 'text',
cell: ()=>({cell: 'select', options: obj.roleOptions,
controlProps: {
allowClear: false,
}
{
id: 'role', label: gettext('Role'), type: 'text',
cell: () => ({
cell: 'select', options: obj.roleOptions,
controlProps: { allowClear: false },
}),
},
];
Expand Down

0 comments on commit 274f2e0

Please sign in to comment.