From f9fc0cc5e30644eaa73dc6507c52f0ebbb82af2e Mon Sep 17 00:00:00 2001 From: Aravind Shankar Date: Wed, 29 May 2019 19:44:21 +0530 Subject: [PATCH] fix console schema update quirks (#2286) --- .../integration/data/insert-browse/spec.js | 1 + .../integration/data/insert-browse/test.js | 1 - console/index.js | 9 +- .../Layout/LeftSubSidebar/LeftSubSidebar.scss | 10 - .../Services/Data/Add/AddActions.js | 4 +- .../Data/Add/AddExistingTableViewActions.js | 6 +- .../ReusableComponents/ForeignKeySelector.js | 4 +- .../components/Services/Data/DataActions.js | 197 ++++++++++-------- .../Services/Data/DataPageContainer.js | 15 +- .../components/Services/Data/DataRouter.js | 4 +- .../src/components/Services/Data/DataState.js | 1 - .../Services/Data/DataSubSidebar.js | 65 +++--- .../Data/Function/Permission/Permission.js | 4 +- .../components/Services/Data/Schema/Schema.js | 61 +++--- .../Data/TableModify/ForeignKeyEditor.js | 4 +- .../Data/TableModify/ModifyActions.js | 6 +- .../Data/TableRelationships/Actions.js | 10 +- .../AddManualRelationship.js | 22 +- .../Services/EventTrigger/Add/AddActions.js | 4 +- 19 files changed, 211 insertions(+), 217 deletions(-) diff --git a/console/cypress/integration/data/insert-browse/spec.js b/console/cypress/integration/data/insert-browse/spec.js index 295dcb96..29d35026 100644 --- a/console/cypress/integration/data/insert-browse/spec.js +++ b/console/cypress/integration/data/insert-browse/spec.js @@ -128,6 +128,7 @@ export const passSearchTables = () => { validateCT(getTableName(0, testName), 'success'); cy.get(getElementFromAlias('search-tables')).type('0'); cy.get(getElementFromAlias('table-links')).should('not.contain', '1'); + cy.get(getElementFromAlias('search-tables')).type('{home}{del}'); }; export const checkInsertRoute = () => { diff --git a/console/cypress/integration/data/insert-browse/test.js b/console/cypress/integration/data/insert-browse/test.js index 7c6df291..a1dc95a3 100644 --- a/console/cypress/integration/data/insert-browse/test.js +++ b/console/cypress/integration/data/insert-browse/test.js @@ -8,7 +8,6 @@ import { deleteBITestTable, checkInsertRoute, failBIWrongDataType, - failBINullKeys, failBIUniqueKeys, passBIInsert20Rows, checkBrowseRoute, diff --git a/console/index.js b/console/index.js index 4701556f..0016527b 100644 --- a/console/index.js +++ b/console/index.js @@ -1,5 +1,5 @@ // import GraphiQL parts -import GraphiQLWrapper from './src/components/ApiExplorer/GraphiQLWrapper/GraphiQLWrapper'; +import GraphiQLWrapper from './src/components/Services/ApiExplorer/GraphiQLWrapper/GraphiQLWrapper'; // import Data Tab parts import dataRouter from './src/components/Services/Data/DataRouter'; @@ -8,8 +8,7 @@ import dataHeaders from './src/components/Services/Data/Common/Headers'; import { handleMigrationErrors } from './src/components/Services/Data/TableModify/ModifyActions'; import { fetchSchemaList, - loadSchema, - loadUntrackedSchema, + updateSchemaInfo, UPDATE_CURRENT_SCHEMA, UPDATE_DATA_HEADERS, ACCESS_KEY_ERROR, @@ -28,7 +27,7 @@ import routes from './src/routes'; import globals from './src/Globals'; import endpoints from './src/Endpoints'; import mainState from './src/components/Main/State'; -import { changeRequestHeader } from './src/components/ApiExplorer/Actions'; +import { changeRequestHeader } from './src/components/Services/ApiExplorer/Actions'; import { validateLogin } from './src/components/Main/Actions'; const filterQueryScss = require('./src/components/Common/FilterQuery/FilterQuery.scss'); @@ -39,7 +38,7 @@ export { GraphiQLWrapper }; // export Data Tab parts export { dataRouter, dataReducer }; -export { fetchSchemaList, loadSchema, loadUntrackedSchema }; +export { fetchSchemaList, updateSchemaInfo }; export { UPDATE_CURRENT_SCHEMA, UPDATE_DATA_HEADERS, ACCESS_KEY_ERROR }; export { dataHeaders }; diff --git a/console/src/components/Common/Layout/LeftSubSidebar/LeftSubSidebar.scss b/console/src/components/Common/Layout/LeftSubSidebar/LeftSubSidebar.scss index 696c9d1e..c670f8ae 100644 --- a/console/src/components/Common/Layout/LeftSubSidebar/LeftSubSidebar.scss +++ b/console/src/components/Common/Layout/LeftSubSidebar/LeftSubSidebar.scss @@ -22,11 +22,6 @@ line-height: 26px; } -.changeSchema { - margin-left: 10px; - width: auto; -} - .sidebar { height: calc(100vh - 26px); overflow: auto; @@ -178,11 +173,6 @@ } } -.heading_tooltip { - display: inline-block; - padding-right: 10px; -} - .activeTable { a { // border-left: 4px solid #FFC627; diff --git a/console/src/components/Services/Data/Add/AddActions.js b/console/src/components/Services/Data/Add/AddActions.js index f5beff30..1180bde0 100644 --- a/console/src/components/Services/Data/Add/AddActions.js +++ b/console/src/components/Services/Data/Add/AddActions.js @@ -1,7 +1,7 @@ import defaultState from './AddState'; import _push from '../push'; -import { loadUntrackedRelations, makeMigrationCall } from '../DataActions'; +import { updateSchemaInfo, makeMigrationCall } from '../DataActions'; import { showSuccessNotification, showErrorNotification, @@ -268,7 +268,7 @@ const createTableSql = () => { dispatch({ type: REQUEST_SUCCESS }); dispatch({ type: SET_DEFAULTS }); dispatch(setTable(state.tableName.trim())); - dispatch(loadUntrackedRelations()).then(() => + dispatch(updateSchemaInfo()).then(() => dispatch( _push( '/schema/' + diff --git a/console/src/components/Services/Data/Add/AddExistingTableViewActions.js b/console/src/components/Services/Data/Add/AddExistingTableViewActions.js index 875368ea..0075f78a 100644 --- a/console/src/components/Services/Data/Add/AddExistingTableViewActions.js +++ b/console/src/components/Services/Data/Add/AddExistingTableViewActions.js @@ -1,7 +1,7 @@ import defaultState from './AddExistingTableViewState'; import _push from '../push'; import { - loadUntrackedRelations, + updateSchemaInfo, fetchTrackedFunctions, makeMigrationCall, } from '../DataActions'; @@ -58,7 +58,7 @@ const addExistingTableSql = () => { const errorMsg = 'Adding existing table/view failed'; const customOnSuccess = () => { dispatch({ type: REQUEST_SUCCESS }); - dispatch(loadUntrackedRelations()).then(() => { + dispatch(updateSchemaInfo()).then(() => { const newTable = getState().tables.allSchemas.find( t => t.table_name === state.tableName.trim() && @@ -213,7 +213,7 @@ const addAllUntrackedTablesSql = tableList => { const customOnSuccess = () => { dispatch(showSuccessNotification('Existing table/view added!')); dispatch({ type: REQUEST_SUCCESS }); - dispatch(loadUntrackedRelations()).then(() => { + dispatch(updateSchemaInfo()).then(() => { dispatch(_push('/schema/' + currentSchema)); }); return; diff --git a/console/src/components/Services/Data/Common/ReusableComponents/ForeignKeySelector.js b/console/src/components/Services/Data/Common/ReusableComponents/ForeignKeySelector.js index d59e2f21..575180fe 100644 --- a/console/src/components/Services/Data/Common/ReusableComponents/ForeignKeySelector.js +++ b/console/src/components/Services/Data/Common/ReusableComponents/ForeignKeySelector.js @@ -2,7 +2,7 @@ import React from 'react'; import styles from '../../../../Common/TableCommon/Table.scss'; import { fkViolationOnUpdate, fkViolationOnDelete } from './Tooltips'; import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger'; -import { loadSchema } from '../../DataActions'; +import { updateSchemaInfo } from '../../DataActions'; const violiationActions = [ 'restrict', @@ -36,7 +36,7 @@ const ForeignKeySelector = ({ } newFks[index].refSchemaName = event.target.value; dispatch(setForeignKeys(newFks)); - dispatch(loadSchema({ schemas: [event.target.value] })); + dispatch(updateSchemaInfo({ schemas: [event.target.value] })); }; return (
diff --git a/console/src/components/Services/Data/DataActions.js b/console/src/components/Services/Data/DataActions.js index 8b2ded4f..9d777d6a 100644 --- a/console/src/components/Services/Data/DataActions.js +++ b/console/src/components/Services/Data/DataActions.js @@ -1,4 +1,5 @@ import sanitize from 'sanitize-filename'; +import { push } from 'react-router-redux'; import Endpoints, { globalCookiePolicy } from '../../../Endpoints'; import requestAction from '../../../utils/requestAction'; @@ -36,7 +37,6 @@ const SET_TABLE = 'Data/SET_TABLE'; const LOAD_FUNCTIONS = 'Data/LOAD_FUNCTIONS'; const LOAD_NON_TRACKABLE_FUNCTIONS = 'Data/LOAD_NON_TRACKABLE_FUNCTIONS'; const LOAD_TRACKED_FUNCTIONS = 'Data/LOAD_TRACKED_FUNCTIONS'; -const UPDATE_TRACKED_FUNCTIONS = 'Data/UPDATE_TRACKED_FUNCTIONS'; const LOAD_SCHEMA = 'Data/LOAD_SCHEMA'; const LOAD_UNTRACKED_RELATIONS = 'Data/LOAD_UNTRACKED_RELATIONS'; const FETCH_SCHEMA_LIST = 'Data/FETCH_SCHEMA_LIST'; @@ -172,19 +172,24 @@ const initQueries = { const fetchTrackedFunctions = () => { return (dispatch, getState) => { const url = Endpoints.getSchema; + const currentSchema = getState().tables.currentSchema; + const body = initQueries.loadTrackedFunctions; body.args.where.function_schema = currentSchema; + const options = { credentials: globalCookiePolicy, method: 'POST', headers: dataHeaders(getState), body: JSON.stringify(body), }; + return dispatch(requestAction(url, options)).then( data => { let consistentFunctions = data; const { inconsistentObjects } = getState().metadata; + if (inconsistentObjects.length > 0) { consistentFunctions = filterInconsistentMetadata( data, @@ -192,6 +197,7 @@ const fetchTrackedFunctions = () => { 'functions' ); } + dispatch({ type: LOAD_TRACKED_FUNCTIONS, data: consistentFunctions }); }, error => { @@ -206,91 +212,105 @@ const setUntrackedRelations = () => (dispatch, getState) => { getState().tables.allSchemas, getState().tables.currentSchema ).bulkRelTrack; + dispatch({ type: LOAD_UNTRACKED_RELATIONS, untrackedRelations, }); }; -const loadSchema = configOptions => (dispatch, getState) => { - const url = Endpoints.getSchema; - let allSchemas = getState().tables.allSchemas; - if ( - !configOptions || - ((!configOptions.schemas || configOptions.schemas.length === 0) && - !configOptions.tables) - ) { - configOptions = { - schemas: [getState().tables.currentSchema], - }; - } - if (configOptions) { - if (configOptions.schemas) { - allSchemas = allSchemas.filter( - schemaInfo => - !configOptions.schemas.some(item => item === schemaInfo.table_schema) - ); +const loadSchema = configOptions => { + return (dispatch, getState) => { + const url = Endpoints.getSchema; + + let allSchemas = getState().tables.allSchemas; + + if ( + !configOptions || + ((!configOptions.schemas || configOptions.schemas.length === 0) && + (!configOptions.tables || configOptions.tables.length === 0)) + ) { + configOptions = { + schemas: [getState().tables.currentSchema], + }; } - if (configOptions.tables) { - allSchemas = allSchemas.filter( - schemaInfo => - !configOptions.tables.some( - item => - item.table_schema === schemaInfo.table_schema && - item.table_name === schemaInfo.table_name - ) - ); - } - } - - const body = { - type: 'bulk', - args: [ - fetchTableListQuery(configOptions), - fetchTrackedTableListQuery(configOptions), // v1/query - fetchTrackedTableFkQuery(configOptions), - fetchTrackedTableReferencedFkQuery(configOptions), - ], - }; - const options = { - credentials: globalCookiePolicy, - method: 'POST', - headers: dataHeaders(getState), - body: JSON.stringify(body), - }; - - return dispatch(requestAction(url, options)).then( - data => { - const mergedData = mergeLoadSchemaData( - JSON.parse(data[0].result[1]), - data[1], - JSON.parse(data[2].result[1]), - JSON.parse(data[3].result[1]) - ); - const maybeInconsistentSchemas = allSchemas.concat(mergedData); - let consistentSchemas; - const { inconsistentObjects } = getState().metadata; - if (inconsistentObjects.length > 0) { - consistentSchemas = filterInconsistentMetadata( - maybeInconsistentSchemas, - inconsistentObjects, - 'tables' + if (configOptions) { + if (configOptions.schemas) { + allSchemas = allSchemas.filter( + schemaInfo => + !configOptions.schemas.some( + item => item === schemaInfo.table_schema + ) + ); + } + + if (configOptions.tables) { + allSchemas = allSchemas.filter( + schemaInfo => + !configOptions.tables.some( + item => + item.table_schema === schemaInfo.table_schema && + item.table_name === schemaInfo.table_name + ) ); } - dispatch({ - type: LOAD_SCHEMA, - allSchemas: consistentSchemas || maybeInconsistentSchemas, - }); - dispatch(loadInconsistentObjects()); - }, - error => { - console.error('Failed to load schema ' + JSON.stringify(error)); } - ); + + const body = { + type: 'bulk', + args: [ + fetchTableListQuery(configOptions), + fetchTrackedTableListQuery(configOptions), // v1/query + fetchTrackedTableFkQuery(configOptions), + fetchTrackedTableReferencedFkQuery(configOptions), + ], + }; + + const options = { + credentials: globalCookiePolicy, + method: 'POST', + headers: dataHeaders(getState), + body: JSON.stringify(body), + }; + + return dispatch(requestAction(url, options)).then( + data => { + const mergedData = mergeLoadSchemaData( + JSON.parse(data[0].result[1]), + data[1], + JSON.parse(data[2].result[1]), + JSON.parse(data[3].result[1]) + ); + + const { inconsistentObjects } = getState().metadata; + + const maybeInconsistentSchemas = allSchemas.concat(mergedData); + + let consistentSchemas; + if (inconsistentObjects.length > 0) { + consistentSchemas = filterInconsistentMetadata( + maybeInconsistentSchemas, + inconsistentObjects, + 'tables' + ); + } + + dispatch({ + type: LOAD_SCHEMA, + allSchemas: consistentSchemas || maybeInconsistentSchemas, + }); + + dispatch(loadInconsistentObjects()); + }, + error => { + console.error('Failed to load schema ' + JSON.stringify(error)); + } + ); + }; }; -const loadUntrackedRelations = options => dispatch => { +const updateSchemaInfo = options => dispatch => { return dispatch(loadSchema(options)).then(() => { dispatch(setUntrackedRelations()); }); @@ -308,6 +328,7 @@ const setConsistentFunctions = data => ({ const fetchDataInit = () => (dispatch, getState) => { const url = Endpoints.getSchema; + const body = { type: 'bulk', args: [initQueries.schemaList], @@ -319,10 +340,11 @@ const fetchDataInit = () => (dispatch, getState) => { headers: dataHeaders(getState), body: JSON.stringify(body), }; + return dispatch(requestAction(url, options)).then( data => { dispatch({ type: FETCH_SCHEMA_LIST, schemaList: data[0] }); - dispatch(loadUntrackedRelations()); + dispatch(updateSchemaInfo()); }, error => { console.error('Failed to fetch schema ' + JSON.stringify(error)); @@ -374,6 +396,17 @@ const fetchFunctionInit = () => (dispatch, getState) => { ); }; +const updateCurrentSchema = schemaName => dispatch => { + dispatch(push(`${globals.urlPrefix}/data/schema/${schemaName}`)); + + Promise.all([ + dispatch({ type: UPDATE_CURRENT_SCHEMA, currentSchema: schemaName }), + dispatch(setUntrackedRelations()), + dispatch(fetchFunctionInit()), + dispatch(updateSchemaInfo()), + ]); +}; + /* ************ action creators *********************** */ const fetchSchemaList = () => (dispatch, getState) => { const url = Endpoints.getSchema; @@ -480,7 +513,7 @@ const makeMigrationCall = ( if (globals.consoleMode === 'cli') { dispatch(loadMigrationStatus()); // don't call for server mode } - dispatch(loadSchema()); + dispatch(updateSchemaInfo()); } if (successMsg) { dispatch(showSuccessNotification(successMsg)); @@ -593,13 +626,6 @@ const dataReducer = (state = defaultState, action) => { return { ...state, trackedFunctions: action.data, - listedFunctions: action.data, - }; - - case UPDATE_TRACKED_FUNCTIONS: - return { - ...state, - listedFunctions: [...action.data], }; case LOAD_SCHEMA: // remove duplicates @@ -634,7 +660,6 @@ const dataReducer = (state = defaultState, action) => { return { ...state, trackedFunctions: action.data, - listedFunctions: action.data, }; case UPDATE_CURRENT_SCHEMA: return { ...state, currentSchema: action.currentSchema }; @@ -697,25 +722,25 @@ export { REQUEST_SUCCESS, REQUEST_ERROR, setTable, - loadSchema, + updateSchemaInfo, handleMigrationErrors, makeMigrationCall, LOAD_UNTRACKED_RELATIONS, UPDATE_CURRENT_SCHEMA, - loadUntrackedRelations, fetchSchemaList, fetchDataInit, fetchFunctionInit, + updateCurrentSchema, ADMIN_SECRET_ERROR, UPDATE_DATA_HEADERS, UPDATE_REMOTE_SCHEMA_MANUAL_REL, RESET_MANUAL_REL_TABLE_LIST, fetchTrackedFunctions, - UPDATE_TRACKED_FUNCTIONS, initQueries, LOAD_SCHEMA, setConsistentSchema, setConsistentFunctions, fetchColumnTypes, RESET_COLUMN_TYPE_LIST, + setUntrackedRelations, }; diff --git a/console/src/components/Services/Data/DataPageContainer.js b/console/src/components/Services/Data/DataPageContainer.js index eaf8782d..8274e0dd 100644 --- a/console/src/components/Services/Data/DataPageContainer.js +++ b/console/src/components/Services/Data/DataPageContainer.js @@ -1,17 +1,12 @@ import React from 'react'; import { Link } from 'react-router'; -import _push from './push'; import globals from '../../../Globals'; import LeftContainer from '../../Common/Layout/LeftContainer/LeftContainer'; import PageContainer from '../../Common/Layout/PageContainer/PageContainer'; import DataSubSidebar from './DataSubSidebar'; -import { - loadUntrackedRelations, - UPDATE_CURRENT_SCHEMA, - fetchFunctionInit, -} from './DataActions'; +import { updateCurrentSchema } from './DataActions'; const sectionPrefix = '/data'; @@ -44,13 +39,7 @@ const DataPageContainer = ({ } const handleSchemaChange = e => { - const updatedSchema = e.target.value; - dispatch(_push(`/schema/${updatedSchema}`)); - Promise.all([ - dispatch({ type: UPDATE_CURRENT_SCHEMA, currentSchema: updatedSchema }), - dispatch(loadUntrackedRelations()), - dispatch(fetchFunctionInit()), - ]); + dispatch(updateCurrentSchema(e.target.value)); }; const sidebarContent = ( diff --git a/console/src/components/Services/Data/DataRouter.js b/console/src/components/Services/Data/DataRouter.js index dbaef7ac..547c14bc 100644 --- a/console/src/components/Services/Data/DataRouter.js +++ b/console/src/components/Services/Data/DataRouter.js @@ -32,7 +32,7 @@ import { fetchDataInit, fetchFunctionInit, UPDATE_CURRENT_SCHEMA, - loadUntrackedRelations, + updateSchemaInfo, // UPDATE_DATA_HEADERS, // ADMIN_SECRET_ERROR, } from './DataActions'; @@ -162,7 +162,7 @@ const dataRouterUtils = (connect, store, composeOnEnterHooks) => { currentSchema: currentSchema, }), store.dispatch(fetchDataInit()), - store.dispatch(loadUntrackedRelations()), + store.dispatch(updateSchemaInfo()), store.dispatch(fetchFunctionInit()), ]).then( () => { diff --git a/console/src/components/Services/Data/DataState.js b/console/src/components/Services/Data/DataState.js index 69fbb30b..996fee56 100644 --- a/console/src/components/Services/Data/DataState.js +++ b/console/src/components/Services/Data/DataState.js @@ -155,7 +155,6 @@ const defaultState = { postgresFunctions: [], nonTrackablePostgresFunctions: [], trackedFunctions: [], - listedFunctions: [], listingSchemas: [], untrackedRelations: [], schemaList: ['public'], diff --git a/console/src/components/Services/Data/DataSubSidebar.js b/console/src/components/Services/Data/DataSubSidebar.js index d8fade4e..b8df5d15 100644 --- a/console/src/components/Services/Data/DataSubSidebar.js +++ b/console/src/components/Services/Data/DataSubSidebar.js @@ -4,8 +4,6 @@ import { Link } from 'react-router'; import LeftSubSidebar from '../../Common/Layout/LeftSubSidebar/LeftSubSidebar'; -import { UPDATE_TRACKED_FUNCTIONS } from './DataActions'; - const appPrefix = '/data'; class DataSubSidebar extends React.Component { @@ -13,51 +11,37 @@ class DataSubSidebar extends React.Component { super(); this.tableSearch = this.tableSearch.bind(this); - this.setTrackedTables = this.setTrackedTables.bind(this); this.state = { trackedTables: [], - tableList: [], + searchInput: '', }; } - componentDidMount() { - const { currentSchema, schema } = this.props; - this.setTrackedTables(currentSchema, schema); - } + static getDerivedStateFromProps(props) { + const { currentSchema, schema } = props; - shouldComponentUpdate(nextProps) { - const { currentSchema, schema } = this.props; - if ( - currentSchema !== nextProps.currentSchema || - schema !== nextProps.schema - ) { - this.setTrackedTables(nextProps.currentSchema, nextProps.schema); - } - return true; - } - - setTrackedTables(currentSchema, schema) { const trackedTables = schema.filter( table => table.is_table_tracked && table.table_schema === currentSchema ); - this.setState({ + + return { trackedTables: trackedTables, - tableList: trackedTables, - }); + }; + } + + shouldComponentUpdate(nextProps) { + if (nextProps.metadata.ongoingRequest) { + return false; + } + return true; } tableSearch(e) { const searchTerm = e.target.value; - this.state.tableList = this.state.trackedTables.filter( - t => t.table_name.indexOf(searchTerm) !== -1 - ); - - const matchedFuncs = this.props.functionsList.filter( - f => f.function_name.indexOf(searchTerm) !== -1 - ); - - this.props.dispatch({ type: UPDATE_TRACKED_FUNCTIONS, data: matchedFuncs }); + this.setState({ + searchInput: searchTerm, + }); } render() { @@ -66,23 +50,25 @@ class DataSubSidebar extends React.Component { const functionSymbolActive = require('../../Common/Layout/LeftSubSidebar/function_high.svg'); const { functionsList, - listedFunctions, currentTable, currentSchema, migrationMode, location, currentFunction, - metadata, } = this.props; - if (metadata.ongoingRequest) { - return null; - } - - const { trackedTables, tableList } = this.state; + const { trackedTables, searchInput } = this.state; const trackedTablesLength = trackedTables.length; + const tableList = trackedTables.filter(t => + t.table_name.includes(searchInput) + ); + + const listedFunctions = functionsList.filter(f => + f.function_name.includes(searchInput) + ); + const getSearchInput = () => { return ( { currentTable: state.tables.currentTable, migrationMode: state.main.migrationMode, functionsList: state.tables.trackedFunctions, - listedFunctions: state.tables.listedFunctions, currentFunction: state.functions.functionName, serverVersion: state.main.serverVersion ? state.main.serverVersion : '', metadata: state.metadata, diff --git a/console/src/components/Services/Data/Function/Permission/Permission.js b/console/src/components/Services/Data/Function/Permission/Permission.js index 5685e6a7..96d0e769 100644 --- a/console/src/components/Services/Data/Function/Permission/Permission.js +++ b/console/src/components/Services/Data/Function/Permission/Permission.js @@ -14,7 +14,7 @@ const prefixUrl = globals.urlPrefix + appPrefix; import { fetchCustomFunction } from '../customFunctionReducer'; import { - loadUntrackedRelations, + updateSchemaInfo, UPDATE_CURRENT_SCHEMA, fetchFunctionInit, setTable, @@ -66,7 +66,7 @@ class Permission extends React.Component { type: UPDATE_CURRENT_SCHEMA, currentSchema: setOffTableSchema, }), - dispatch(loadUntrackedRelations()), + dispatch(updateSchemaInfo()), dispatch(fetchFunctionInit()), dispatch(setTable(setOffTable)), ]); diff --git a/console/src/components/Services/Data/Schema/Schema.js b/console/src/components/Services/Data/Schema/Schema.js index 8830ce01..fb7ff3f5 100644 --- a/console/src/components/Services/Data/Schema/Schema.js +++ b/console/src/components/Services/Data/Schema/Schema.js @@ -1,6 +1,3 @@ -/* eslint-disable space-infix-ops */ -/* eslint-disable no-loop-func */ - import PropTypes from 'prop-types'; import React, { Component } from 'react'; @@ -22,9 +19,9 @@ import { addExistingFunction, } from '../Add/AddExistingTableViewActions'; import { - loadUntrackedRelations, + updateSchemaInfo, fetchFunctionInit, - UPDATE_CURRENT_SCHEMA, + updateCurrentSchema, } from '../DataActions'; import { autoAddRelName, @@ -49,7 +46,7 @@ class Schema extends Component { this.props.dispatch(fetchFunctionInit()); this.props.dispatch( - loadUntrackedRelations({ schemas: [this.props.currentSchema] }) + updateSchemaInfo({ schemas: [this.props.currentSchema] }) ); } @@ -66,20 +63,10 @@ class Schema extends Component { trackedFunctions, } = this.props; - const styles = require('../../../Common/Layout/LeftSubSidebar/LeftSubSidebar.scss'); - - const updateCurrentSchema = schemaName => { - dispatch(push(`${appPrefix}/schema/${schemaName}`)); - - Promise.all([ - dispatch({ type: UPDATE_CURRENT_SCHEMA, currentSchema: schemaName }), - dispatch(fetchFunctionInit()), - dispatch(loadUntrackedRelations({ schemas: [schemaName] })), - ]); - }; + const styles = require('../../../Common/Common.scss'); const handleSchemaChange = e => { - updateCurrentSchema(e.target.value); + dispatch(updateCurrentSchema(e.target.value)); }; /***********/ @@ -165,14 +152,18 @@ class Schema extends Component { }; const handleCreateClick = () => { + const schemaName = schemaNameEdit.trim(); + const successCb = () => { - updateCurrentSchema(schemaNameEdit.trim()); + dispatch(updateCurrentSchema(schemaName)); + this.setState({ schemaNameEdit: '', createSchemaOpen: false, }); }; - dispatch(createNewSchema(schemaNameEdit.trim(), successCb)); + + dispatch(createNewSchema(schemaName, successCb)); }; const handleCancelCreateNewSchema = () => { @@ -236,8 +227,9 @@ class Schema extends Component { if (migrationMode) { const handleDelete = () => { const successCb = () => { - updateCurrentSchema('public'); + dispatch(updateCurrentSchema('public')); }; + dispatch(deleteCurrentSchema(successCb)); }; @@ -262,7 +254,12 @@ class Schema extends Component {