Skip to content

Commit

Permalink
Merge pull request #1 from oslabs-beta/kevin
Browse files Browse the repository at this point in the history
# Commit Message
  • Loading branch information
choukevin612 authored Jan 19, 2024
2 parents 56e056c + 3e7e7f1 commit 20900b4
Show file tree
Hide file tree
Showing 12 changed files with 364 additions and 181 deletions.
2 changes: 1 addition & 1 deletion backend/src/models/configModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DocConfigFile } from '../../BE_types';

// HELPER FUNCTIONS

const home = `${os.homedir()}/Documents/SeeQR`;
const home = process.cwd();
const configFile = 'config.json';
const configPath = `${home}/${configFile}`;

Expand Down
1 change: 1 addition & 0 deletions backend/src/utils/helperFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ const helperFunctions: HelperFunctions = {
dbCopyName,
file,
dbType: DBType,

) {
const SQL_data = docConfig.getFullConfig();
const PG = ` PGPASSWORD=${SQL_data?.pg_options.password} pg_dump -s -U ${SQL_data?.pg_options.user} -p ${SQL_data?.pg_options.port} -F p -d "${dbCopyName}" > "${file}"`;
Expand Down
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"mysql_options":{"user":"","password":"","port":3306},"pg_options":{"user":"postgres","password":"test","port":"5434"},"rds_mysql_options":{"user":"","password":"","port":3306,"host":""},"rds_pg_options":{"user":"","password":"","port":5432,"host":""},"sqlite_options":{"filename":""},"directPGURI_options":{"connectionString":""}}
2 changes: 1 addition & 1 deletion frontend/components/views/DbView/TablesTabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function TablesTabs({
aria-label="table"
className="tables-view-btn"
>
Table
Table View
</ToggleButton>
</StyledToggleButtonGroup>
<ErView
Expand Down
7 changes: 6 additions & 1 deletion frontend/components/views/ERTables/ERTabling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ const mmStyle: object = {
height: 150,
overflow: 'hidden',
};

console.log(Node);
// defines the styling for the minimap nodes
const nodeColor = (node: Node): string => {
switch (node.type) {
case 'tableHeader':
return colors.greyLightest;
case 'tableField':
return 'white';
case 'tableFooter':
return 'white';
default:
return 'red';
}
Expand Down Expand Up @@ -224,8 +226,11 @@ function ERTabling({ tables, selectedDb, curDBType }: ERTablingProps) {

// This useEffect fires when schemaState changes and will convert the state to a form react flow requires
useEffect(() => {
console.log(schemaState);
console.log(stateToReactFlow);
// send the schema state to the convert method to convert the schema to the form react flow requires
const initialState = stateToReactFlow.convert(schemaState);
console.log(initialState);
// create a deep copy of the state, to ensure the state is not directly modified
const schemaStateString = JSON.stringify(schemaState);
const schemaStateCopy = JSON.parse(schemaStateString);
Expand Down
3 changes: 3 additions & 0 deletions frontend/components/views/ERTables/NodeTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import tableHeader from './TableHeaderNode';
import tableField from './TableFieldNode';
import tableFooter from './TableFooterNode';
/**
* This file is required for React-flow
* React-flow states:
Expand All @@ -13,10 +14,12 @@ import tableField from './TableFieldNode';
type NodeTypes = {
tableHeader: any;
tableField: any;
tableFooter: any;
};
const nodeTypes: NodeTypes = {
tableHeader,
tableField,
tableFooter,
};
export type TablePosObjType = {
table_name: string;
Expand Down
92 changes: 60 additions & 32 deletions frontend/components/views/ERTables/TableFieldNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,29 +161,38 @@ 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}`;
if (constraint_type === 'FOREIGN KEY') alterColumnsObj.rename_constraint = `fk_${alterTablesObj.table_name}${column_name}`;
if (constraint_type === 'UNIQUE') alterColumnsObj.rename_constraint = `unique_${alterTablesObj.table_name}${column_name}`;
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}`;
if (constraint_type === 'FOREIGN KEY')
alterColumnsObj.rename_constraint = `fk_${alterTablesObj.table_name}${column_name}`;
if (constraint_type === 'UNIQUE')
alterColumnsObj.rename_constraint = `unique_${alterTablesObj.table_name}${column_name}`;
}

// handle isNullable change
const isNullable = document.getElementById(
`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;
const isNullableString: 'YES' | 'NO' = isNullable.checked
? 'YES'
: 'NO';
schemaStateCopy.tableList[i].columns[j].is_nullable =
isNullableString;
alterColumnsObj.is_nullable =
isNull !== isNullableString ? isNullableString : null;

// handle max_character_length change
const columnMaxCharacterLengthInput = document.getElementById(
`type-input-char_max_size-${tableColumn}`,
) as HTMLSelectElement;
if (columnMaxCharacterLengthInput.value) {
if (
character_maximum_length
!== parseInt(columnMaxCharacterLengthInput.value, 10)
character_maximum_length !==
parseInt(columnMaxCharacterLengthInput.value, 10)
) {
alterColumnsObj.character_maximum_length = parseInt(
columnMaxCharacterLengthInput.value,
Expand All @@ -203,11 +212,12 @@ function TableField({ data }: TableFieldProps) {
`type-dd-${tableColumn}`,
) as HTMLSelectElement;
if (
(data_type === 'character varying' ? 'varchar' : data_type)
!== dataTypeInput.value
(data_type === 'character varying' ? 'varchar' : data_type) !==
dataTypeInput.value
) {
alterColumnsObj.data_type = dataTypeInput.value;
schemaStateCopy.tableList[i].columns[j].data_type = dataTypeInput.value;
schemaStateCopy.tableList[i].columns[j].data_type =
dataTypeInput.value;
}

// handle add/Drop Constraint type
Expand All @@ -225,8 +235,8 @@ function TableField({ data }: TableFieldProps) {
) as HTMLInputElement;
// if constraint type is PK in state but checkbox is unchecked, drop the constraint
if (
constraint_type === 'PRIMARY KEY'
&& pkCheckBox.checked === false
constraint_type === 'PRIMARY KEY' &&
pkCheckBox.checked === false
) {
// modify state to remove constraint
schemaStateCopy.tableList[i].columns[j].constraint_type = null;
Expand All @@ -236,15 +246,19 @@ function TableField({ data }: TableFieldProps) {
);
} // if constraint type is not in state but checkbox is checked, add the constraint
else if (
constraint_type !== 'PRIMARY KEY'
&& pkCheckBox.checked === true
constraint_type !== 'PRIMARY KEY' &&
pkCheckBox.checked === true
) {
// modify state to remove constraint
schemaStateCopy.tableList[i].columns[j].constraint_type = 'PRIMARY KEY';
schemaStateCopy.tableList[i].columns[j].constraint_type =
'PRIMARY KEY';
// create a copy in case multiple constraints are added
const addConstraintObjCopy: AddConstraintObjType = { ...addConstraintObj };
const addConstraintObjCopy: AddConstraintObjType = {
...addConstraintObj,
};
// name the constraint PK_<tableNamecolumn_name>
addConstraintObjCopy.constraint_name = `pk_${data.tableName + column_name
addConstraintObjCopy.constraint_name = `pk_${
data.tableName + column_name
}`;
// assign the constraint_type to 'PRIMARY KEY'
addConstraintObjCopy.constraint_type = 'PRIMARY KEY';
Expand All @@ -258,8 +272,8 @@ function TableField({ data }: TableFieldProps) {
) as HTMLInputElement;
// if constraint type is FK in state but checkbox is unchecked, drop the constraint
if (
constraint_type === 'FOREIGN KEY'
&& fkCheckBox.checked === false
constraint_type === 'FOREIGN KEY' &&
fkCheckBox.checked === false
) {
// modify state to remove constraint
schemaStateCopy.tableList[i].columns[j].constraint_type = null;
Expand All @@ -268,14 +282,16 @@ function TableField({ data }: TableFieldProps) {
`FK_${data.tableName + column_name}`,
);
} else if (
constraint_type !== 'FOREIGN KEY'
&& fkCheckBox.checked === true
constraint_type !== 'FOREIGN KEY' &&
fkCheckBox.checked === true
) {
// modify state to add constraint
schemaStateCopy.tableList[i].columns[j].constraint_type = 'FOREIGN KEY';
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
addConstraintObjCopy.constraint_name = `fk_${
data.tableName + column_name
}`;
// assign the constraint type to 'FOREIGN KEY'
addConstraintObjCopy.constraint_type = 'FOREIGN KEY';
Expand All @@ -296,21 +312,33 @@ function TableField({ data }: TableFieldProps) {
}

// handle unique constraint
const uniqueCheckBox = document.getElementById(`unique-chkbox-${tableColumn}`) as HTMLInputElement;
if (constraint_type === 'UNIQUE' && uniqueCheckBox.checked === false) {
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) {
} else if (
constraint_type !== 'UNIQUE' &&
uniqueCheckBox.checked === true
) {
// modify state to add constraint
schemaStateCopy.tableList[i].columns[j].constraint_type = 'UNIQUE';
schemaStateCopy.tableList[i].columns[j].constraint_type =
'UNIQUE';
// create a copy in case multiple constraints are added
const addConstraintObjCopy: AddConstraintObjType = { ...addConstraintObj };
const addConstraintObjCopy: AddConstraintObjType = {
...addConstraintObj,
};
// name the constraint PK_<tableNamecolumn_name>
addConstraintObjCopy.constraint_name = `unique_${data.tableName + column_name
addConstraintObjCopy.constraint_name = `unique_${
data.tableName + column_name
}`;
// assign the constraint_type to 'UNIQUE'
addConstraintObjCopy.constraint_type = 'UNIQUE';
Expand Down
Loading

0 comments on commit 20900b4

Please sign in to comment.