mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fixed an issue where user was not able to assign new/old columns as primary key once column with primary key is deleted. #5749
This commit is contained in:
parent
fc411bfc49
commit
73430a2062
@ -165,7 +165,7 @@ export default class ColumnSchema extends BaseUISchema {
|
||||
// Need to show this field only when creating new table
|
||||
// [in SubNode control]
|
||||
id: 'is_primary_key', label: gettext('Primary key?'),
|
||||
cell: 'switch', type: 'switch', width: 100, disableResizing: true, deps:['name'],
|
||||
cell: 'switch', type: 'switch', width: 100, disableResizing: true, deps:['name', ['primary_key']],
|
||||
visible: ()=>{
|
||||
return obj.top?.nodeInfo && _.isUndefined(
|
||||
obj.top.nodeInfo['table'] || obj.top.nodeInfo['view'] ||
|
||||
@ -178,13 +178,13 @@ export default class ColumnSchema extends BaseUISchema {
|
||||
// - Table is a partitioned table
|
||||
if (
|
||||
obj.top && ((
|
||||
!_.isUndefined(obj.top.origData['oid'])
|
||||
&& !_.isUndefined(obj.top.origData['primary_key'])
|
||||
&& obj.top.origData['primary_key'].length > 0
|
||||
&& !_.isUndefined(obj.top.origData['primary_key'][0]['oid'])
|
||||
!_.isUndefined(obj.top.sessData['oid'])
|
||||
&& !_.isUndefined(obj.top.sessData['primary_key'])
|
||||
&& obj.top.sessData['primary_key'].length > 0
|
||||
&& !_.isUndefined(obj.top.sessData['primary_key'][0]['oid'])
|
||||
) || (
|
||||
'is_partitioned' in obj.top.origData
|
||||
&& obj.top.origData['is_partitioned']
|
||||
'is_partitioned' in obj.top.sessData
|
||||
&& obj.top.sessData['is_partitioned']
|
||||
&& obj.getServerVersion() < 11000
|
||||
))
|
||||
) {
|
||||
@ -200,10 +200,10 @@ export default class ColumnSchema extends BaseUISchema {
|
||||
// If primary key already exist then disable.
|
||||
if (
|
||||
obj.top && (
|
||||
!_.isUndefined(obj.top.origData['oid'])
|
||||
&& !_.isUndefined(obj.top.origData['primary_key'])
|
||||
&& obj.top.origData['primary_key'].length > 0
|
||||
&& !_.isUndefined(obj.top.origData['primary_key'][0]['oid'])
|
||||
!_.isUndefined(obj.top.sessData['oid'])
|
||||
&& !_.isUndefined(obj.top.sessData['primary_key'])
|
||||
&& obj.top.sessData['primary_key'].length > 0
|
||||
&& !_.isUndefined(obj.top.sessData['primary_key'][0]['oid'])
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
@ -212,8 +212,8 @@ export default class ColumnSchema extends BaseUISchema {
|
||||
// If table is partitioned table then disable
|
||||
if(
|
||||
obj.top && (
|
||||
'is_partitioned' in obj.top.origData
|
||||
&& obj.top.origData['is_partitioned']
|
||||
'is_partitioned' in obj.top.sessData
|
||||
&& obj.top.sessData['is_partitioned']
|
||||
&& obj.getServerVersion() < 11000)
|
||||
) {
|
||||
return false;
|
||||
|
@ -113,7 +113,7 @@ export class ConstraintsSchema extends BaseUISchema {
|
||||
schema: this.primaryKeyObj,
|
||||
editable: false, type: 'collection',
|
||||
group: gettext('Primary Key'), mode: ['edit', 'create'],
|
||||
canEdit: true, canDelete: true, deps:['is_partitioned', 'typname'],
|
||||
canEdit: true, canDelete: true, deps:['is_partitioned', 'typname', 'columns'],
|
||||
columns : ['name', 'columns'],
|
||||
disabled: this.inCatalog,
|
||||
canAdd: function(state) {
|
||||
@ -136,6 +136,20 @@ export class ConstraintsSchema extends BaseUISchema {
|
||||
}));
|
||||
return {columns: state.columns};
|
||||
}
|
||||
/* If column or primary key is deleted */
|
||||
if(actionObj.type === SCHEMA_STATE_ACTIONS.DELETE_ROW) {
|
||||
let deletedColumn = _.differenceBy(actionObj.oldState.columns,state.columns,'cid');
|
||||
if(deletedColumn.length && deletedColumn[0].is_primary_key && !obj.top.isNew(state)) {
|
||||
state.columns = state.columns.map(c=>({
|
||||
...c, is_primary_key: false
|
||||
}));
|
||||
return {primary_key: []};
|
||||
} else if(source[0] === 'primary_key') {
|
||||
state.columns = state.columns.map(c=>({
|
||||
...c, is_primary_key: false
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
},{
|
||||
id: 'foreign_key', label: '',
|
||||
|
@ -515,8 +515,6 @@ function SchemaDialogView({
|
||||
useEffect(()=>{
|
||||
/* if sessData changes, validate the schema */
|
||||
if(!formReady) return;
|
||||
/* Set the _sessData, can be usefull to some deep controls */
|
||||
schema._sessData = sessData;
|
||||
let isNotValid = validateSchema(schema, sessData, (path, message)=>{
|
||||
if(message) {
|
||||
setFormErr({
|
||||
@ -779,6 +777,8 @@ function SchemaDialogView({
|
||||
};
|
||||
|
||||
let ButtonIcon = getButtonIcon();
|
||||
/* Set the _sessData, can be usefull to some deep controls */
|
||||
schema._sessData = sessData;
|
||||
|
||||
/* I am Groot */
|
||||
return (
|
||||
|
Loading…
Reference in New Issue
Block a user