Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added state updates when the user hits save while updating column #77

Merged
merged 4 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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