- Add VaccumSettings schema. - Allow collection to have fixed rows. - Changes in data change comparison and add state utils context. - Fixed jasmine test cases.

This commit is contained in:
Aditya Toshniwal
2021-07-29 13:18:04 +05:30
committed by Akshay Joshi
parent eb48765a5a
commit 377fe80046
8 changed files with 342 additions and 79 deletions

View File

@@ -0,0 +1,179 @@
import gettext from 'sources/gettext';
import BaseUISchema from 'sources/SchemaView/base_schema.ui';
import { getNodeAjaxOptions } from '../../../../static/js/node_ajax';
export function getNodeVacuumSettingsSchema(nodeObj, treeNodeInfo, itemNodeData) {
let tableVacuumRows = ()=>getNodeAjaxOptions('get_table_vacuum', nodeObj, treeNodeInfo, itemNodeData, {noCache: true});
let toastTableVacuumRows = ()=>getNodeAjaxOptions('get_toast_table_vacuum', nodeObj, treeNodeInfo, itemNodeData, {noCache: true});
return new VacuumSettingsSchema(tableVacuumRows, toastTableVacuumRows, treeNodeInfo);
}
export class VacuumTableSchema extends BaseUISchema {
constructor(valueDep) {
super();
this.valueDep = valueDep;
}
get baseFields() {
let obj = this;
return [
{
id: 'label', name: 'label', label: gettext('Label'),
},
{
id: 'value', name: 'value', label: gettext('Value'),
type: 'text', deps: [[this.valueDep]],
editable: function() {
return obj.top.sessData[this.valueDep];
},
cell: (state)=>{
switch(state.column_type) {
case 'integer':
return {cell: 'int'};
case 'number':
return {cell: 'numeric', controlProps: {decimals: 5}};
case 'string':
return {cell: 'text'};
default:
return {cell: ''};
}
}
},
{
id: 'setting', name: 'setting', label: gettext('Default'),
},
];
}
}
export default class VacuumSettingsSchema extends BaseUISchema {
constructor(tableVars, toastTableVars, nodeInfo) {
super({
vacuum_table: [],
vacuum_toast: [],
});
this.tableVars = tableVars;
this.toastTableVars = toastTableVars;
this.nodeInfo = nodeInfo;
this.vacuumTableObj = new VacuumTableSchema('autovacuum_custom');
this.vacuumToastTableObj = new VacuumTableSchema('toast_autovacuum');
}
inSchemaCheck() {
if(this.nodeInfo && 'catalog' in this.nodeInfo)
{
return true;
}
return false;
}
get baseFields() {
var obj = this;
return [{
id: 'autovacuum_custom', label: gettext('Custom auto-vacuum?'),
group: gettext('Table'), mode: ['edit', 'create'],
type: 'switch', disabled: function(state) {
if(state.is_partitioned) {
return true;
}
// If table is partitioned table then disabled it.
if(state.top && state.is_partitioned) {
// We also need to unset rest of all
state.autovacuum_custom = false;
return true;
}
if(obj.inSchemaCheck)
{
return false;
}
return true;
},
depChange(state) {
if(state.is_partitioned) {
return {autovacuum_custom: false};
}
}
},
{
id: 'autovacuum_enabled', label: gettext('Autovacuum Enabled?'),
group: gettext('Table'), mode: ['edit', 'create'], type: 'toggle',
options: [
{'label': gettext('Not set'), 'value': 'x'},
{'label': gettext('Yes'), 'value': 't'},
{'label': gettext('No'), 'value': 'f'},
],
deps: ['autovacuum_custom'],
disabled: function(state) {
if(obj.inSchemaCheck && state.autovacuum_custom) {
return false;
}
return true;
},
depChange: function(state) {
if(obj.inSchemaCheck && state.autovacuum_custom) {
return;
}
return {autovacuum_enabled: 'x'};
},
},
{
id: 'vacuum_table', label: '', editable: false, type: 'collection',
canEdit: false, canAdd: false, canDelete: false, group: gettext('Table'),
fixedRows: this.tableVars,
schema: this.vacuumTableObj,
mode: ['edit', 'create'],
},
{
id: 'toast_autovacuum', label: gettext('Custom auto-vacuum?'),
group: gettext('TOAST table'), mode: ['edit', 'create'],
type: 'switch',
disabled: function(state) {
// We need to check additional condition to toggle enable/disable
// for table auto-vacuum
if(obj.inSchemaCheck && (obj.isNew() || (state.toast_autovacuum_enabled || state.hastoasttable))) {
return false;
}
return true;
}
},
{
id: 'toast_autovacuum_enabled', label: gettext('Autovacuum Enabled?'),
group: gettext('TOAST table'), mode: ['edit', 'create'],
type: 'toggle',
options: [
{'label': gettext('Not set'), 'value': 'x'},
{'label': gettext('Yes'), 'value': 't'},
{'label': gettext('No'), 'value': 'f'},
],
deps:['toast_autovacuum'],
disabled: function(state) {
if(obj.inSchemaCheck && state.toast_autovacuum) {
return false;
}
return true;
},
depChange: function(state) {
if(obj.inSchemaCheck && state.toast_autovacuum) {
return;
}
if(obj.isNew() || state.hastoasttable) {
return {toast_autovacuum_enabled: 'x'};
}
},
},
{
id: 'vacuum_toast', label: '',
type: 'collection',
fixedRows: this.toastTableVars,
editable: function(state) {
return state.isNew();
},
canEdit: false, canAdd: false, canDelete: false, group: gettext('TOAST table'),
schema: this.vacuumToastTableObj,
mode: ['properties', 'edit', 'create'], deps: ['toast_autovacuum'],
}];
}
}