mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fixed an issue where the index is not loaded in the Unique Constraint dialog. Fixes #6857
This commit is contained in:
committed by
Akshay Joshi
parent
40b8da8223
commit
7eaa3179ad
@@ -6,6 +6,7 @@ import { SCHEMA_STATE_ACTIONS } from '../../../../../../../../../../static/js/Sc
|
||||
import DataGridViewWithHeaderForm from '../../../../../../../../../../static/js/helpers/DataGridViewWithHeaderForm';
|
||||
import { getNodeAjaxOptions, getNodeListByName } from '../../../../../../../../../static/js/node_ajax';
|
||||
import { pgAlertify } from '../../../../../../../../../../static/js/helpers/legacyConnector';
|
||||
import TableSchema from '../../../../static/js/table.ui';
|
||||
|
||||
export function getNodeExclusionConstraintSchema(treeNodeInfo, itemNodeData, pgBrowser, noColumns=false) {
|
||||
let tableNode = pgBrowser.Nodes['table'];
|
||||
@@ -210,10 +211,10 @@ export default class ExclusionConstraintSchema extends BaseUISchema {
|
||||
}
|
||||
|
||||
get inTable() {
|
||||
if(_.isUndefined(this.nodeInfo)) {
|
||||
if(this.top && this.top instanceof TableSchema) {
|
||||
return true;
|
||||
}
|
||||
return _.isUndefined(this.nodeInfo['exclusion_constraint']);
|
||||
return false;
|
||||
}
|
||||
|
||||
initialise(data) {
|
||||
|
||||
@@ -5,8 +5,9 @@ import { isEmptyString } from 'sources/validators';
|
||||
import { SCHEMA_STATE_ACTIONS } from '../../../../../../../../../../static/js/SchemaView';
|
||||
import DataGridViewWithHeaderForm from '../../../../../../../../../../static/js/helpers/DataGridViewWithHeaderForm';
|
||||
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({
|
||||
local_column: noColumns ? [] : ()=>getNodeListByName('column', treeNodeInfo, itemNodeData),
|
||||
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,
|
||||
}));
|
||||
});
|
||||
});
|
||||
}, initData);
|
||||
}
|
||||
|
||||
class ForeignKeyHeaderSchema extends BaseUISchema {
|
||||
@@ -110,7 +111,7 @@ class ForeignKeyColumnSchema extends BaseUISchema {
|
||||
}
|
||||
|
||||
export default class ForeignKeySchema extends BaseUISchema {
|
||||
constructor(fieldOptions={}, nodeInfo, getColumns) {
|
||||
constructor(fieldOptions={}, nodeInfo, getColumns, initData={}) {
|
||||
super({
|
||||
name: undefined,
|
||||
reftab: undefined,
|
||||
@@ -124,9 +125,10 @@ export default class ForeignKeySchema extends BaseUISchema {
|
||||
columns: undefined,
|
||||
confupdtype: 'a',
|
||||
confdeltype: 'a',
|
||||
autoindex: ForeignKeySchema.checkInTable(nodeInfo) ? false : true,
|
||||
autoindex: true,
|
||||
coveringindex: undefined,
|
||||
hasindex:undefined,
|
||||
...initData,
|
||||
});
|
||||
|
||||
this.nodeInfo = nodeInfo;
|
||||
@@ -142,14 +144,10 @@ export default class ForeignKeySchema extends BaseUISchema {
|
||||
}
|
||||
|
||||
get inTable() {
|
||||
return ForeignKeySchema.checkInTable(this.nodeInfo);
|
||||
}
|
||||
|
||||
static checkInTable(nodeInfo) {
|
||||
if(_.isUndefined(nodeInfo)) {
|
||||
if(this.top && this.top instanceof TableSchema) {
|
||||
return true;
|
||||
}
|
||||
return _.isUndefined(nodeInfo['foreign_key']);
|
||||
return false;
|
||||
}
|
||||
|
||||
changeColumnOptions(columns) {
|
||||
|
||||
@@ -3,6 +3,7 @@ import BaseUISchema from 'sources/SchemaView/base_schema.ui';
|
||||
import _ from 'lodash';
|
||||
import { isEmptyString } from 'sources/validators';
|
||||
import { SCHEMA_STATE_ACTIONS } from '../../../../../../../../../../static/js/SchemaView';
|
||||
import TableSchema from '../../../../static/js/table.ui';
|
||||
export default class PrimaryKeySchema extends BaseUISchema {
|
||||
constructor(fieldOptions={}, nodeInfo) {
|
||||
super({
|
||||
@@ -28,10 +29,10 @@ export default class PrimaryKeySchema extends BaseUISchema {
|
||||
}
|
||||
|
||||
get inTable() {
|
||||
if(_.isUndefined(this.nodeInfo)) {
|
||||
if(this.top && this.top instanceof TableSchema) {
|
||||
return true;
|
||||
}
|
||||
return _.isUndefined(this.nodeInfo['primary_key']);
|
||||
return false;
|
||||
}
|
||||
|
||||
changeColumnOptions(columns) {
|
||||
@@ -193,9 +194,9 @@ export default class PrimaryKeySchema extends BaseUISchema {
|
||||
id: 'index', label: gettext('Index'),
|
||||
mode: ['create'],
|
||||
type: 'select', group: gettext('Definition'),
|
||||
options: this.fieldOptions.index,
|
||||
controlProps:{
|
||||
allowClear:true,
|
||||
options: this.fieldOptions.index,
|
||||
},
|
||||
readonly: function() {
|
||||
if(!obj.isNew()) {
|
||||
|
||||
@@ -3,6 +3,7 @@ import BaseUISchema from 'sources/SchemaView/base_schema.ui';
|
||||
import _ from 'lodash';
|
||||
import { isEmptyString } from 'sources/validators';
|
||||
import { SCHEMA_STATE_ACTIONS } from '../../../../../../../../../../static/js/SchemaView';
|
||||
import TableSchema from '../../../../static/js/table.ui';
|
||||
|
||||
export default class UniqueConstraintSchema extends BaseUISchema {
|
||||
constructor(fieldOptions={}, nodeInfo) {
|
||||
@@ -29,10 +30,10 @@ export default class UniqueConstraintSchema extends BaseUISchema {
|
||||
}
|
||||
|
||||
get inTable() {
|
||||
if(_.isUndefined(this.nodeInfo)) {
|
||||
if(this.top && this.top instanceof TableSchema) {
|
||||
return true;
|
||||
}
|
||||
return _.isUndefined(this.nodeInfo['unique_constraint']);
|
||||
return false;
|
||||
}
|
||||
|
||||
changeColumnOptions(columns) {
|
||||
@@ -196,9 +197,9 @@ export default class UniqueConstraintSchema extends BaseUISchema {
|
||||
id: 'index', label: gettext('Index'),
|
||||
mode: ['create'],
|
||||
type: 'select', group: gettext('Definition'),
|
||||
options: this.fieldOptions.index,
|
||||
controlProps:{
|
||||
allowClear:true,
|
||||
options: this.fieldOptions.index,
|
||||
},
|
||||
readonly: function() {
|
||||
if(!obj.isNew()) {
|
||||
|
||||
@@ -48,7 +48,7 @@ export function getNodeTableSchema(treeNodeInfo, itemNodeData, pgBrowser) {
|
||||
vacuum_settings: ()=>getNodeVacuumSettingsSchema(tableNode, treeNodeInfo, itemNodeData),
|
||||
constraints: ()=>new ConstraintsSchema(
|
||||
treeNodeInfo,
|
||||
()=>getNodeForeignKeySchema(treeNodeInfo, itemNodeData, pgBrowser, true),
|
||||
()=>getNodeForeignKeySchema(treeNodeInfo, itemNodeData, pgBrowser, true, {autoindex: false}),
|
||||
()=>getNodeExclusionConstraintSchema(treeNodeInfo, itemNodeData, pgBrowser, true),
|
||||
{spcname: spcname},
|
||||
),
|
||||
@@ -275,8 +275,8 @@ export class LikeSchema extends BaseUISchema {
|
||||
}
|
||||
|
||||
export default class TableSchema extends BaseUISchema {
|
||||
constructor(fieldOptions={}, nodeInfo, schemas, getPrivilegeRoleSchema, getColumns,
|
||||
getCollations, getOperatorClass, getAttachTables, initValues) {
|
||||
constructor(fieldOptions={}, nodeInfo, schemas={}, getPrivilegeRoleSchema=()=>{}, getColumns=()=>[],
|
||||
getCollations=()=>[], getOperatorClass=()=>[], getAttachTables=()=>[], initValues={}) {
|
||||
super({
|
||||
name: undefined,
|
||||
oid: undefined,
|
||||
@@ -321,9 +321,9 @@ export default class TableSchema extends BaseUISchema {
|
||||
this.getColumns = getColumns;
|
||||
|
||||
this.partitionsObj = new PartitionsSchema(this.nodeInfo, getCollations, getOperatorClass, getAttachTables);
|
||||
this.constraintsObj = this.schemas.constraints();
|
||||
this.columnsSchema = this.schemas.columns();
|
||||
this.vacuumSettingsSchema = this.schemas.vacuum_settings();
|
||||
this.constraintsObj = this.schemas.constraints && this.schemas.constraints() || {};
|
||||
this.columnsSchema = this.schemas.columns && this.schemas.columns() || {};
|
||||
this.vacuumSettingsSchema = this.schemas.vacuum_settings && this.schemas.vacuum_settings() || {};
|
||||
this.partitionKeysObj = new PartitionKeysSchema([], getCollations, getOperatorClass);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 * as legacyConnector from 'sources/helpers/legacyConnector';
|
||||
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 {
|
||||
constructor(schemaObj) {
|
||||
@@ -196,6 +197,7 @@ describe('ExclusionConstraintSchema', ()=>{
|
||||
it('depChange', ()=>{
|
||||
let state = {columns: [{local_column: 'id'}]};
|
||||
|
||||
schemaObj.top = new TableSchema({}, null);
|
||||
expect(getFieldDepChange(schemaObj, 'columns')(state, ['columns', 0], null, {
|
||||
type: SCHEMA_STATE_ACTIONS.DELETE_ROW,
|
||||
oldState: {
|
||||
|
||||
@@ -18,6 +18,7 @@ import BaseUISchema from '../../../pgadmin/static/js/SchemaView/base_schema.ui';
|
||||
import _ from 'lodash';
|
||||
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 TableSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.ui';
|
||||
|
||||
class SchemaInColl extends BaseUISchema {
|
||||
constructor(schemaObj) {
|
||||
@@ -197,8 +198,7 @@ describe('ForeignKeySchema', ()=>{
|
||||
expect(getFieldDepChange(schemaObj, 'autoindex')(state, null, null, actionObj)).toEqual({});
|
||||
|
||||
state.oid = null;
|
||||
schemaObj.nodeInfo = {table: {}};
|
||||
schemaObj.top = schemaObj;
|
||||
schemaObj.top = new TableSchema({}, null);
|
||||
expect(getFieldDepChange(schemaObj, 'autoindex')(state, null, null, actionObj)).toEqual({
|
||||
autoindex: false,
|
||||
coveringindex: '',
|
||||
|
||||
@@ -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 _ from 'lodash';
|
||||
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 {
|
||||
constructor(schemaObj) {
|
||||
@@ -172,6 +173,7 @@ describe('PrimaryKeySchema', ()=>{
|
||||
expect(getFieldDepChange(schemaObj, 'condeferrable')(state)).toEqual({});
|
||||
expect(getFieldDepChange(schemaObj, 'condeferred')(state)).toEqual({});
|
||||
|
||||
schemaObj.top = new TableSchema({}, null);
|
||||
expect(getFieldDepChange(schemaObj, 'columns')(state, ['columns', 0], null, {
|
||||
type: SCHEMA_STATE_ACTIONS.DELETE_ROW,
|
||||
oldState: {
|
||||
|
||||
@@ -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 _ from 'lodash';
|
||||
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 {
|
||||
constructor(schemaObj) {
|
||||
@@ -171,6 +172,7 @@ describe('UniqueConstraintSchema', ()=>{
|
||||
expect(getFieldDepChange(schemaObj, 'condeferrable')(state)).toEqual({});
|
||||
expect(getFieldDepChange(schemaObj, 'condeferred')(state)).toEqual({});
|
||||
|
||||
schemaObj.top = new TableSchema({}, null);
|
||||
expect(getFieldDepChange(schemaObj, 'columns')(state, ['columns', 0], null, {
|
||||
type: SCHEMA_STATE_ACTIONS.DELETE_ROW,
|
||||
oldState: {
|
||||
|
||||
Reference in New Issue
Block a user