From 0ae4d8c73ac5bbd681f95aa74f5b139f89537323 Mon Sep 17 00:00:00 2001 From: rikinsk Date: Mon, 7 Oct 2019 13:09:19 +0530 Subject: [PATCH] allow only tracked tables in manual relationships --- .../AddManualRelationship.js | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/console/src/components/Services/Data/TableRelationships/AddManualRelationship.js b/console/src/components/Services/Data/TableRelationships/AddManualRelationship.js index 48915455250b7..be401ea186183 100644 --- a/console/src/components/Services/Data/TableRelationships/AddManualRelationship.js +++ b/console/src/components/Services/Data/TableRelationships/AddManualRelationship.js @@ -3,6 +3,15 @@ import { ordinalColSort } from '../utils'; import { addRelViewMigrate, resetManualRelationshipForm } from './Actions'; import ExpandableEditor from '../../../Common/Layout/ExpandableEditor/Editor'; import ManualRelationshipSelector from './ManualRelationshipSelector'; +import { + getColumnName, + getSchemaName, + getSchemaTables, + getTableColumnNames, + getTableName, + getTableSchema, + getTrackedTables, +} from '../../../Common/utils/pgUtils'; const AddManualRelationship = ({ tableSchema, @@ -17,20 +26,21 @@ const AddManualRelationship = ({ // columns in the right order with their indices const orderedColumns = columns.map((c, i) => ({ - name: c.column_name, + name: getColumnName(c), index: i, })); - relAdd.rSchema = relAdd.rSchema || tableSchema.table_schema; + relAdd.rSchema = relAdd.rSchema || getTableSchema(tableSchema); const refTables = {}; - allSchemas.forEach(ts => { - if (ts.table_schema === relAdd.rSchema) { - refTables[ts.table_name] = ts.columns.map(c => c.column_name); - } - }); + const trackedSchemaTables = getTrackedTables( + getSchemaTables(allSchemas, relAdd.rSchema) + ); + trackedSchemaTables.forEach( + ts => (refTables[getTableName(ts)] = getTableColumnNames(ts)) + ); - const orderedSchemaList = schemaList.map(s => s.schema_name).sort(); + const orderedSchemaList = schemaList.map(s => getSchemaName(s)).sort(); const resetManualRel = () => { dispatch(resetManualRelationshipForm());