From 21556c215a003703f9396af91491bf5eee65f077 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 2 Feb 2023 16:19:50 +0000 Subject: [PATCH] PR comments. --- .../Datasources/CreateEditRelationship.svelte | 77 +++++++++---------- .../backend/Datasources/relationshipErrors.js | 4 +- 2 files changed, 40 insertions(+), 41 deletions(-) diff --git a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte index 57ac41a093..64a6057a7c 100644 --- a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte +++ b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte @@ -120,14 +120,12 @@ } function getErrorCount(errors) { - return Object.entries(errors) - .filter(entry => !!entry[1]) - .map(entry => entry[0]).length + return Object.entries(errors).filter(entry => !!entry[1]).length } function allRequiredAttributesSet() { const base = fromTable && toTable && fromColumn && toColumn - if (isManyToOne) { + if (relationshipType === RelationshipTypes.MANY_TO_ONE) { return base && fromPrimary && fromForeign } else { return base && throughTable && throughFromKey && throughToKey @@ -140,39 +138,37 @@ } hasValidated = true errorChecker.setType(relationshipType) - const errObj = {} - errObj.relationshipType = errorChecker.relationshipTypeSet(relationshipType) - errObj.fromTable = errorChecker.tableSet(fromTable) - errObj.toTable = errorChecker.tableSet(toTable) - errObj.throughTable = errorChecker.throughTableSet(throughTable) - errObj.throughFromKey = errorChecker.manyForeignKeySet(throughFromKey) - errObj.throughToKey = errorChecker.manyForeignKeySet(throughToKey) - errObj.throughTable = errorChecker.throughIsNullable() - errObj.fromForeign = errorChecker.foreignKeySet(fromForeign) - errObj.fromPrimary = errorChecker.primaryKeySet(fromPrimary) - errObj.fromTable = errorChecker.doesRelationshipExists() - errObj.toTable = errorChecker.doesRelationshipExists() - // currently don't support relationships back onto the table itself, needs to relate out - errObj.fromTable = errorChecker.differentTables(fromId, toId, throughId) - errObj.toTable = errorChecker.differentTables(toId, fromId, throughId) - errObj.throughTable = errorChecker.differentTables(throughId, fromId, toId) - errObj.fromColumn = errorChecker.columnBeingUsed( - toTable, - fromColumn, - originalFromColumnName - ) - errObj.toColumn = errorChecker.columnBeingUsed( - fromTable, - toColumn, - originalToColumnName - ) - errObj.fromForeign = errorChecker.typeMismatch( - fromTable, - toTable, - fromPrimary, - fromForeign - ) - errors = errObj + errors = { + relationshipType: errorChecker.relationshipTypeSet(relationshipType), + fromTable: + errorChecker.tableSet(fromTable) || + errorChecker.doesRelationshipExists() || + errorChecker.differentTables(fromId, toId, throughId), + toTable: + errorChecker.tableSet(toTable) || + errorChecker.doesRelationshipExists() || + errorChecker.differentTables(toId, fromId, throughId), + throughTable: + errorChecker.throughTableSet(throughTable) || + errorChecker.throughIsNullable() || + errorChecker.differentTables(throughId, fromId, toId), + throughFromKey: errorChecker.manyForeignKeySet(throughFromKey), + throughToKey: errorChecker.manyForeignKeySet(throughToKey), + fromForeign: + errorChecker.foreignKeySet(fromForeign) || + errorChecker.typeMismatch(fromTable, toTable, fromPrimary, fromForeign), + fromPrimary: errorChecker.primaryKeySet(fromPrimary), + fromColumn: errorChecker.columnBeingUsed( + toTable, + fromColumn, + originalFromColumnName + ), + toColumn: errorChecker.columnBeingUsed( + fromTable, + toColumn, + originalToColumnName + ), + } return getErrorCount(errors) === 0 } @@ -285,7 +281,7 @@ } function changed(fn) { - if (fn && typeof fn === "function") { + if (typeof fn === "function") { fn() } validate() @@ -325,7 +321,10 @@ options={relationshipTypes} bind:value={relationshipType} bind:error={errors.relationshipType} - on:change={changed} + on:change={() => + changed(() => { + hasValidated = false + })} />
Tables diff --git a/packages/builder/src/components/backend/Datasources/relationshipErrors.js b/packages/builder/src/components/backend/Datasources/relationshipErrors.js index cdb7805506..55353f7423 100644 --- a/packages/builder/src/components/backend/Datasources/relationshipErrors.js +++ b/packages/builder/src/components/backend/Datasources/relationshipErrors.js @@ -1,7 +1,7 @@ import { RelationshipTypes } from "constants/backend" const typeMismatch = "Column type of the foreign key must match the primary key" -const columnCantExist = "Column name cannot be an existing column" +const columnBeingUsed = "Column name cannot be an existing column" const mustBeDifferentTables = "From/to/through tables must be different" const primaryKeyNotSet = "Please pick the primary key" const throughNotNullable = @@ -75,7 +75,7 @@ export class RelationshipErrorChecker { } columnBeingUsed(table, column, ogName) { - return isColumnNameBeingUsed(table, column, ogName) ? columnCantExist : null + return isColumnNameBeingUsed(table, column, ogName) ? columnBeingUsed : null } typeMismatch(fromTable, toTable, primary, foreign) {