Port FTS Template, FTS Parsers nodes to react. Fixes #6587.

This commit is contained in:
Rahul Shirsat 2021-07-12 15:55:41 +05:30 committed by Akshay Joshi
parent 4b8e655948
commit f16b18371e
6 changed files with 570 additions and 71 deletions

View File

@ -7,6 +7,9 @@
//
//////////////////////////////////////////////////////////////
import FTSParserSchema from './fts_parser.ui';
import { getNodeAjaxOptions, getNodeListById } from '../../../../../../../static/js/node_ajax';
define('pgadmin.node.fts_parser', [
'sources/gettext', 'sources/url_for', 'jquery', 'underscore',
'sources/pgadmin', 'pgadmin.browser', 'pgadmin.node.schema.dir/child',
@ -74,12 +77,6 @@ define('pgadmin.node.fts_parser', [
name: undefined, // Fts parser name
is_sys_obj: undefined, // Is system object
description: undefined, // Comment on parser
schema: undefined, // Schema name to which parser belongs
prsstart: undefined, // Start function for fts parser
prstoken: undefined, // Token function for fts parser
prsend: undefined, // End function for fts parser
prslextype: undefined, // Lextype function for fts parser
prsheadline: undefined, // Headline function for fts parse
},
initialize: function(attrs, args) {
var isNew = (_.size(attrs) === 0);
@ -97,47 +94,9 @@ define('pgadmin.node.fts_parser', [
},{
id: 'oid', label: gettext('OID'), cell: 'string',
editable: false, type: 'text', mode:['properties'],
},{
id: 'schema', label: gettext('Schema'), cell: 'string',
type: 'text', mode: ['create','edit'], node: 'schema',
control: 'node-list-by-id', cache_node: 'database',
cache_level: 'database',
},{
id: 'is_sys_obj', label: gettext('System FTS parser?'),
cell:'boolean', type: 'switch', mode: ['properties'],
},{
id: 'description', label: gettext('Comment'), cell: 'string',
type: 'multiline', cellHeaderClasses: 'width_percent_50',
},{
id: 'prsstart', label: gettext('Start function'),
type: 'text', readonly: function(m) { return !m.isNew(); },
control: 'node-ajax-options', url: 'start_functions',
group: gettext('Definition'), cache_level: 'database',
cache_node: 'schema',
},{
id: 'prstoken', label: gettext('Get next token function'),
type: 'text', readonly: function(m) { return !m.isNew(); },
control: 'node-ajax-options', url: 'token_functions',
group: gettext('Definition'), cache_level: 'database',
cache_node: 'schema',
},{
id: 'prsend', label: gettext('End function'),
type: 'text', readonly: function(m) { return !m.isNew(); },
control: 'node-ajax-options', url: 'end_functions',
group: gettext('Definition'), cache_level: 'database',
cache_node: 'schema',
},{
id: 'prslextype', label: gettext('Lextypes function'),
type: 'text', readonly: function(m) { return !m.isNew(); },
control: 'node-ajax-options', url: 'lextype_functions',
group: gettext('Definition'), cache_level: 'database',
cache_node: 'schema',
},{
id: 'prsheadline', label: gettext('Headline function'),
type: 'text', readonly: function(m) { return !m.isNew(); },
control: 'node-ajax-options', url: 'headline_functions',
group: gettext('Definition'), cache_level: 'database',
cache_node: 'schema',
}],
/*
@ -213,6 +172,34 @@ define('pgadmin.node.fts_parser', [
return null;
},
}),
getSchema: (treeNodeInfo, itemNodeData) => {
let nodeObj = pgAdmin.Browser.Nodes['fts_parser'];
return new FTSParserSchema(
{
prsstartList: () => getNodeAjaxOptions('start_functions', nodeObj, treeNodeInfo, itemNodeData, {
cacheLevel: 'database',
}),
prstokenList: () => getNodeAjaxOptions('token_functions', nodeObj, treeNodeInfo, itemNodeData, {
cacheLevel: 'database',
}),
prsendList: () => getNodeAjaxOptions('end_functions', nodeObj, treeNodeInfo, itemNodeData, {
cacheLevel: 'database',
}),
prslextypeList: () => getNodeAjaxOptions('lextype_functions', nodeObj, treeNodeInfo, itemNodeData, {
cacheLevel: 'database',
}),
prsheadlineList: () => getNodeAjaxOptions('headline_functions', nodeObj, treeNodeInfo, itemNodeData, {
cacheLevel: 'database',
}),
schemaList:() => getNodeListById(pgBrowser.Nodes['schema'], treeNodeInfo, itemNodeData, {
cacheLevel: 'database'
})
},
{
schema: treeNodeInfo.schema._id,
}
);
}
});
}

View File

@ -0,0 +1,195 @@
/////////////////////////////////////////////////////////////
//
// 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';
export default class FTSParserSchema extends BaseUISchema {
constructor(fieldOptions = {}, initValues) {
super({
name: null,
oid: undefined,
version: '',
schema: undefined,
description: '',
is_sys_obj: false,
...initValues
});
this.fieldOptions = {
prsstartList: [],
prstokenList: [],
prsendList: [],
prslextypeList: [],
prsheadlineList: [],
schemaList: [],
...fieldOptions
};
}
get idAttribute() {
return 'oid';
}
get baseFields() {
let obj = this;
return [{
id: 'name', label: gettext('Name'), cell: 'string',
type: 'text', cellHeaderClasses: 'width_percent_50', noEmpty: true,
},{
id: 'oid', label: gettext('OID'), cell: 'string',
editable: false, type: 'text', mode:['properties'],
},{
id: 'schema', label: gettext('Schema'), cell: 'string',
type: 'select', mode: ['create','edit'], node: 'schema',
noEmpty: true, options: this.fieldOptions.schemaList
},{
id: 'is_sys_obj', label: gettext('System FTS parser?'),
cell:'boolean', type: 'switch', mode: ['properties'],
},{
id: 'description', label: gettext('Comment'), cell: 'string',
type: 'multiline', cellHeaderClasses: 'width_percent_50',
},{
id: 'prsstart', label: gettext('Start function'),
group: gettext('Definition'), noEmpty: true,
readonly: function(state) { return !obj.isNew(state); },
type: (state) => {
return {
type: 'select',
options: obj.fieldOptions.prsstartList,
optionsLoaded: (options) => { obj.fieldOptions.prsstartList = options; },
controlProps: {
allowClear: true,
filter: (options) => {
let res = [];
if (state && obj.isNew(state)) {
options.forEach((option) => {
if(option && option.label == '') {
return;
}
res.push({ label: option.label, value: option.value });
});
} else {
res = options;
}
return res;
}
}
};
},
},{
id: 'prstoken', label: gettext('Get next token function'), group: gettext('Definition'),
noEmpty: true, readonly: function(state) { return !obj.isNew(state); },
type: (state) => {
return {
type: 'select',
options: obj.fieldOptions.prstokenList,
optionsLoaded: (options) => { obj.fieldOptions.prstokenList = options; },
controlProps: {
allowClear: true,
filter: (options) => {
let res = [];
if (state && obj.isNew(state)) {
options.forEach((option) => {
if(option && option.label == '') {
return;
}
res.push({ label: option.label, value: option.value });
});
} else {
res = options;
}
return res;
}
}
};
},
},{
id: 'prsend', label: gettext('End function'), group: gettext('Definition'),
noEmpty: true, readonly: function(state) { return !obj.isNew(state); },
type: (state) => {
return {
type: 'select',
options: obj.fieldOptions.prsendList,
optionsLoaded: (options) => { obj.fieldOptions.prsendList = options; },
controlProps: {
allowClear: true,
filter: (options) => {
let res = [];
if (state && obj.isNew(state)) {
options.forEach((option) => {
if(option && option.label == '') {
return;
}
res.push({ label: option.label, value: option.value });
});
} else {
res = options;
}
return res;
}
}
};
},
},{
id: 'prslextype', label: gettext('Lextypes function'), group: gettext('Definition'),
noEmpty: true, readonly: function(state) { return !obj.isNew(state); },
type: (state) => {
return {
type: 'select',
options: obj.fieldOptions.prslextypeList,
optionsLoaded: (options) => { obj.fieldOptions.prslextypeList = options; },
controlProps: {
allowClear: true,
filter: (options) => {
let res = [];
if (state && obj.isNew(state)) {
options.forEach((option) => {
if(option && option.label == '') {
return;
}
res.push({ label: option.label, value: option.value });
});
} else {
res = options;
}
return res;
}
}
};
},
},{
id: 'prsheadline', label: gettext('Headline function'), group: gettext('Definition'),
readonly: function(state) { return !obj.isNew(state); },
type: (state) => {
return {
type: 'select',
options: obj.fieldOptions.prsheadlineList,
optionsLoaded: (options) => { obj.fieldOptions.prsheadlineList = options; },
controlProps: {
allowClear: true,
filter: (options) => {
let res = [];
if (state && obj.isNew(state)) {
options.forEach((option) => {
if(option && option.label == '') {
return;
}
res.push({ label: option.label, value: option.value });
});
} else {
res = options;
}
return res;
}
}
};
},
}];
}
}

View File

@ -7,6 +7,9 @@
//
//////////////////////////////////////////////////////////////
import FTSTemplateSchema from './fts_template.ui';
import { getNodeAjaxOptions, getNodeListById } from '../../../../../../../static/js/node_ajax';
define('pgadmin.node.fts_template', [
'sources/gettext', 'sources/url_for', 'jquery', 'underscore',
'sources/pgadmin', 'pgadmin.browser', 'pgadmin.node.schema.dir/child',
@ -70,14 +73,6 @@ define('pgadmin.node.fts_template', [
// Defining backform model for fts template node
model: pgAdmin.Browser.Node.Model.extend({
idAttribute: 'oid',
defaults: {
name: undefined, // Fts template name
is_sys_obj: undefined, // Is system object
description: undefined, // Comment on template
schema: undefined, // Schema name to which template belongs
tmplinit: undefined, // Init function for fts template
tmpllexize: undefined, // Lexize function for fts template
},
initialize: function(attrs, args) {
var isNew = (_.size(attrs) === 0);
pgAdmin.Browser.Node.Model.prototype.initialize.apply(this, arguments);
@ -92,28 +87,9 @@ define('pgadmin.node.fts_template', [
},{
id: 'oid', label: gettext('OID'), cell: 'string',
editable: false, type: 'text', mode:['properties'],
},{
id: 'schema', label: gettext('Schema'), cell: 'string',
type: 'text', mode: ['create','edit'], node: 'schema',
control: 'node-list-by-id', cache_node: 'database',
cache_level: 'database',
},{
id: 'is_sys_obj', label: gettext('System FTS template?'),
cell:'boolean', type: 'switch', mode: ['properties'],
},{
id: 'description', label: gettext('Comment'), cell: 'string',
type: 'multiline', cellHeaderClasses: 'width_percent_50',
},{
id: 'tmplinit', label: gettext('Init function'),
group: gettext('Definition'), type: 'text', readonly: function(m) {
return !m.isNew();
}, control: 'node-ajax-options', url: 'get_init',
cache_level: 'database', cache_node: 'schema',
},{
id: 'tmpllexize', label: gettext('Lexize function'), group: gettext('Definition'),
type: 'text', readonly: function(m) { return !m.isNew(); },
control: 'node-ajax-options', url: 'get_lexize', cache_level: 'database',
cache_node: 'schema',
}],
/*
@ -153,6 +129,23 @@ define('pgadmin.node.fts_template', [
return null;
},
}),
getSchema: (treeNodeInfo, itemNodeData) => {
let nodeObj = pgAdmin.Browser.Nodes['fts_template'];
return new FTSTemplateSchema(
{
initFunctionList:()=>getNodeAjaxOptions('get_init', nodeObj, treeNodeInfo, itemNodeData, {
cacheLevel: 'database'
}),
lexisFunctionList:()=>getNodeAjaxOptions('get_lexize', nodeObj, treeNodeInfo, itemNodeData, {
cacheLevel: 'database'
}),
schemaList:()=>getNodeListById(pgBrowser.Nodes['schema'], treeNodeInfo, itemNodeData),
},
{
schema: treeNodeInfo.schema._id,
}
);
}
});
}

View File

@ -0,0 +1,117 @@
/////////////////////////////////////////////////////////////
//
// 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';
export default class FTSTemplateSchema extends BaseUISchema {
constructor(fieldOptions = {}, initValues) {
super({
name: null,
oid: undefined,
version: '',
schema: undefined,
description: '',
is_sys_obj: false,
tmplinit: undefined,
tmpllexize: undefined, // Lexize function for fts template
...initValues
});
this.fieldOptions = {
schemaList: [],
initFunctionList: [],
lexisFunctionList: [],
...fieldOptions,
};
}
get idAttribute() {
return 'oid';
}
get baseFields() {
let obj = this;
return [{
id: 'name', label: gettext('Name'), cell: 'string', type: 'text',
cellHeaderClasses: 'width_percent_50', noEmpty: true,
}, {
id: 'oid', label: gettext('OID'), cell: 'string',
editable: false, type: 'text', mode: ['properties'],
}, {
id: 'schema', label: gettext('Schema'), mode: ['create', 'edit'], node: 'schema',
type: 'select', editable: false, noEmpty: true, options: this.fieldOptions.schemaList,
}, {
id: 'is_sys_obj', label: gettext('System FTS template?'),
cell: 'boolean', type: 'switch', mode: ['properties'],
}, {
id: 'description', label: gettext('Comment'), cell: 'string',
type: 'multiline', cellHeaderClasses: 'width_percent_50',
}, {
id: 'tmplinit', label: gettext('Init function'), group: gettext('Definition'),
cache_level: 'database', cache_node: 'schema',
readonly: function (state) {
return !obj.isNew(state);
},
type: (state) => {
return {
type: 'select',
options: obj.fieldOptions.initFunctionList,
optionsLoaded: (options) => { obj.fieldOptions.initFunctionData = options; },
controlProps: {
allowClear: true,
filter: (options) => {
let res = [];
if (state && obj.isNew(state)) {
options.forEach((option) => {
if(option && option.label == '') {
return;
}
res.push({ label: option.label, value: option.value });
});
} else {
res = options;
}
return res;
}
}
};
},
}, {
id: 'tmpllexize', label: gettext('Lexize function'), group: gettext('Definition'),
noEmpty: true, cache_level: 'database', cache_node: 'schema',
readonly: function (state) {
return !obj.isNew(state);
},
type: (state) => {
return {
type: 'select',
options: obj.fieldOptions.lexisFunctionList,
optionsLoaded: (options) => { obj.fieldOptions.lexisFunctionData = options; },
controlProps: {
allowClear: true,
filter: (options) => {
let res = [];
if (state && obj.isNew(state)) {
options.forEach((option) => {
if(option && option.label == '') {
return;
}
res.push({ label: option.label, value: option.value });
});
} else {
res = options;
}
return res;
}
}
};
},
}];
}
}

View File

@ -0,0 +1,105 @@
/////////////////////////////////////////////////////////////
//
// 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 FTSParserSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/fts_parsers/static/js/fts_parser.ui';
describe('FTSParserSchema', ()=>{
let mount;
let schemaObj = new FTSParserSchema(
{
prsstartList: ()=> [{ label: '', value: ''}, { label: 'lb1', value: 'val1'}],
prstokenList: ()=> [{ label: '', value: ''}, { label: 'lb1', value: 'val1'}],
prsendList: ()=> [{ label: '', value: ''}, { label: 'lb1', value: 'val1'}],
prslextypeList: ()=> [{ label: '', value: ''}, { label: 'lb1', value: 'val1'}],
prsheadlineList: ()=> [{ label: '', value: ''}, { label: 'lb1', value: 'val1'}],
schemaList: ()=> [],
},
{
schema: 123
}
);
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: 'create',
}}
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={()=>{}}
/>);
});
});

View File

@ -0,0 +1,102 @@
/////////////////////////////////////////////////////////////
//
// 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 FTSTemplateSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/static/js/fts_template.ui';
describe('FTSTemplateSchema', ()=>{
let mount;
let schemaObj = new FTSTemplateSchema(
{
schemaList: ()=> [],
initFunctionList: ()=> [{ label: '', value: ''}, { label: 'lb1', value: 'val1'}],
lexisFunctionList: ()=> [{ label: '', value: ''}, { label: 'lb1', value: 'val1'}],
},
{
schema: 123
}
);
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: 'create',
}}
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={()=>{}}
/>);
});
});