Fixed an issue where the index is not loaded in the Unique Constraint dialog. Fixes #6857

This commit is contained in:
Aditya Toshniwal
2021-10-04 19:28:27 +05:30
committed by Akshay Joshi
parent 40b8da8223
commit 7eaa3179ad
9 changed files with 33 additions and 26 deletions

View File

@@ -6,6 +6,7 @@ import { SCHEMA_STATE_ACTIONS } from '../../../../../../../../../../static/js/Sc
import DataGridViewWithHeaderForm from '../../../../../../../../../../static/js/helpers/DataGridViewWithHeaderForm'; import DataGridViewWithHeaderForm from '../../../../../../../../../../static/js/helpers/DataGridViewWithHeaderForm';
import { getNodeAjaxOptions, getNodeListByName } from '../../../../../../../../../static/js/node_ajax'; import { getNodeAjaxOptions, getNodeListByName } from '../../../../../../../../../static/js/node_ajax';
import { pgAlertify } from '../../../../../../../../../../static/js/helpers/legacyConnector'; import { pgAlertify } from '../../../../../../../../../../static/js/helpers/legacyConnector';
import TableSchema from '../../../../static/js/table.ui';
export function getNodeExclusionConstraintSchema(treeNodeInfo, itemNodeData, pgBrowser, noColumns=false) { export function getNodeExclusionConstraintSchema(treeNodeInfo, itemNodeData, pgBrowser, noColumns=false) {
let tableNode = pgBrowser.Nodes['table']; let tableNode = pgBrowser.Nodes['table'];
@@ -210,10 +211,10 @@ export default class ExclusionConstraintSchema extends BaseUISchema {
} }
get inTable() { get inTable() {
if(_.isUndefined(this.nodeInfo)) { if(this.top && this.top instanceof TableSchema) {
return true; return true;
} }
return _.isUndefined(this.nodeInfo['exclusion_constraint']); return false;
} }
initialise(data) { initialise(data) {

View File

@@ -5,8 +5,9 @@ import { isEmptyString } from 'sources/validators';
import { SCHEMA_STATE_ACTIONS } from '../../../../../../../../../../static/js/SchemaView'; import { SCHEMA_STATE_ACTIONS } from '../../../../../../../../../../static/js/SchemaView';
import DataGridViewWithHeaderForm from '../../../../../../../../../../static/js/helpers/DataGridViewWithHeaderForm'; import DataGridViewWithHeaderForm from '../../../../../../../../../../static/js/helpers/DataGridViewWithHeaderForm';
import { getNodeAjaxOptions, getNodeListByName } from '../../../../../../../../../static/js/node_ajax'; import { getNodeAjaxOptions, getNodeListByName } from '../../../../../../../../../static/js/node_ajax';
import TableSchema from '../../../../static/js/table.ui';
export function getNodeForeignKeySchema(treeNodeInfo, itemNodeData, pgBrowser, noColumns=false) { export function getNodeForeignKeySchema(treeNodeInfo, itemNodeData, pgBrowser, noColumns=false, initData={}) {
return new ForeignKeySchema({ return new ForeignKeySchema({
local_column: noColumns ? [] : ()=>getNodeListByName('column', treeNodeInfo, itemNodeData), local_column: noColumns ? [] : ()=>getNodeListByName('column', treeNodeInfo, itemNodeData),
references: ()=>getNodeAjaxOptions('all_tables', pgBrowser.Nodes['table'], treeNodeInfo, itemNodeData, {cacheLevel: 'server'}, (rows)=>{ references: ()=>getNodeAjaxOptions('all_tables', pgBrowser.Nodes['table'], treeNodeInfo, itemNodeData, {cacheLevel: 'server'}, (rows)=>{
@@ -27,7 +28,7 @@ export function getNodeForeignKeySchema(treeNodeInfo, itemNodeData, pgBrowser, n
'label': r.name, 'label': r.name,
})); }));
}); });
}); }, initData);
} }
class ForeignKeyHeaderSchema extends BaseUISchema { class ForeignKeyHeaderSchema extends BaseUISchema {
@@ -110,7 +111,7 @@ class ForeignKeyColumnSchema extends BaseUISchema {
} }
export default class ForeignKeySchema extends BaseUISchema { export default class ForeignKeySchema extends BaseUISchema {
constructor(fieldOptions={}, nodeInfo, getColumns) { constructor(fieldOptions={}, nodeInfo, getColumns, initData={}) {
super({ super({
name: undefined, name: undefined,
reftab: undefined, reftab: undefined,
@@ -124,9 +125,10 @@ export default class ForeignKeySchema extends BaseUISchema {
columns: undefined, columns: undefined,
confupdtype: 'a', confupdtype: 'a',
confdeltype: 'a', confdeltype: 'a',
autoindex: ForeignKeySchema.checkInTable(nodeInfo) ? false : true, autoindex: true,
coveringindex: undefined, coveringindex: undefined,
hasindex:undefined, hasindex:undefined,
...initData,
}); });
this.nodeInfo = nodeInfo; this.nodeInfo = nodeInfo;
@@ -142,14 +144,10 @@ export default class ForeignKeySchema extends BaseUISchema {
} }
get inTable() { get inTable() {
return ForeignKeySchema.checkInTable(this.nodeInfo); if(this.top && this.top instanceof TableSchema) {
}
static checkInTable(nodeInfo) {
if(_.isUndefined(nodeInfo)) {
return true; return true;
} }
return _.isUndefined(nodeInfo['foreign_key']); return false;
} }
changeColumnOptions(columns) { changeColumnOptions(columns) {

View File

@@ -3,6 +3,7 @@ import BaseUISchema from 'sources/SchemaView/base_schema.ui';
import _ from 'lodash'; import _ from 'lodash';
import { isEmptyString } from 'sources/validators'; import { isEmptyString } from 'sources/validators';
import { SCHEMA_STATE_ACTIONS } from '../../../../../../../../../../static/js/SchemaView'; import { SCHEMA_STATE_ACTIONS } from '../../../../../../../../../../static/js/SchemaView';
import TableSchema from '../../../../static/js/table.ui';
export default class PrimaryKeySchema extends BaseUISchema { export default class PrimaryKeySchema extends BaseUISchema {
constructor(fieldOptions={}, nodeInfo) { constructor(fieldOptions={}, nodeInfo) {
super({ super({
@@ -28,10 +29,10 @@ export default class PrimaryKeySchema extends BaseUISchema {
} }
get inTable() { get inTable() {
if(_.isUndefined(this.nodeInfo)) { if(this.top && this.top instanceof TableSchema) {
return true; return true;
} }
return _.isUndefined(this.nodeInfo['primary_key']); return false;
} }
changeColumnOptions(columns) { changeColumnOptions(columns) {
@@ -193,9 +194,9 @@ export default class PrimaryKeySchema extends BaseUISchema {
id: 'index', label: gettext('Index'), id: 'index', label: gettext('Index'),
mode: ['create'], mode: ['create'],
type: 'select', group: gettext('Definition'), type: 'select', group: gettext('Definition'),
options: this.fieldOptions.index,
controlProps:{ controlProps:{
allowClear:true, allowClear:true,
options: this.fieldOptions.index,
}, },
readonly: function() { readonly: function() {
if(!obj.isNew()) { if(!obj.isNew()) {

View File

@@ -3,6 +3,7 @@ import BaseUISchema from 'sources/SchemaView/base_schema.ui';
import _ from 'lodash'; import _ from 'lodash';
import { isEmptyString } from 'sources/validators'; import { isEmptyString } from 'sources/validators';
import { SCHEMA_STATE_ACTIONS } from '../../../../../../../../../../static/js/SchemaView'; import { SCHEMA_STATE_ACTIONS } from '../../../../../../../../../../static/js/SchemaView';
import TableSchema from '../../../../static/js/table.ui';
export default class UniqueConstraintSchema extends BaseUISchema { export default class UniqueConstraintSchema extends BaseUISchema {
constructor(fieldOptions={}, nodeInfo) { constructor(fieldOptions={}, nodeInfo) {
@@ -29,10 +30,10 @@ export default class UniqueConstraintSchema extends BaseUISchema {
} }
get inTable() { get inTable() {
if(_.isUndefined(this.nodeInfo)) { if(this.top && this.top instanceof TableSchema) {
return true; return true;
} }
return _.isUndefined(this.nodeInfo['unique_constraint']); return false;
} }
changeColumnOptions(columns) { changeColumnOptions(columns) {
@@ -196,9 +197,9 @@ export default class UniqueConstraintSchema extends BaseUISchema {
id: 'index', label: gettext('Index'), id: 'index', label: gettext('Index'),
mode: ['create'], mode: ['create'],
type: 'select', group: gettext('Definition'), type: 'select', group: gettext('Definition'),
options: this.fieldOptions.index,
controlProps:{ controlProps:{
allowClear:true, allowClear:true,
options: this.fieldOptions.index,
}, },
readonly: function() { readonly: function() {
if(!obj.isNew()) { if(!obj.isNew()) {

View File

@@ -48,7 +48,7 @@ export function getNodeTableSchema(treeNodeInfo, itemNodeData, pgBrowser) {
vacuum_settings: ()=>getNodeVacuumSettingsSchema(tableNode, treeNodeInfo, itemNodeData), vacuum_settings: ()=>getNodeVacuumSettingsSchema(tableNode, treeNodeInfo, itemNodeData),
constraints: ()=>new ConstraintsSchema( constraints: ()=>new ConstraintsSchema(
treeNodeInfo, treeNodeInfo,
()=>getNodeForeignKeySchema(treeNodeInfo, itemNodeData, pgBrowser, true), ()=>getNodeForeignKeySchema(treeNodeInfo, itemNodeData, pgBrowser, true, {autoindex: false}),
()=>getNodeExclusionConstraintSchema(treeNodeInfo, itemNodeData, pgBrowser, true), ()=>getNodeExclusionConstraintSchema(treeNodeInfo, itemNodeData, pgBrowser, true),
{spcname: spcname}, {spcname: spcname},
), ),
@@ -275,8 +275,8 @@ export class LikeSchema extends BaseUISchema {
} }
export default class TableSchema extends BaseUISchema { export default class TableSchema extends BaseUISchema {
constructor(fieldOptions={}, nodeInfo, schemas, getPrivilegeRoleSchema, getColumns, constructor(fieldOptions={}, nodeInfo, schemas={}, getPrivilegeRoleSchema=()=>{}, getColumns=()=>[],
getCollations, getOperatorClass, getAttachTables, initValues) { getCollations=()=>[], getOperatorClass=()=>[], getAttachTables=()=>[], initValues={}) {
super({ super({
name: undefined, name: undefined,
oid: undefined, oid: undefined,
@@ -321,9 +321,9 @@ export default class TableSchema extends BaseUISchema {
this.getColumns = getColumns; this.getColumns = getColumns;
this.partitionsObj = new PartitionsSchema(this.nodeInfo, getCollations, getOperatorClass, getAttachTables); this.partitionsObj = new PartitionsSchema(this.nodeInfo, getCollations, getOperatorClass, getAttachTables);
this.constraintsObj = this.schemas.constraints(); this.constraintsObj = this.schemas.constraints && this.schemas.constraints() || {};
this.columnsSchema = this.schemas.columns(); this.columnsSchema = this.schemas.columns && this.schemas.columns() || {};
this.vacuumSettingsSchema = this.schemas.vacuum_settings(); this.vacuumSettingsSchema = this.schemas.vacuum_settings && this.schemas.vacuum_settings() || {};
this.partitionKeysObj = new PartitionKeysSchema([], getCollations, getOperatorClass); this.partitionKeysObj = new PartitionKeysSchema([], getCollations, getOperatorClass);
} }

View File

@@ -19,6 +19,7 @@ import _ from 'lodash';
import { getNodeExclusionConstraintSchema } from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/static/js/exclusion_constraint.ui'; import { getNodeExclusionConstraintSchema } from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/static/js/exclusion_constraint.ui';
import * as legacyConnector from 'sources/helpers/legacyConnector'; import * as legacyConnector from 'sources/helpers/legacyConnector';
import * as nodeAjax from '../../../pgadmin/browser/static/js/node_ajax'; import * as nodeAjax from '../../../pgadmin/browser/static/js/node_ajax';
import TableSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.ui';
class SchemaInColl extends BaseUISchema { class SchemaInColl extends BaseUISchema {
constructor(schemaObj) { constructor(schemaObj) {
@@ -196,6 +197,7 @@ describe('ExclusionConstraintSchema', ()=>{
it('depChange', ()=>{ it('depChange', ()=>{
let state = {columns: [{local_column: 'id'}]}; let state = {columns: [{local_column: 'id'}]};
schemaObj.top = new TableSchema({}, null);
expect(getFieldDepChange(schemaObj, 'columns')(state, ['columns', 0], null, { expect(getFieldDepChange(schemaObj, 'columns')(state, ['columns', 0], null, {
type: SCHEMA_STATE_ACTIONS.DELETE_ROW, type: SCHEMA_STATE_ACTIONS.DELETE_ROW,
oldState: { oldState: {

View File

@@ -18,6 +18,7 @@ import BaseUISchema from '../../../pgadmin/static/js/SchemaView/base_schema.ui';
import _ from 'lodash'; import _ from 'lodash';
import * as nodeAjax from '../../../pgadmin/browser/static/js/node_ajax'; import * as nodeAjax from '../../../pgadmin/browser/static/js/node_ajax';
import { getNodeForeignKeySchema } from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.ui'; import { getNodeForeignKeySchema } from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.ui';
import TableSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.ui';
class SchemaInColl extends BaseUISchema { class SchemaInColl extends BaseUISchema {
constructor(schemaObj) { constructor(schemaObj) {
@@ -197,8 +198,7 @@ describe('ForeignKeySchema', ()=>{
expect(getFieldDepChange(schemaObj, 'autoindex')(state, null, null, actionObj)).toEqual({}); expect(getFieldDepChange(schemaObj, 'autoindex')(state, null, null, actionObj)).toEqual({});
state.oid = null; state.oid = null;
schemaObj.nodeInfo = {table: {}}; schemaObj.top = new TableSchema({}, null);
schemaObj.top = schemaObj;
expect(getFieldDepChange(schemaObj, 'autoindex')(state, null, null, actionObj)).toEqual({ expect(getFieldDepChange(schemaObj, 'autoindex')(state, null, null, actionObj)).toEqual({
autoindex: false, autoindex: false,
coveringindex: '', coveringindex: '',

View File

@@ -17,6 +17,7 @@ import SchemaView, { SCHEMA_STATE_ACTIONS } from '../../../pgadmin/static/js/Sch
import BaseUISchema from '../../../pgadmin/static/js/SchemaView/base_schema.ui'; import BaseUISchema from '../../../pgadmin/static/js/SchemaView/base_schema.ui';
import _ from 'lodash'; import _ from 'lodash';
import PrimaryKeySchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/static/js/primary_key.ui'; import PrimaryKeySchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/static/js/primary_key.ui';
import TableSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.ui';
class SchemaInColl extends BaseUISchema { class SchemaInColl extends BaseUISchema {
constructor(schemaObj) { constructor(schemaObj) {
@@ -172,6 +173,7 @@ describe('PrimaryKeySchema', ()=>{
expect(getFieldDepChange(schemaObj, 'condeferrable')(state)).toEqual({}); expect(getFieldDepChange(schemaObj, 'condeferrable')(state)).toEqual({});
expect(getFieldDepChange(schemaObj, 'condeferred')(state)).toEqual({}); expect(getFieldDepChange(schemaObj, 'condeferred')(state)).toEqual({});
schemaObj.top = new TableSchema({}, null);
expect(getFieldDepChange(schemaObj, 'columns')(state, ['columns', 0], null, { expect(getFieldDepChange(schemaObj, 'columns')(state, ['columns', 0], null, {
type: SCHEMA_STATE_ACTIONS.DELETE_ROW, type: SCHEMA_STATE_ACTIONS.DELETE_ROW,
oldState: { oldState: {

View File

@@ -17,6 +17,7 @@ import SchemaView, { SCHEMA_STATE_ACTIONS } from '../../../pgadmin/static/js/Sch
import BaseUISchema from '../../../pgadmin/static/js/SchemaView/base_schema.ui'; import BaseUISchema from '../../../pgadmin/static/js/SchemaView/base_schema.ui';
import _ from 'lodash'; import _ from 'lodash';
import UniqueConstraintSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/static/js/unique_constraint.ui'; import UniqueConstraintSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/static/js/unique_constraint.ui';
import TableSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.ui';
class SchemaInColl extends BaseUISchema { class SchemaInColl extends BaseUISchema {
constructor(schemaObj) { constructor(schemaObj) {
@@ -171,6 +172,7 @@ describe('UniqueConstraintSchema', ()=>{
expect(getFieldDepChange(schemaObj, 'condeferrable')(state)).toEqual({}); expect(getFieldDepChange(schemaObj, 'condeferrable')(state)).toEqual({});
expect(getFieldDepChange(schemaObj, 'condeferred')(state)).toEqual({}); expect(getFieldDepChange(schemaObj, 'condeferred')(state)).toEqual({});
schemaObj.top = new TableSchema({}, null);
expect(getFieldDepChange(schemaObj, 'columns')(state, ['columns', 0], null, { expect(getFieldDepChange(schemaObj, 'columns')(state, ['columns', 0], null, {
type: SCHEMA_STATE_ACTIONS.DELETE_ROW, type: SCHEMA_STATE_ACTIONS.DELETE_ROW,
oldState: { oldState: {