From 56c67509aa40677045d1f2011555995e5dc428bb Mon Sep 17 00:00:00 2001 From: Rikin Kachhia Date: Wed, 3 Apr 2019 15:07:14 +0530 Subject: [PATCH] update track relationship text in console (#1927) --- console/src/components/Common/Common.scss | 13 - .../CustomResolver/Landing/CustomResolver.js | 108 ++- .../Services/Data/Schema/AutoAddRelations.js | 107 --- .../components/Services/Data/Schema/Schema.js | 627 +++++++++++------- .../TableRelationships/RelationshipEditor.js | 11 +- .../Data/TableRelationships/Relationships.js | 27 +- .../TableRelationships/RelationshipsView.js | 4 +- .../Services/Data/TableRelationships/utils.js | 21 +- .../Services/EventTrigger/Schema/Schema.js | 84 ++- .../manual/schema/using-existing-database.rst | 17 +- 10 files changed, 531 insertions(+), 488 deletions(-) delete mode 100644 console/src/components/Services/Data/Schema/AutoAddRelations.js diff --git a/console/src/components/Common/Common.scss b/console/src/components/Common/Common.scss index 8c21981d..b03663b9 100644 --- a/console/src/components/Common/Common.scss +++ b/console/src/components/Common/Common.scss @@ -879,15 +879,9 @@ code { } } -/*Newly added for remote schema page*/ .headerText { font-size: 24px; font-weight: bold; - padding-bottom: 20px; -} - -.addPaddRight { - padding-right: 30px; } .subHeaderText { @@ -912,13 +906,6 @@ code { font-weight: 600; } -.noPadd { - padding-left: 0; - padding-right: 0; -} - -/*Newly added for remote schema page*/ - .heading_text { font-size: 18px; font-weight: bold; diff --git a/console/src/components/Services/CustomResolver/Landing/CustomResolver.js b/console/src/components/Services/CustomResolver/Landing/CustomResolver.js index de623881..8f5f819b 100644 --- a/console/src/components/Services/CustomResolver/Landing/CustomResolver.js +++ b/console/src/components/Services/CustomResolver/Landing/CustomResolver.js @@ -16,7 +16,50 @@ class CustomResolver extends React.Component { const { dispatch, migrationMode, customResolverList } = this.props; - const showFirstSection = customResolverList.resolvers.length ? false : true; + const getIntroSection = () => { + const showIntroSection = !customResolverList.resolvers.length; + if (!showIntroSection) { + return null; + } + + return ( +
+ +
+
+ ); + }; + + const getAddBtn = () => { + let addBtn = null; + + if (migrationMode) { + const handleClick = e => { + e.preventDefault(); + + dispatch(push(`${globals.urlPrefix}${appPrefix}/manage/add`)); + }; + + addBtn = ( + + ); + } + + return addBtn; + }; return (
-

+

Remote Schemas

- {migrationMode ? ( - - ) : null} + {getAddBtn()}

- {showFirstSection ? ( -
- -
-
- ) : null} + + {getIntroSection()}
- {/* -
- Add pre-CRUD custom business logic like data validation, etc. or also - fetch data from another GraphQL server by stitching schemas -
-
- -
-
- - - -
-
- - Read more - -
- */}
); diff --git a/console/src/components/Services/Data/Schema/AutoAddRelations.js b/console/src/components/Services/Data/Schema/AutoAddRelations.js deleted file mode 100644 index 8428b211..00000000 --- a/console/src/components/Services/Data/Schema/AutoAddRelations.js +++ /dev/null @@ -1,107 +0,0 @@ -/* eslint-disable space-infix-ops */ -/* eslint-disable no-loop-func */ - -import PropTypes from 'prop-types'; - -import React, { Component } from 'react'; -import { - autoTrackRelations, - autoAddRelName, -} from '../TableRelationships/Actions'; -import { getRelationshipLine } from '../TableRelationships/Relationships'; -import Button from '../../../Common/Button/Button'; - -class AutoAddRelations extends Component { - trackAllRelations = untrackedData => { - this.props.dispatch(autoTrackRelations(untrackedData)); - }; - - render() { - const styles = require('../../../Common/Layout/LeftSubSidebar/LeftSubSidebar.scss'); - - const { untrackedRelations, dispatch } = this.props; - - const handleAutoAddIndivRel = obj => { - dispatch(autoAddRelName(obj)); - }; - - if (untrackedRelations.length === 0) { - return ( -
- There are no untracked relations -
- ); - } - - const untrackData = untrackedRelations.map((obj, i) => { - return ( -
- -
- {obj.data.tableName} -{' '} - {getRelationshipLine( - obj.data.isObjRel, - obj.data.lcol, - obj.data.rcol, - obj.data.rTable - )} -
-
- ); - }); - - return ( -
- {untrackedRelations.length === 0 ? ( -
- There are no untracked relations -
- ) : ( -
- There are {untrackedRelations.length} untracked relations -
- )} - -
{untrackData}
-
- ); - } -} - -AutoAddRelations.propTypes = { - untrackedRelations: PropTypes.array.isRequired, - schema: PropTypes.array.isRequired, - dispatch: PropTypes.func.isRequired, -}; - -export default AutoAddRelations; diff --git a/console/src/components/Services/Data/Schema/Schema.js b/console/src/components/Services/Data/Schema/Schema.js index 17e70df6..aa1f0354 100644 --- a/console/src/components/Services/Data/Schema/Schema.js +++ b/console/src/components/Services/Data/Schema/Schema.js @@ -28,26 +28,33 @@ import { LOAD_UNTRACKED_RELATIONS, UPDATE_CURRENT_SCHEMA, } from '../DataActions'; -import { getAllUnTrackedRelations } from '../TableRelationships/Actions'; -import AutoAddRelationsConnector from './AutoAddRelations'; +import { + autoAddRelName, + autoTrackRelations, + getAllUnTrackedRelations, +} from '../TableRelationships/Actions'; import globals from '../../../../Globals'; +import { getRelDef } from '../TableRelationships/Relationships'; const appPrefix = globals.urlPrefix + '/data'; class Schema extends Component { constructor(props) { super(props); + this.state = { isExporting: false, }; + // Initialize this table - const dispatch = this.props.dispatch; - dispatch(fetchDataInit()); - dispatch(fetchFunctionInit()); + this.props.dispatch(fetchDataInit()); + this.props.dispatch(fetchFunctionInit()); + const untrackedRelations = getAllUnTrackedRelations( this.props.schema, this.props.currentSchema ).bulkRelTrack; + this.props.dispatch({ type: LOAD_UNTRACKED_RELATIONS, untrackedRelations, @@ -59,6 +66,7 @@ class Schema extends Component { this.props.schema, this.props.currentSchema ).bulkRelTrack; + this.props.dispatch({ type: LOAD_UNTRACKED_RELATIONS, untrackedRelations, @@ -69,7 +77,7 @@ class Schema extends Component { const { schema, schemaList, - untracked, + untrackedTables, migrationMode, untrackedRelations, currentSchema, @@ -81,20 +89,11 @@ class Schema extends Component { const styles = require('../../../Common/Layout/LeftSubSidebar/LeftSubSidebar.scss'); - /* Filter */ - const trackedFuncs = trackedFunctions.map(t => t.function_name); - // Assuming schema for both function and tables are same - const trackableFuncs = functionsList.filter(f => { - // return function which are tracked && function name whose setof tables are tracked - return ( - trackedFuncs.indexOf(f.function_name) === -1 && !!f.return_table_info - ); // && add condition which will check whether the setoff table is tracked or not - }); - /* */ - const handleSchemaChange = e => { const updatedSchema = e.target.value; + dispatch(push(`${appPrefix}/schema/${updatedSchema}`)); + Promise.all([ dispatch({ type: UPDATE_CURRENT_SCHEMA, currentSchema: updatedSchema }), dispatch(fetchDataInit()), @@ -103,144 +102,271 @@ class Schema extends Component { ]); }; - let relationships = 0; - schema.map(t => (relationships += t.relationships.length)); + /***********/ - // find which tables are untracked - const ids1 = schema.map(item => item.table_name); - const ids2 = untracked.map(item => item.table_name); + const getTrackableFunctions = () => { + const trackedFuncNames = trackedFunctions.map(t => t.function_name); - const untrackedTables = ids1 - .map((id, index) => { - if (ids2.indexOf(id) < 0) { - return schema[index]; - } - }) - .concat( - ids2.map((id, index) => { - if (ids1.indexOf(id) < 0) { - return untracked[index]; - } - }) - ) - .filter(item => item !== undefined) - .sort((a, b) => { + // Assuming schema for both function and tables are same + // return function which are tracked && function name whose + // set of tables are tracked + const filterCondition = func => { + return ( + !trackedFuncNames.includes(func.function_name) && + !!func.return_table_info + ); + }; + + return functionsList.filter(filterCondition); + }; + + const getUntrackedTables = () => { + const tableNames = schema.map(item => item.table_name); + const untrackedTableNames = untrackedTables.map(item => item.table_name); + + const schemaUntrackedTables = schema.filter( + table => !untrackedTableNames.includes(table.table_name) + ); + + const untrackedTablesNotInSchema = untrackedTables.filter( + table => !tableNames.includes(table.table_name) + ); + + const tableSortFunc = (a, b) => { return a.table_name === b.table_name ? 0 : +(a.table_name > b.table_name) || -1; + }; + + const _untrackedTables = schemaUntrackedTables.concat( + untrackedTablesNotInSchema + ); + + return _untrackedTables.sort(tableSortFunc); + }; + + /***********/ + + const allUntrackedTables = getUntrackedTables(); + const trackableFuncs = getTrackableFunctions(); + + const getCreateBtn = () => { + let createBtn = null; + + if (migrationMode) { + const handleClick = e => { + e.preventDefault(); + + dispatch(push(`${appPrefix}/schema/${currentSchema}/table/add`)); + }; + + createBtn = ( + + ); + } + + return createBtn; + }; + + const getCurrentSchemaSection = () => { + const schemaOptions = schemaList.map(s => { + return ; }); - const untrackedHtml = []; - for (let i = 0; i < untrackedTables.length; i++) { - untrackedHtml.push( -
-
+ return ( +
+
Current Postgres schema
+
+ +
+
+ ); + }; + + const getUntrackedTablesSection = () => { + const getTrackAllBtn = () => { + let trackAllBtn = null; + + if (allUntrackedTables.length > 0) { + trackAllBtn = ( -
-
- {untrackedTables[i].table_name} -
-
- ); - } - if (!untrackedHtml.length) { - untrackedHtml.push( -
There are no untracked tables or views
- ); - } + ); + } - return ( -
-
- -
-

- {' '} - Schema{' '} -

- {migrationMode ? ( - - ) : null} -
-
-
-
Current postgres schema
-
- -
-
-
-
-
-

- Untracked tables or views -

- -