mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2024-11-25 18:20:20 -06:00
Port Tablespace node to react. Fixes #6644.
This commit is contained in:
parent
d9cfbf592e
commit
39765903d4
@ -11,6 +11,7 @@ import gettext from 'sources/gettext';
|
||||
import _ from 'lodash';
|
||||
import BaseUISchema from 'sources/SchemaView/base_schema.ui';
|
||||
import { getNodeAjaxOptions, getNodeListByName } from '../../../../static/js/node_ajax';
|
||||
import { isEmptyString } from '../../../../../static/js/validators';
|
||||
|
||||
export function getNodeVariableSchema(nodeObj, treeNodeInfo, itemNodeData, hasDatabase, hasRole) {
|
||||
let keys = ['name', 'value'];
|
||||
@ -81,7 +82,7 @@ export default class VariableSchema extends BaseUISchema {
|
||||
case 'integer':
|
||||
return 'int';
|
||||
case 'real':
|
||||
return 'number';
|
||||
return 'numeric';
|
||||
case 'string':
|
||||
return 'text';
|
||||
default:
|
||||
@ -107,11 +108,10 @@ export default class VariableSchema extends BaseUISchema {
|
||||
optionsLoaded: (options)=>{obj.setVarTypes(options);},
|
||||
controlProps: { allowClear: false },
|
||||
}),
|
||||
noEmpty: true,
|
||||
},
|
||||
{
|
||||
id: 'value', label: gettext('Value'), type: 'text',
|
||||
noEmpty: true, deps: ['name'],
|
||||
deps: ['name'],
|
||||
depChange: (state, changeSource)=>{
|
||||
if(changeSource == 'name') {
|
||||
return {...state
|
||||
@ -136,4 +136,21 @@ export default class VariableSchema extends BaseUISchema {
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
validate(state, setError) {
|
||||
if (isEmptyString(state.name)) {
|
||||
setError('name', gettext('Please select a parameter name.'));
|
||||
return true;
|
||||
} else {
|
||||
setError('name', null);
|
||||
}
|
||||
|
||||
if (isEmptyString(state.value)) {
|
||||
setError('value', gettext('Please enter a value for the parameter.'));
|
||||
return true;
|
||||
} else {
|
||||
setError('value', null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,11 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import { getNodeListByName } from '../../../../../static/js/node_ajax';
|
||||
import { getNodePrivilegeRoleSchema } from '../../../static/js/privilege.ui';
|
||||
import { getNodeVariableSchema } from '../../../static/js/variable.ui';
|
||||
import TablespaceSchema from './tablespace.ui';
|
||||
|
||||
define('pgadmin.node.tablespace', [
|
||||
'sources/gettext', 'sources/url_for', 'jquery', 'underscore', 'backbone',
|
||||
'sources/pgadmin', 'pgadmin.browser', 'pgadmin.alertifyjs',
|
||||
@ -318,18 +323,22 @@ define('pgadmin.node.tablespace', [
|
||||
Alertify.move_objects_dlg(true).resizeTo(pgBrowser.stdW.md,pgBrowser.stdH.md);
|
||||
},
|
||||
},
|
||||
|
||||
getSchema: function(treeNodeInfo, itemNodeData) {
|
||||
return new TablespaceSchema(
|
||||
()=>getNodeVariableSchema(this, treeNodeInfo, itemNodeData, false, false),
|
||||
(privileges)=>getNodePrivilegeRoleSchema(this, treeNodeInfo, itemNodeData, privileges),
|
||||
{
|
||||
role: ()=>getNodeListByName('role', treeNodeInfo, itemNodeData),
|
||||
},
|
||||
{
|
||||
spcuser: pgBrowser.serverInfo[treeNodeInfo.server._id].user.name,
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
model: pgBrowser.Node.Model.extend({
|
||||
idAttribute: 'oid',
|
||||
defaults: {
|
||||
name: undefined,
|
||||
owner: undefined,
|
||||
is_sys_obj: undefined,
|
||||
comment: undefined,
|
||||
spclocation: undefined,
|
||||
spcoptions: [],
|
||||
spcacl: [],
|
||||
seclabels:[],
|
||||
},
|
||||
|
||||
// Default values!
|
||||
initialize: function(attrs, args) {
|
||||
@ -342,73 +351,19 @@ define('pgadmin.node.tablespace', [
|
||||
pgBrowser.Node.Model.prototype.initialize.apply(this, arguments);
|
||||
},
|
||||
|
||||
schema: [{
|
||||
id: 'name', label: gettext('Name'), cell: 'string',
|
||||
type: 'text',
|
||||
},{
|
||||
id: 'oid', label: gettext('OID'), cell: 'string',
|
||||
type: 'text', mode: ['properties'],
|
||||
},{
|
||||
id: 'spclocation', label: gettext('Location'), cell: 'string',
|
||||
group: gettext('Definition'), type: 'text', mode: ['properties', 'edit','create'],
|
||||
readonly: function(m) {
|
||||
// To disabled it in edit mode,
|
||||
// We'll check if model is new if yes then disabled it
|
||||
return !m.isNew();
|
||||
schema: [
|
||||
{
|
||||
id: 'name', label: gettext('Name'), cell: 'string',
|
||||
type: 'text',
|
||||
}, {
|
||||
id: 'spcuser', label: gettext('Owner'), cell: 'string',
|
||||
type: 'text', control: 'node-list-by-name', node: 'role',
|
||||
select2: {allowClear: false},
|
||||
}, {
|
||||
id: 'description', label: gettext('Comment'), cell: 'string',
|
||||
type: 'multiline',
|
||||
},
|
||||
},{
|
||||
id: 'spcuser', label: gettext('Owner'), cell: 'string',
|
||||
type: 'text', control: 'node-list-by-name', node: 'role',
|
||||
select2: {allowClear: false},
|
||||
},{
|
||||
id: 'acl', label: gettext('Privileges'), type: 'text',
|
||||
group: gettext('Security'), mode: ['properties'],
|
||||
},{
|
||||
id: 'is_sys_obj', label: gettext('System tablespace?'),
|
||||
cell:'boolean', type: 'switch', mode: ['properties'],
|
||||
},{
|
||||
id: 'description', label: gettext('Comment'), cell: 'string',
|
||||
type: 'multiline',
|
||||
},{
|
||||
id: 'spcoptions', label: '', type: 'collection',
|
||||
group: gettext('Parameters'), control: 'variable-collection',
|
||||
model: pgBrowser.Node.VariableModel,
|
||||
mode: ['edit', 'create'], canAdd: true, canEdit: false,
|
||||
canDelete: true,
|
||||
},{
|
||||
id: 'spcacl', label: gettext('Privileges'), type: 'collection',
|
||||
group: gettext('Security'), control: 'unique-col-collection',
|
||||
model: pgBrowser.Node.PrivilegeRoleModel.extend({privileges: ['C']}),
|
||||
mode: ['edit', 'create'], canAdd: true, canDelete: true,
|
||||
uniqueCol : ['grantee'],
|
||||
columns: ['grantee', 'grantor', 'privileges'],
|
||||
},{
|
||||
id: 'seclabels', label: gettext('Security labels'),
|
||||
model: pgBrowser.SecLabelModel, editable: false, type: 'collection',
|
||||
group: gettext('Security'), mode: ['edit', 'create'],
|
||||
min_version: 90200, canAdd: true,
|
||||
canEdit: false, canDelete: true, control: 'unique-col-collection',
|
||||
},
|
||||
],
|
||||
validate: function() {
|
||||
var msg;
|
||||
|
||||
if (_.isUndefined(this.get('name'))
|
||||
|| String(this.get('name')).replace(/^\s+|\s+$/g, '') == '') {
|
||||
msg = gettext('Name cannot be empty.');
|
||||
this.errorModel.set('name', msg);
|
||||
} else if (this.isNew() &&
|
||||
(_.isUndefined(this.get('spclocation'))
|
||||
|| String(this.get('spclocation')).replace(/^\s+|\s+$/g, '') == '')) {
|
||||
msg = gettext('Location cannot be empty.');
|
||||
this.errorModel.set('spclocation', msg);
|
||||
this.errorModel.unset('name');
|
||||
} else {
|
||||
this.errorModel.unset('name');
|
||||
this.errorModel.unset('spclocation');
|
||||
}
|
||||
return null;
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
|
@ -0,0 +1,91 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import gettext from 'sources/gettext';
|
||||
import BaseUISchema from 'sources/SchemaView/base_schema.ui';
|
||||
import SecLabelSchema from '../../../static/js/sec_label.ui';
|
||||
|
||||
export default class TablespaceSchema extends BaseUISchema {
|
||||
constructor(getVariableSchema, getPrivilegeRoleSchema, fieldOptions={}, initValues) {
|
||||
super({
|
||||
name: undefined,
|
||||
owner: undefined,
|
||||
is_sys_obj: undefined,
|
||||
comment: undefined,
|
||||
spclocation: undefined,
|
||||
spcoptions: [],
|
||||
spcacl: [],
|
||||
seclabels:[],
|
||||
...initValues,
|
||||
});
|
||||
this.getPrivilegeRoleSchema = getPrivilegeRoleSchema;
|
||||
this.getVariableSchema = getVariableSchema;
|
||||
this.fieldOptions = {
|
||||
role: [],
|
||||
...fieldOptions,
|
||||
};
|
||||
}
|
||||
|
||||
get idAttribute() {
|
||||
return 'oid';
|
||||
}
|
||||
|
||||
get baseFields() {
|
||||
let obj = this;
|
||||
return [
|
||||
{
|
||||
id: 'name', label: gettext('Name'), cell: 'text',
|
||||
type: 'text', mode: ['properties', 'create', 'edit'],
|
||||
noEmpty: true,
|
||||
}, {
|
||||
id: 'oid', label: gettext('OID'), cell: 'text',
|
||||
type: 'text', mode: ['properties'],
|
||||
}, {
|
||||
id: 'spcuser', label: gettext('Owner'), cell: 'text',
|
||||
editable: false, type: 'select', options: this.fieldOptions.role,
|
||||
controlProps: { allowClear: false }
|
||||
}, {
|
||||
id: 'is_sys_obj', label: gettext('System tablespace?'),
|
||||
cell:'boolean', type: 'switch', mode: ['properties'],
|
||||
}, {
|
||||
id: 'description', label: gettext('Comment'), cell: 'text',
|
||||
type: 'multiline',
|
||||
}, {
|
||||
id: 'spclocation', label: gettext('Location'),
|
||||
group: gettext('Definition'), type: 'text',
|
||||
mode: ['properties', 'edit','create'],
|
||||
readonly: function(state) {return !obj.isNew(state); },
|
||||
noEmpty: true,
|
||||
}, {
|
||||
id: 'acl', label: gettext('Privileges'), type: 'text',
|
||||
group: gettext('Security'), mode: ['properties'],
|
||||
}, {
|
||||
id: 'spcoptions', label: '', type: 'collection',
|
||||
schema: this.getVariableSchema(),
|
||||
editable: false,
|
||||
group: gettext('Parameters'), mode: ['edit', 'create'],
|
||||
canAdd: true, canEdit: false, canDelete: true,
|
||||
}, {
|
||||
id: 'spcacl', label: gettext('Privileges'), type: 'collection',
|
||||
group: gettext('Security'),
|
||||
schema: this.getPrivilegeRoleSchema(['C']),
|
||||
mode: ['edit', 'create'], uniqueCol : ['grantee'],
|
||||
canAdd: true, canDelete: true,
|
||||
}, {
|
||||
id: 'seclabels', label: gettext('Security labels'), type: 'collection',
|
||||
editable: false, group: gettext('Security'),
|
||||
schema: new SecLabelSchema(),
|
||||
mode: ['edit', 'create'],
|
||||
min_version: 90200,
|
||||
uniqueCol : ['provider'],
|
||||
canAdd: true, canEdit: false, canDelete: true,
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ describe('DomainSchema', ()=>{
|
||||
{
|
||||
role: ()=>[],
|
||||
schema: ()=>[],
|
||||
basetype: ()=>[],
|
||||
basetype: ()=>['character varying', 'numeric'],
|
||||
collation: ()=>[],
|
||||
},
|
||||
[],
|
||||
|
165
web/regression/javascript/schema_ui_files/tablespace.ui.spec.js
Normal file
165
web/regression/javascript/schema_ui_files/tablespace.ui.spec.js
Normal file
@ -0,0 +1,165 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import {messages} from '../fake_messages';
|
||||
import SchemaView from '../../../pgadmin/static/js/SchemaView';
|
||||
import BaseUISchema from 'sources/SchemaView/base_schema.ui';
|
||||
import TablespaceSchema from '../../../pgadmin/browser/server_groups/servers/tablespaces/static/js/tablespace.ui';
|
||||
|
||||
class MockSchema extends BaseUISchema {
|
||||
get baseFields() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
describe('TablespaceSchema', ()=>{
|
||||
let mount;
|
||||
let schemaObj = new TablespaceSchema(
|
||||
()=>new MockSchema(),
|
||||
()=>new MockSchema(),
|
||||
{
|
||||
role: ()=>[],
|
||||
},
|
||||
{
|
||||
spcuser: 'postgres'
|
||||
}
|
||||
);
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* Use createMount so that material ui components gets the required context */
|
||||
/* https://material-ui.com/guides/testing/#api */
|
||||
beforeAll(()=>{
|
||||
mount = createMount();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mount.cleanUp();
|
||||
});
|
||||
|
||||
beforeEach(()=>{
|
||||
jasmineEnzyme();
|
||||
/* messages used by validators */
|
||||
pgAdmin.Browser = pgAdmin.Browser || {};
|
||||
pgAdmin.Browser.messages = pgAdmin.Browser.messages || messages;
|
||||
pgAdmin.Browser.utils = pgAdmin.Browser.utils || {};
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'edit',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='tab'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'properties',
|
||||
}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
/>);
|
||||
});
|
||||
|
||||
// it('validate', ()=>{
|
||||
// let state = {};
|
||||
// let setError = jasmine.createSpy('setError');
|
||||
//
|
||||
// state.seqowner = null;
|
||||
// schemaObj.validate(state, setError);
|
||||
// expect(setError).toHaveBeenCalledWith('seqowner', '\'Owner\' cannot be empty.');
|
||||
//
|
||||
// state.seqowner = 'postgres';
|
||||
// state.schema = null;
|
||||
// schemaObj.validate(state, setError);
|
||||
// expect(setError).toHaveBeenCalledWith('schema', '\'Schema\' cannot be empty.');
|
||||
//
|
||||
// state.schema = 'public';
|
||||
// state.oid = 12345;
|
||||
// state.current_value = null;
|
||||
// schemaObj.validate(state, setError);
|
||||
// expect(setError).toHaveBeenCalledWith('current_value', '\'Current value\' cannot be empty.');
|
||||
//
|
||||
// state.current_value = 10;
|
||||
// state.increment = null;
|
||||
// schemaObj.validate(state, setError);
|
||||
// expect(setError).toHaveBeenCalledWith('increment', '\'Increment value\' cannot be empty.');
|
||||
//
|
||||
//
|
||||
// state.increment = 1;
|
||||
// state.minimum = null;
|
||||
// schemaObj.validate(state, setError);
|
||||
// expect(setError).toHaveBeenCalledWith('minimum', '\'Minimum value\' cannot be empty.');
|
||||
//
|
||||
// state.minimum = 5;
|
||||
// state.maximum = null;
|
||||
// schemaObj.validate(state, setError);
|
||||
// expect(setError).toHaveBeenCalledWith('maximum', '\'Maximum value\' cannot be empty.');
|
||||
//
|
||||
// state.maximum = 200;
|
||||
// state.cache = null;
|
||||
// schemaObj.validate(state, setError);
|
||||
// expect(setError).toHaveBeenCalledWith('cache', '\'Cache value\' cannot be empty.');
|
||||
//
|
||||
// state.cache = 1;
|
||||
// state.minimum = 10;
|
||||
// state.maximum = 5;
|
||||
// schemaObj.validate(state, setError);
|
||||
// expect(setError).toHaveBeenCalledWith('minimum', 'Minimum value must be less than maximum value.');
|
||||
//
|
||||
// state.start = 5;
|
||||
// state.minimum = 10;
|
||||
// state.maximum = 50;
|
||||
// schemaObj.validate(state, setError);
|
||||
// expect(setError).toHaveBeenCalledWith('start', 'Start value cannot be less than minimum value.');
|
||||
//
|
||||
// state.start = 500;
|
||||
// schemaObj.validate(state, setError);
|
||||
// expect(setError).toHaveBeenCalledWith('start', 'Start value cannot be greater than maximum value.');
|
||||
// });
|
||||
});
|
||||
|
@ -123,7 +123,7 @@ describe('VariableSchema', ()=>{
|
||||
cell: 'select',
|
||||
}));
|
||||
expect(schemaObj.getValueFieldProps({vartype: 'integer'})).toBe('int');
|
||||
expect(schemaObj.getValueFieldProps({vartype: 'real'})).toBe('number');
|
||||
expect(schemaObj.getValueFieldProps({vartype: 'real'})).toBe('numeric');
|
||||
expect(schemaObj.getValueFieldProps({vartype: 'string'})).toBe('text');
|
||||
expect(schemaObj.getValueFieldProps({})).toBe('');
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user