Skip to content

Commit

Permalink
Merge pull request #77 from open-source-labs/bryan/updatecolumnstate
Browse files Browse the repository at this point in the history
added state updates when the user hits save while updating column
  • Loading branch information
mkchang168 authored Apr 28, 2022
2 parents 274f434 + 1017197 commit 70f5ac2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<img src="./assets/readmeImages/logo_readme.png" height=300/>

[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/oslabs-beta/SeeQR)
![Release: 7.0.0](https://img.shields.io/badge/Release-7.0.0-red)
![Release: 7.0.1](https://img.shields.io/badge/Release-7.0.1-red)
![License: MIT](https://img.shields.io/badge/License-MIT-orange.svg)
![Contributions Welcome](https://img.shields.io/badge/Contributions-welcome-blue.svg)
[![Twitter](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Ftwitter.com%2Ftheseeqr)](https://twitter.com/theseeqr)
Expand Down
15 changes: 15 additions & 0 deletions frontend/components/views/ERTables/TableFieldNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ function TableField({ data }: TableFieldProps) {
) as HTMLSelectElement;
if (column_name !== columnNameInput.value) {
alterColumnsObj.new_column_name = columnNameInput.value;
schemaStateCopy.tableList[i].columns[j].column_name =
columnNameInput.value;
schemaStateCopy.tableList[i].columns[j].new_column_name =
columnNameInput.value;
if (constraint_type === 'PRIMARY KEY') alterColumnsObj.rename_constraint = `pk_${alterTablesObj.table_name}${column_name}`;
Expand All @@ -174,6 +176,7 @@ function TableField({ data }: TableFieldProps) {
`allow-null-chkbox-${tableColumn}`
) as HTMLInputElement;
const isNullableString: 'YES' | 'NO' = isNullable.checked ? 'YES' : 'NO';
schemaStateCopy.tableList[i].columns[j].is_nullable = isNullableString;
alterColumnsObj.is_nullable =
isNull !== isNullableString ? isNullableString : null;

Expand Down Expand Up @@ -230,6 +233,8 @@ function TableField({ data }: TableFieldProps) {
constraint_type === 'PRIMARY KEY' &&
pkCheckBox.checked === false
) {
// modify state to remove constraint
schemaStateCopy.tableList[i].columns[j].constraint_type = null;
// add the PK constraint name to the drop constraint array
alterColumnsObj.drop_constraint.push(
`PK_${data.tableName + column_name}`
Expand All @@ -239,6 +244,8 @@ function TableField({ data }: TableFieldProps) {
constraint_type !== 'PRIMARY KEY' &&
pkCheckBox.checked === true
) {
// modify state to remove constraint
schemaStateCopy.tableList[i].columns[j].constraint_type = 'PRIMARY KEY';
// create a copy in case multiple constraints are added
const addConstraintObjCopy: AddConstraintObjType = { ...addConstraintObj };
// name the constraint PK_<tableNamecolumn_name>
Expand All @@ -259,6 +266,8 @@ function TableField({ data }: TableFieldProps) {
constraint_type === 'FOREIGN KEY' &&
fkCheckBox.checked === false
) {
// modify state to remove constraint
schemaStateCopy.tableList[i].columns[j].constraint_type = null;
// add the fk constraint name to the drop constraint array
alterColumnsObj.drop_constraint.push(
`FK_${data.tableName + column_name}`
Expand All @@ -267,6 +276,8 @@ function TableField({ data }: TableFieldProps) {
constraint_type !== 'FOREIGN KEY' &&
fkCheckBox.checked === true
) {
// modify state to add constraint
schemaStateCopy.tableList[i].columns[j].constraint_type = 'FOREIGN KEY';
const addConstraintObjCopy = { ...addConstraintObj };
// name the constraint FK_<tableNameColumn_name>
addConstraintObjCopy.constraint_name = `fk_${data.tableName + column_name
Expand All @@ -292,12 +303,16 @@ function TableField({ data }: TableFieldProps) {
// handle unique constraint
const uniqueCheckBox = document.getElementById(`unique-chkbox-${tableColumn}`) as HTMLInputElement;
if (constraint_type === 'UNIQUE' && uniqueCheckBox.checked === false) {
// modify state to remove constraint
schemaStateCopy.tableList[i].columns[j].constraint_type = null;
// add the unique constraint name to the drop constraint array
alterColumnsObj.drop_constraint.push(
`unique_${data.tableName + column_name}`
);
}
else if (constraint_type !== 'UNIQUE' && uniqueCheckBox.checked === true) {
// modify state to add constraint
schemaStateCopy.tableList[i].columns[j].constraint_type = 'UNIQUE';
// create a copy in case multiple constraints are added
const addConstraintObjCopy: AddConstraintObjType = { ...addConstraintObj };
// name the constraint PK_<tableNamecolumn_name>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "seeqr",
"productName": "SeeQR App",
"version": "7.0.0",
"version": "7.0.1",
"description": "SQL Toolbox - Model Implementer, Execution Plan Visualizer and Query Comparison Tool",
"main": "./tsCompiled/backend/main.js",
"babel": {
Expand Down

0 comments on commit 70f5ac2

Please sign in to comment.