From 9b7a6c928c52f32ee541a3d33fdc051a121b6603 Mon Sep 17 00:00:00 2001 From: strongSoda Date: Thu, 6 Jun 2019 15:18:47 +0530 Subject: [PATCH 01/12] render 404 for nonexistent resources --- console/src/NotFoundError.js | 1 + console/src/components/Error/ErrorBoundary.js | 72 +++++++++++++------ .../Data/TableBrowseRows/ViewTable.js | 7 +- 3 files changed, 56 insertions(+), 24 deletions(-) create mode 100644 console/src/NotFoundError.js diff --git a/console/src/NotFoundError.js b/console/src/NotFoundError.js new file mode 100644 index 0000000000000..1f587e59ed08d --- /dev/null +++ b/console/src/NotFoundError.js @@ -0,0 +1 @@ +export default class NotFoundError extends Error {} diff --git a/console/src/components/Error/ErrorBoundary.js b/console/src/components/Error/ErrorBoundary.js index 35b4e67c88479..3a664cb972793 100644 --- a/console/src/components/Error/ErrorBoundary.js +++ b/console/src/components/Error/ErrorBoundary.js @@ -10,11 +10,18 @@ import Spinner from '../Common/Spinner/Spinner'; import { Link } from 'react-router'; import Helmet from 'react-helmet'; +import NotFoundError from '../../NotFoundError'; + class ErrorBoundary extends React.Component { constructor(props) { super(props); - this.state = { hasError: false, info: null, error: null }; + this.state = { + hasError: false, + info: null, + error: null, + type: '500', + }; } resetState = () => { @@ -22,12 +29,20 @@ class ErrorBoundary extends React.Component { }; componentDidCatch(error, info) { + console.log(error.message); + const { dispatch } = this.props; + + // for invalid path segment errors + if (error instanceof NotFoundError) { + this.setState({ + type: '404', + }); + } + this.setState({ hasError: true, info: info, error: error }); // TODO logErrorToMyService(error, info); - const { dispatch } = this.props; - dispatch(loadInconsistentObjects(true)).then(() => { if (this.props.metadata.inconsistentObjects.length > 0) { if (!isMetadataStatusPage()) { @@ -60,26 +75,41 @@ class ErrorBoundary extends React.Component {
-
-

Error

-
-
- Something went wrong. Head back{' '} - - Home - - . + {this.state.type === '404' ? ( +
+

404

+
+
+ This page doesn't exist. Head back{' '} + + Home + + . +
+
-
-
- You can report this issue on our{' '} - - GitHub - {' '} - or chat with us on{' '} - Discord + ) : ( +
+

Error

+
+
+ Something went wrong. Head back{' '} + + Home + + . +
+
+
+ You can report this issue on our{' '} + + GitHub + {' '} + or chat with us on{' '} + Discord +
-
+ )}
{ if (headings.length === 0) { @@ -166,8 +167,8 @@ class ViewTable extends Component { s => s.table_name === tableName && s.table_schema === currentSchema ); if (!currentTable) { - // dispatch a 404 route - dispatch(replace('/404')); + // throw a 404 exception + throw new NotFoundError('404 Not Found'); } // Is this a view const isView = currentTable.table_type !== 'BASE TABLE'; From 91b1f499f0ad7f991632dac05740f8f45d75576b Mon Sep 17 00:00:00 2001 From: strongSoda Date: Thu, 6 Jun 2019 17:40:13 +0530 Subject: [PATCH 02/12] render 404 for nonexistent resources --- console/src/NotFoundError.js | 1 - console/src/components/Error/ErrorBoundary.js | 76 ++++++++----------- console/src/components/Error/PageNotFound.js | 2 + .../Data/TableBrowseRows/ViewTable.js | 2 +- 4 files changed, 35 insertions(+), 46 deletions(-) delete mode 100644 console/src/NotFoundError.js diff --git a/console/src/NotFoundError.js b/console/src/NotFoundError.js deleted file mode 100644 index 1f587e59ed08d..0000000000000 --- a/console/src/NotFoundError.js +++ /dev/null @@ -1 +0,0 @@ -export default class NotFoundError extends Error {} diff --git a/console/src/components/Error/ErrorBoundary.js b/console/src/components/Error/ErrorBoundary.js index 3a664cb972793..006a2e7e88f51 100644 --- a/console/src/components/Error/ErrorBoundary.js +++ b/console/src/components/Error/ErrorBoundary.js @@ -10,26 +10,27 @@ import Spinner from '../Common/Spinner/Spinner'; import { Link } from 'react-router'; import Helmet from 'react-helmet'; -import NotFoundError from '../../NotFoundError'; +import PageNotFound, { NotFoundError } from './PageNotFound'; class ErrorBoundary extends React.Component { + initialState = { + hasError: false, + info: null, + error: null, + type: '500', + }; + constructor(props) { super(props); - this.state = { - hasError: false, - info: null, - error: null, - type: '500', - }; + this.state = this.initialState; } resetState = () => { - this.setState({ hasError: false, info: null, error: null }); + this.setState({ ...this.initialState }); }; componentDidCatch(error, info) { - console.log(error.message); const { dispatch } = this.props; // for invalid path segment errors @@ -41,8 +42,6 @@ class ErrorBoundary extends React.Component { this.setState({ hasError: true, info: info, error: error }); - // TODO logErrorToMyService(error, info); - dispatch(loadInconsistentObjects(true)).then(() => { if (this.props.metadata.inconsistentObjects.length > 0) { if (!isMetadataStatusPage()) { @@ -70,46 +69,35 @@ class ErrorBoundary extends React.Component { } if (this.state.hasError) { + if (this.state.type === '404') { + return ; + } + return (
- {this.state.type === '404' ? ( -
-

404

-
-
- This page doesn't exist. Head back{' '} - - Home - - . -
-
+
+

Error

+
+
+ Something went wrong. Head back{' '} + + Home + + .
- ) : ( -
-

Error

-
-
- Something went wrong. Head back{' '} - - Home - - . -
-
-
- You can report this issue on our{' '} - - GitHub - {' '} - or chat with us on{' '} - Discord -
+
+
+ You can report this issue on our{' '} + + GitHub + {' '} + or chat with us on{' '} + Discord
- )} +
{ if (headings.length === 0) { From 16254434f9cc09aaecd5ae6521ad2c7a5126a714 Mon Sep 17 00:00:00 2001 From: strongSoda Date: Thu, 6 Jun 2019 20:37:53 +0530 Subject: [PATCH 03/12] (events) render 404 for nonexistent resources --- .../components/Services/EventTrigger/Modify/Modify.js | 7 ++++--- .../Services/EventTrigger/PendingEvents/ViewActions.js | 5 +---- .../Services/EventTrigger/PendingEvents/ViewTable.js | 9 +++++---- .../Services/EventTrigger/ProcessedEvents/ViewActions.js | 7 ++----- .../Services/EventTrigger/ProcessedEvents/ViewTable.js | 6 +++--- .../Services/EventTrigger/RunningEvents/ViewTable.js | 6 +++--- .../Services/EventTrigger/StreamingLogs/Logs.js | 6 ++++++ 7 files changed, 24 insertions(+), 22 deletions(-) diff --git a/console/src/components/Services/EventTrigger/Modify/Modify.js b/console/src/components/Services/EventTrigger/Modify/Modify.js index 065a10c803554..10bef08c746aa 100644 --- a/console/src/components/Services/EventTrigger/Modify/Modify.js +++ b/console/src/components/Services/EventTrigger/Modify/Modify.js @@ -3,7 +3,6 @@ import TableHeader from '../TableCommon/TableHeader'; import styles from './ModifyEvent.scss'; import { getTableColumns } from '../utils'; -import _push from '../push'; import Info from './Info'; import WebhookEditor from './WebhookEditor'; @@ -14,6 +13,8 @@ import ActionButtons from './ActionButtons'; import { save, setDefaults, RESET_MODIFY_STATE } from './Actions'; +import { NotFoundError } from '../../../Error/PageNotFound'; + class Modify extends React.Component { componentDidMount() { const { dispatch } = this.props; @@ -41,8 +42,8 @@ class Modify extends React.Component { ); if (!currentTrigger) { - dispatch(_push('/events/manage')); - return null; + // throw a 404 exception + throw new NotFoundError('404 Not Found'); } const { diff --git a/console/src/components/Services/EventTrigger/PendingEvents/ViewActions.js b/console/src/components/Services/EventTrigger/PendingEvents/ViewActions.js index 19b65a028ae3f..515651d9d3b62 100644 --- a/console/src/components/Services/EventTrigger/PendingEvents/ViewActions.js +++ b/console/src/components/Services/EventTrigger/PendingEvents/ViewActions.js @@ -34,9 +34,6 @@ const vMakeRequest = () => { const state = getState(); const url = Endpoints.query; const originalTrigger = getState().triggers.currentTrigger; - const triggerList = getState().triggers.triggerList; - const triggerSchema = triggerList.filter(t => t.name === originalTrigger); - const triggerName = triggerSchema[0].name; const currentQuery = JSON.parse(JSON.stringify(state.triggers.view.query)); // count query const countQuery = JSON.parse(JSON.stringify(state.triggers.view.query)); @@ -52,7 +49,7 @@ const vMakeRequest = () => { finalAndClause.push({ error: false }); currentQuery.columns[1].where = { $and: finalAndClause }; currentQuery.where = { name: state.triggers.currentTrigger }; - countQuery.where.$and.push({ trigger_name: triggerName }); + countQuery.where.$and.push({ trigger_name: originalTrigger }); } else { // reset where for events if (currentQuery.columns[1]) { diff --git a/console/src/components/Services/EventTrigger/PendingEvents/ViewTable.js b/console/src/components/Services/EventTrigger/PendingEvents/ViewTable.js index 87389352f6788..de020f45c4ab1 100644 --- a/console/src/components/Services/EventTrigger/PendingEvents/ViewTable.js +++ b/console/src/components/Services/EventTrigger/PendingEvents/ViewTable.js @@ -4,7 +4,7 @@ import { vSetDefaults, vMakeRequest, vExpandHeading } from './ViewActions'; // e import { setTrigger } from '../EventActions'; import TableHeader from '../TableCommon/TableHeader'; import ViewRows from './ViewRows'; -import { replace } from 'react-router-redux'; +import { NotFoundError } from '../../../Error/PageNotFound'; const genHeadings = headings => { if (headings.length === 0) { @@ -130,12 +130,13 @@ class ViewTable extends Component { expandedRow, } = this.props; // eslint-disable-line no-unused-vars - // check if table exists + // check if trigger exists const currentTrigger = triggerList.find(s => s.name === triggerName); if (!currentTrigger) { - // dispatch a 404 route - dispatch(replace('/404')); + // throw a 404 exception + throw new NotFoundError('404 Not Found'); } + // Is this a view const isView = false; diff --git a/console/src/components/Services/EventTrigger/ProcessedEvents/ViewActions.js b/console/src/components/Services/EventTrigger/ProcessedEvents/ViewActions.js index 503cf2c67edd6..513bef2914e74 100644 --- a/console/src/components/Services/EventTrigger/ProcessedEvents/ViewActions.js +++ b/console/src/components/Services/EventTrigger/ProcessedEvents/ViewActions.js @@ -44,9 +44,6 @@ const vMakeRequest = () => { const state = getState(); const url = Endpoints.query; const originalTrigger = getState().triggers.currentTrigger; - const triggerList = getState().triggers.triggerList; - const triggerSchema = triggerList.filter(t => t.name === originalTrigger); - const triggerName = triggerSchema[0].name; const currentQuery = JSON.parse(JSON.stringify(state.triggers.view.query)); // count query const countQuery = JSON.parse(JSON.stringify(state.triggers.view.query)); @@ -64,7 +61,7 @@ const vMakeRequest = () => { currentQuery.columns[1].where = { $and: finalAndClause }; currentQuery.where = { name: state.triggers.currentTrigger }; countQuery.where.$and.push({ - trigger_name: state.triggers.currentTrigger, + trigger_name: originalTrigger, }); } else { // reset where for events @@ -76,7 +73,7 @@ const vMakeRequest = () => { currentQuery.where = { name: state.triggers.currentTrigger }; countQuery.where = { $and: [ - { trigger_name: triggerName }, + { trigger_name: state.triggers.currentTrigger }, { $or: [{ delivered: { $eq: true } }, { error: { $eq: true } }] }, ], }; diff --git a/console/src/components/Services/EventTrigger/ProcessedEvents/ViewTable.js b/console/src/components/Services/EventTrigger/ProcessedEvents/ViewTable.js index d3dbe6df615b0..96759db8a3726 100644 --- a/console/src/components/Services/EventTrigger/ProcessedEvents/ViewTable.js +++ b/console/src/components/Services/EventTrigger/ProcessedEvents/ViewTable.js @@ -4,7 +4,7 @@ import { vSetDefaults, vMakeRequest, vExpandHeading } from './ViewActions'; // e import { setTrigger } from '../EventActions'; import TableHeader from '../TableCommon/TableHeader'; import ViewRows from './ViewRows'; -import { replace } from 'react-router-redux'; +import { NotFoundError } from '../../../Error/PageNotFound'; const genHeadings = headings => { if (headings.length === 0) { @@ -144,8 +144,8 @@ class ViewTable extends Component { // check if table exists const currentTrigger = triggerList.find(s => s.name === triggerName); if (!currentTrigger) { - // dispatch a 404 route - dispatch(replace('/404')); + // throw a 404 exception + throw new NotFoundError('404 Not Found'); } // Is this a view const isView = false; diff --git a/console/src/components/Services/EventTrigger/RunningEvents/ViewTable.js b/console/src/components/Services/EventTrigger/RunningEvents/ViewTable.js index cdb0e26ef7caf..def15462defaf 100644 --- a/console/src/components/Services/EventTrigger/RunningEvents/ViewTable.js +++ b/console/src/components/Services/EventTrigger/RunningEvents/ViewTable.js @@ -4,7 +4,7 @@ import { vSetDefaults, vMakeRequest, vExpandHeading } from './ViewActions'; // e import { setTrigger } from '../EventActions'; import TableHeader from '../TableCommon/TableHeader'; import ViewRows from './ViewRows'; -import { replace } from 'react-router-redux'; +import { NotFoundError } from '../../../Error/PageNotFound'; const genHeadings = headings => { if (headings.length === 0) { @@ -134,8 +134,8 @@ class ViewTable extends Component { // check if table exists const currentTrigger = triggerList.find(s => s.name === triggerName); if (!currentTrigger) { - // dispatch a 404 route - dispatch(replace('/404')); + // throw a 404 exception + throw new NotFoundError('404 Not Found'); } // Is this a view const isView = false; diff --git a/console/src/components/Services/EventTrigger/StreamingLogs/Logs.js b/console/src/components/Services/EventTrigger/StreamingLogs/Logs.js index 9125577343a15..90fcb03244442 100644 --- a/console/src/components/Services/EventTrigger/StreamingLogs/Logs.js +++ b/console/src/components/Services/EventTrigger/StreamingLogs/Logs.js @@ -28,6 +28,7 @@ import * as tooltip from '../Common/Tooltips'; import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger'; import { convertDateTimeToLocale } from '../utils'; import Button from '../../../Common/Button/Button'; +import { NotFoundError } from '../../../Error/PageNotFound'; class StreamingLogs extends Component { constructor(props) { @@ -117,7 +118,12 @@ class StreamingLogs extends Component { const styles = require('../TableCommon/EventTable.scss'); + // check if trigger exists const currentTrigger = triggerList.find(s => s.name === triggerName); + if (!currentTrigger) { + // throw a 404 exception + throw new NotFoundError('404 Not Found'); + } const invocationColumns = [ 'redeliver', From aef2472ce31f518aa7e9b0948884c5d58f4adfee Mon Sep 17 00:00:00 2001 From: rikinsk Date: Fri, 7 Jun 2019 19:51:12 +0530 Subject: [PATCH 04/12] separate 500 page --- console/src/components/Error/ErrorBoundary.js | 58 +++--------------- console/src/components/Error/PageNotFound.js | 9 ++- console/src/components/Error/RuntimeError.js | 60 +++++++++++++++++++ 3 files changed, 77 insertions(+), 50 deletions(-) create mode 100644 console/src/components/Error/RuntimeError.js diff --git a/console/src/components/Error/ErrorBoundary.js b/console/src/components/Error/ErrorBoundary.js index 006a2e7e88f51..271d7169e3187 100644 --- a/console/src/components/Error/ErrorBoundary.js +++ b/console/src/components/Error/ErrorBoundary.js @@ -7,10 +7,8 @@ import { } from '../Services/Metadata/Actions'; import Spinner from '../Common/Spinner/Spinner'; -import { Link } from 'react-router'; -import Helmet from 'react-helmet'; - import PageNotFound, { NotFoundError } from './PageNotFound'; +import RuntimeError from './RuntimeError'; class ErrorBoundary extends React.Component { initialState = { @@ -55,60 +53,22 @@ class ErrorBoundary extends React.Component { } render() { - const errorImage = require('./error-logo.png'); - const styles = require('./ErrorPage.scss'); const { metadata } = this.props; + const { hasError, type } = this.state; - if (this.state.hasError && metadata.ongoingRequest) { + if (hasError && metadata.ongoingRequest) { return (
- {' '} - {' '} +
); } - if (this.state.hasError) { - if (this.state.type === '404') { - return ; - } - - return ( -
- -
-
-
-

Error

-
-
- Something went wrong. Head back{' '} - - Home - - . -
-
-
- You can report this issue on our{' '} - - GitHub - {' '} - or chat with us on{' '} - Discord -
-
-
- -
-
-
-
+ if (hasError) { + return type === '404' ? ( + + ) : ( + ); } diff --git a/console/src/components/Error/PageNotFound.js b/console/src/components/Error/PageNotFound.js index 4a6b047c333cc..cd680dfd098ee 100644 --- a/console/src/components/Error/PageNotFound.js +++ b/console/src/components/Error/PageNotFound.js @@ -12,6 +12,8 @@ class PageNotFound extends Component { const errorImage = require('./error-logo.png'); const styles = require('./ErrorPage.scss'); + const { resetCallback } = this.props; + return (
@@ -21,7 +23,11 @@ class PageNotFound extends Component {

404


- This page doesn't exist. Head back Home. + This page doesn't exist.Head back{' '} + + Home + + .
@@ -41,6 +47,7 @@ class PageNotFound extends Component { PageNotFound.propTypes = { dispatch: PropTypes.func.isRequired, + resetCallback: PropTypes.func.isRequired, }; export default connect()(PageNotFound); diff --git a/console/src/components/Error/RuntimeError.js b/console/src/components/Error/RuntimeError.js new file mode 100644 index 0000000000000..8a614e3ee0cac --- /dev/null +++ b/console/src/components/Error/RuntimeError.js @@ -0,0 +1,60 @@ +import PropTypes from 'prop-types'; +import React, { Component } from 'react'; +import { connect } from 'react-redux'; + +import { Link } from 'react-router'; +import Helmet from 'react-helmet'; + +class RuntimeError extends Component { + render() { + const errorImage = require('./error-logo.png'); + const styles = require('./ErrorPage.scss'); + + const { resetCallback } = this.props; + + return ( +
+ +
+
+
+

Error

+
+
+ Something went wrong. Head back{' '} + + Home + + . +
+
+
+ You can report this issue on our{' '} + + GitHub + {' '} + or chat with us on{' '} + Discord +
+
+
+ +
+
+
+
+ ); + } +} + +RuntimeError.propTypes = { + dispatch: PropTypes.func.isRequired, + resetCallback: PropTypes.func.isRequired, +}; + +export default connect()(RuntimeError); From e989c030a765938da661b00e7b8f6716a3d2d217 Mon Sep 17 00:00:00 2001 From: strongSoda Date: Mon, 10 Jun 2019 13:40:08 +0530 Subject: [PATCH 05/12] (data)render 404 for nonexistent resources --- .../Data/TableInsertItem/InsertItem.js | 11 +++++++++ .../Services/Data/TableModify/ModifyTable.js | 6 ++--- .../Data/TablePermissions/Permissions.js | 23 +++++++++++-------- .../Data/TableRelationships/Relationships.js | 7 ++++++ 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/console/src/components/Services/Data/TableInsertItem/InsertItem.js b/console/src/components/Services/Data/TableInsertItem/InsertItem.js index 0b3ff374751f6..fe3b4db827ecc 100644 --- a/console/src/components/Services/Data/TableInsertItem/InsertItem.js +++ b/console/src/components/Services/Data/TableInsertItem/InsertItem.js @@ -10,6 +10,8 @@ import { getPlaceholder, BOOLEAN, JSONB, JSONDTYPE } from '../utils'; import { getParentNodeByClass } from '../../../../utils/domFunctions'; +import { NotFoundError } from '../../../Error/PageNotFound'; + class InsertItem extends Component { constructor() { super(); @@ -48,6 +50,15 @@ class InsertItem extends Component { } = this.props; const styles = require('../../../Common/TableCommon/Table.scss'); + // check if table exists + const currentTable = schemas.find( + s => s.table_name === tableName && s.table_schema === currentSchema + ); + if (!currentTable) { + // throw a 404 exception + throw new NotFoundError('404 Not Found'); + } + const _columns = schemas.find( x => x.table_name === tableName && x.table_schema === currentSchema ).columns; diff --git a/console/src/components/Services/Data/TableModify/ModifyTable.js b/console/src/components/Services/Data/TableModify/ModifyTable.js index 725ebea014a63..32b05edfbe1a0 100644 --- a/console/src/components/Services/Data/TableModify/ModifyTable.js +++ b/console/src/components/Services/Data/TableModify/ModifyTable.js @@ -24,7 +24,7 @@ import TableCommentEditor from './TableCommentEditor'; import ForeignKeyEditor from './ForeignKeyEditor'; import UniqueKeyEditor from './UniqueKeyEditor'; import styles from './ModifyTable.scss'; -import { replace } from 'react-router-redux'; +import { NotFoundError } from '../../../Error/PageNotFound'; class ModifyTable extends React.Component { componentDidMount() { @@ -62,8 +62,8 @@ class ModifyTable extends React.Component { t => t.table_name === tableName && t.table_schema === currentSchema ); if (!tableSchema) { - dispatch(replace('/404')); - return null; + // throw a 404 exception + throw new NotFoundError('404 Not Found'); } const tableComment = tableSchema.comment; diff --git a/console/src/components/Services/Data/TablePermissions/Permissions.js b/console/src/components/Services/Data/TablePermissions/Permissions.js index 325d0ef8e843d..91a8dc986b11b 100644 --- a/console/src/components/Services/Data/TablePermissions/Permissions.js +++ b/console/src/components/Services/Data/TablePermissions/Permissions.js @@ -48,6 +48,8 @@ import { allOperators, getLegacyOperator } from './PermissionBuilder/utils'; import Button from '../../../Common/Button/Button'; import { defaultPresetsState } from '../DataState'; +import { NotFoundError } from '../../../Error/PageNotFound'; + class Permissions extends Component { constructor() { super(); @@ -66,16 +68,6 @@ class Permissions extends Component { componentDidMount() { this.props.dispatch({ type: RESET }); - const currentTableSchema = this.props.allSchemas.find( - t => - t.table_name === this.props.tableName && - t.table_schema === this.props.currentSchema - ); - - if (!currentTableSchema) { - return; - } - this.props.dispatch(setTable(this.props.tableName)); } @@ -94,6 +86,17 @@ class Permissions extends Component { currentSchema, } = this.props; + const currentTableSchema = this.props.allSchemas.find( + t => + t.table_name === this.props.tableName && + t.table_schema === this.props.currentSchema + ); + + if (!currentTableSchema) { + // throw a 404 exception + throw new NotFoundError('404 Not Found'); + } + const styles = require('../TableModify/ModifyTable.scss'); const getAllRoles = allTableSchemas => { diff --git a/console/src/components/Services/Data/TableRelationships/Relationships.js b/console/src/components/Services/Data/TableRelationships/Relationships.js index 1921dfe3355ea..6185ed5906e4d 100644 --- a/console/src/components/Services/Data/TableRelationships/Relationships.js +++ b/console/src/components/Services/Data/TableRelationships/Relationships.js @@ -22,6 +22,7 @@ import Button from '../../../Common/Button/Button'; import AddManualRelationship from './AddManualRelationship'; import suggestedRelationshipsRaw from './autoRelations'; import RelationshipEditor from './RelationshipEditor'; +import { NotFoundError } from '../../../Error/PageNotFound'; const addRelationshipCellView = ( dispatch, @@ -330,6 +331,12 @@ class Relationships extends Component { const tableSchema = allSchemas.find( t => t.table_name === tableName && t.table_schema === currentSchema ); + + if (!tableSchema) { + // throw a 404 exception + throw new NotFoundError('404 Not Found'); + } + let alert = null; if (ongoingRequest) { alert = ( From ecd880b225320f76ba9b69ca4bb27ee8e9825e90 Mon Sep 17 00:00:00 2001 From: strongSoda Date: Mon, 10 Jun 2019 16:32:25 +0530 Subject: [PATCH 06/12] (remote schema) render 404 for nonexistent resources --- .../components/Services/CustomResolver/Edit/Edit.js | 12 ++++++++++++ .../components/Services/CustomResolver/Edit/View.js | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/console/src/components/Services/CustomResolver/Edit/Edit.js b/console/src/components/Services/CustomResolver/Edit/Edit.js index 3a637f1eb30ff..f6ea850cd6613 100644 --- a/console/src/components/Services/CustomResolver/Edit/Edit.js +++ b/console/src/components/Services/CustomResolver/Edit/Edit.js @@ -17,6 +17,8 @@ import Button from '../../../Common/Button/Button'; import { appPrefix, pageTitle } from '../constants'; +import { NotFoundError } from '../../../Error/PageNotFound'; + import globals from '../../../../Globals'; const prefixUrl = globals.urlPrefix + appPrefix; @@ -102,6 +104,15 @@ class Edit extends React.Component { } render() { + const currentResolver = this.props.allResolvers.find( + r => r.name === this.props.params.resolverName + ); + + if (!currentResolver) { + // throw a 404 exception + throw new NotFoundError('404 Not Found'); + } + const styles = require('../CustomResolver.scss'); const { isFetching, isRequesting, editState, migrationMode } = this.props; @@ -234,6 +245,7 @@ const mapStateToProps = state => { return { ...state.customResolverData.addData, ...state.customResolverData.headerData, + allResolvers: state.customResolverData.listData.resolvers, migrationMode: state.main.migrationMode, dataHeaders: { ...state.tables.dataHeaders }, }; diff --git a/console/src/components/Services/CustomResolver/Edit/View.js b/console/src/components/Services/CustomResolver/Edit/View.js index 9423169c43024..cdf2963a2e56c 100644 --- a/console/src/components/Services/CustomResolver/Edit/View.js +++ b/console/src/components/Services/CustomResolver/Edit/View.js @@ -13,6 +13,8 @@ import ReloadMetadata from '../../Metadata/MetadataOptions/ReloadMetadata'; import { appPrefix } from '../constants'; +import { NotFoundError } from '../../../Error/PageNotFound'; + import globals from '../../../../Globals'; const prefixUrl = globals.urlPrefix + appPrefix; @@ -49,6 +51,15 @@ class ViewStitchedSchema extends React.Component { } render() { + const currentResolver = this.props.allResolvers.find( + r => r.name === this.props.params.resolverName + ); + + if (!currentResolver) { + // throw a 404 exception + throw new NotFoundError('404 Not Found'); + } + const styles = require('../CustomResolver.scss'); const { resolverName } = this.props.params; @@ -171,6 +182,7 @@ const mapStateToProps = state => { return { ...state.customResolverData.addData, ...state.customResolverData.headerData, + allResolvers: state.customResolverData.listData.resolvers, dataHeaders: { ...state.tables.dataHeaders }, }; }; From 01c93b39ed9586981e5195163b1d6916d33ef7e2 Mon Sep 17 00:00:00 2001 From: rikinsk Date: Tue, 11 Jun 2019 23:27:32 +0530 Subject: [PATCH 07/12] . --- console/src/components/Error/PageNotFound.js | 2 +- .../Services/CustomResolver/Edit/Edit.js | 2 +- .../Services/CustomResolver/Edit/View.js | 2 +- .../components/Services/Data/DataActions.js | 6 ++-- .../Services/Data/DataPageContainer.js | 22 +++++++++--- .../Function/Modify/ModifyCustomFunction.js | 34 ++++++++++++++----- .../Data/Function/Permission/Permission.js | 26 ++++++++++++-- .../Data/Function/customFunctionReducer.js | 3 +- .../components/Services/Data/Schema/Schema.js | 10 +++--- .../Data/TableBrowseRows/ViewTable.js | 8 +++-- .../Data/TableInsertItem/InsertItem.js | 2 +- .../Services/Data/TableModify/ModifyTable.js | 2 +- .../Services/Data/TableModify/ModifyView.js | 9 ++++- .../Data/TablePermissions/Permissions.js | 2 +- .../Data/TableRelationships/Relationships.js | 2 +- .../TableRelationships/RelationshipsView.js | 7 ++++ .../Services/EventTrigger/Modify/Modify.js | 2 +- .../EventTrigger/PendingEvents/ViewTable.js | 2 +- .../EventTrigger/ProcessedEvents/ViewTable.js | 2 +- .../EventTrigger/RunningEvents/ViewTable.js | 2 +- .../EventTrigger/StreamingLogs/Logs.js | 2 +- 21 files changed, 109 insertions(+), 40 deletions(-) diff --git a/console/src/components/Error/PageNotFound.js b/console/src/components/Error/PageNotFound.js index cd680dfd098ee..b4adade2ea888 100644 --- a/console/src/components/Error/PageNotFound.js +++ b/console/src/components/Error/PageNotFound.js @@ -23,7 +23,7 @@ class PageNotFound extends Component {

404


- This page doesn't exist.Head back{' '} + This page doesn't exist. Head back{' '} Home diff --git a/console/src/components/Services/CustomResolver/Edit/Edit.js b/console/src/components/Services/CustomResolver/Edit/Edit.js index f6ea850cd6613..7a3c96d9d0f3a 100644 --- a/console/src/components/Services/CustomResolver/Edit/Edit.js +++ b/console/src/components/Services/CustomResolver/Edit/Edit.js @@ -110,7 +110,7 @@ class Edit extends React.Component { if (!currentResolver) { // throw a 404 exception - throw new NotFoundError('404 Not Found'); + throw new NotFoundError(); } const styles = require('../CustomResolver.scss'); diff --git a/console/src/components/Services/CustomResolver/Edit/View.js b/console/src/components/Services/CustomResolver/Edit/View.js index cdf2963a2e56c..a5425f76f3efd 100644 --- a/console/src/components/Services/CustomResolver/Edit/View.js +++ b/console/src/components/Services/CustomResolver/Edit/View.js @@ -57,7 +57,7 @@ class ViewStitchedSchema extends React.Component { if (!currentResolver) { // throw a 404 exception - throw new NotFoundError('404 Not Found'); + throw new NotFoundError(); } const styles = require('../CustomResolver.scss'); diff --git a/console/src/components/Services/Data/DataActions.js b/console/src/components/Services/Data/DataActions.js index 6733118518bbc..d8b8dc08ec4b2 100644 --- a/console/src/components/Services/Data/DataActions.js +++ b/console/src/components/Services/Data/DataActions.js @@ -396,8 +396,10 @@ const fetchFunctionInit = () => (dispatch, getState) => { ); }; -const updateCurrentSchema = schemaName => dispatch => { - dispatch(push(`${globals.urlPrefix}/data/schema/${schemaName}`)); +const updateCurrentSchema = (schemaName, redirect = true) => dispatch => { + if (redirect) { + dispatch(push(`${globals.urlPrefix}/data/schema/${schemaName}`)); + } Promise.all([ dispatch({ type: UPDATE_CURRENT_SCHEMA, currentSchema: schemaName }), diff --git a/console/src/components/Services/Data/DataPageContainer.js b/console/src/components/Services/Data/DataPageContainer.js index 8274e0ddb2f2b..7de606d39e254 100644 --- a/console/src/components/Services/Data/DataPageContainer.js +++ b/console/src/components/Services/Data/DataPageContainer.js @@ -7,6 +7,7 @@ import PageContainer from '../../Common/Layout/PageContainer/PageContainer'; import DataSubSidebar from './DataSubSidebar'; import { updateCurrentSchema } from './DataActions'; +import { NotFoundError } from '../../Error/PageNotFound'; const sectionPrefix = '/data'; @@ -20,6 +21,13 @@ const DataPageContainer = ({ }) => { const styles = require('../../Common/TableCommon/Table.scss'); + if (!schemaList.map(s => s.schema_name).includes(currentSchema)) { + dispatch(updateCurrentSchema('public', false)); + + // throw a 404 exception + throw new NotFoundError(); + } + const currentLocation = location.pathname; let migrationTab = null; @@ -42,6 +50,14 @@ const DataPageContainer = ({ dispatch(updateCurrentSchema(e.target.value)); }; + const getSchemaOptions = () => { + return schemaList.map(s => ( + + )); + }; + const sidebarContent = (
  • - {schemaList.map(s => ( - - ))} + {getSchemaOptions()}
diff --git a/console/src/components/Services/Data/Function/Modify/ModifyCustomFunction.js b/console/src/components/Services/Data/Function/Modify/ModifyCustomFunction.js index b4e976e771189..3f62a67c75645 100644 --- a/console/src/components/Services/Data/Function/Modify/ModifyCustomFunction.js +++ b/console/src/components/Services/Data/Function/Modify/ModifyCustomFunction.js @@ -23,12 +23,16 @@ import { } from '../customFunctionReducer'; import { SET_SQL } from '../../RawSQL/Actions'; +import { NotFoundError } from '../../../../Error/PageNotFound'; class ModifyCustomFunction extends React.Component { constructor() { super(); - this.state = {}; - this.state.deleteConfirmationError = null; + + this.state = { + deleteConfirmationError: null, + funcFetchCompleted: false, + }; } componentDidMount() { @@ -37,7 +41,11 @@ class ModifyCustomFunction extends React.Component { this.props.dispatch(push(prefixUrl)); } Promise.all([ - this.props.dispatch(fetchCustomFunction(functionName, schema)), + this.props + .dispatch(fetchCustomFunction(functionName, schema)) + .then(() => { + this.setState({ funcFetchCompleted: true }); + }), ]); } @@ -48,12 +56,16 @@ class ModifyCustomFunction extends React.Component { schema !== nextProps.params.schema ) { Promise.all([ - this.props.dispatch( - fetchCustomFunction( - nextProps.params.functionName, - nextProps.params.schema + this.props + .dispatch( + fetchCustomFunction( + nextProps.params.functionName, + nextProps.params.schema + ) ) - ), + .then(() => { + this.setState({ funcFetchCompleted: true }); + }), ]); } } @@ -108,6 +120,11 @@ class ModifyCustomFunction extends React.Component { isFetching, } = this.props.functions; + if (this.state.funcFetchCompleted && !functionName) { + // throw a 404 exception + throw new NotFoundError(); + } + const { migrationMode } = this.props; const baseUrl = `${appPrefix}/schema/${schema}/functions/${functionName}`; @@ -182,6 +199,7 @@ class ModifyCustomFunction extends React.Component { url: '', }); } + return (
{ + this.setState({ funcFetchCompleted: true }); + }), ]); } render() { @@ -39,6 +54,11 @@ class Permission extends React.Component { setOffTableSchema, } = this.props.functions; + if (this.state.funcFetchCompleted && !functionName) { + // throw a 404 exception + throw new NotFoundError(); + } + const { dispatch } = this.props; const baseUrl = `${appPrefix}/schema/${schema}/functions/${functionName}`; diff --git a/console/src/components/Services/Data/Function/customFunctionReducer.js b/console/src/components/Services/Data/Function/customFunctionReducer.js index d1c32529c007e..cc35f35adf25e 100644 --- a/console/src/components/Services/Data/Function/customFunctionReducer.js +++ b/console/src/components/Services/Data/Function/customFunctionReducer.js @@ -157,10 +157,9 @@ const fetchCustomFunction = (functionName, schema) => { }); return Promise.resolve(); } - return dispatch(_push('/')); }, error => { - console.error('Failed to fetch resolver' + JSON.stringify(error)); + console.error('Failed to fetch function' + JSON.stringify(error)); return dispatch({ type: CUSTOM_FUNCTION_FETCH_FAIL, data: error }); } ); diff --git a/console/src/components/Services/Data/Schema/Schema.js b/console/src/components/Services/Data/Schema/Schema.js index fb7ff3f5967a6..bebacf9ab2acc 100644 --- a/console/src/components/Services/Data/Schema/Schema.js +++ b/console/src/components/Services/Data/Schema/Schema.js @@ -133,9 +133,11 @@ class Schema extends Component { }; const getCurrentSchemaSection = () => { - const schemaOptions = schemaList.map(s => { - return ; - }); + const getSchemaOptions = () => { + return schemaList.map(s => ( + + )); + }; const getCreateSchemaSection = () => { let createSchemaSection = null; @@ -262,7 +264,7 @@ class Schema extends Component { } value={currentSchema} > - {schemaOptions} + {getSchemaOptions()}
diff --git a/console/src/components/Services/Data/TableBrowseRows/ViewTable.js b/console/src/components/Services/Data/TableBrowseRows/ViewTable.js index a69985c043d17..8b986ac634b1d 100644 --- a/console/src/components/Services/Data/TableBrowseRows/ViewTable.js +++ b/console/src/components/Services/Data/TableBrowseRows/ViewTable.js @@ -147,7 +147,7 @@ class ViewTable extends Component { query, curFilter, rows, - count, // eslint-disable-line no-unused-vars + count, activePath, migrationMode, ongoingRequest, @@ -160,16 +160,18 @@ class ViewTable extends Component { manualTriggers = [], triggeredRow, triggeredFunction, - } = this.props; // eslint-disable-line no-unused-vars + } = this.props; // check if table exists const currentTable = schemas.find( s => s.table_name === tableName && s.table_schema === currentSchema ); + if (!currentTable) { // throw a 404 exception - throw new NotFoundError('404 Not Found'); + throw new NotFoundError(); } + // Is this a view const isView = currentTable.table_type !== 'BASE TABLE'; diff --git a/console/src/components/Services/Data/TableInsertItem/InsertItem.js b/console/src/components/Services/Data/TableInsertItem/InsertItem.js index fe3b4db827ecc..b0dc6aaa5bf57 100644 --- a/console/src/components/Services/Data/TableInsertItem/InsertItem.js +++ b/console/src/components/Services/Data/TableInsertItem/InsertItem.js @@ -56,7 +56,7 @@ class InsertItem extends Component { ); if (!currentTable) { // throw a 404 exception - throw new NotFoundError('404 Not Found'); + throw new NotFoundError(); } const _columns = schemas.find( diff --git a/console/src/components/Services/Data/TableModify/ModifyTable.js b/console/src/components/Services/Data/TableModify/ModifyTable.js index 32b05edfbe1a0..09f6667a369f9 100644 --- a/console/src/components/Services/Data/TableModify/ModifyTable.js +++ b/console/src/components/Services/Data/TableModify/ModifyTable.js @@ -63,7 +63,7 @@ class ModifyTable extends React.Component { ); if (!tableSchema) { // throw a 404 exception - throw new NotFoundError('404 Not Found'); + throw new NotFoundError(); } const tableComment = tableSchema.comment; diff --git a/console/src/components/Services/Data/TableModify/ModifyView.js b/console/src/components/Services/Data/TableModify/ModifyView.js index 0efdffc852dbd..49bc41ef37ff1 100644 --- a/console/src/components/Services/Data/TableModify/ModifyView.js +++ b/console/src/components/Services/Data/TableModify/ModifyView.js @@ -12,6 +12,7 @@ import TableCommentEditor from './TableCommentEditor'; import { ordinalColSort } from '../utils'; import { setTable } from '../DataActions'; import Button from '../../../Common/Button/Button'; +import { NotFoundError } from '../../../Error/PageNotFound'; class ModifyView extends Component { componentDidMount() { @@ -45,7 +46,13 @@ class ModifyView extends Component { const tableSchema = allSchemas.find( t => t.table_name === tableName && t.table_schema === currentSchema - ); // eslint-disable-line no-unused-vars + ); + + if (!tableSchema) { + // throw a 404 exception + throw new NotFoundError(); + } + const tableComment = tableSchema.comment; let alert = null; diff --git a/console/src/components/Services/Data/TablePermissions/Permissions.js b/console/src/components/Services/Data/TablePermissions/Permissions.js index 91a8dc986b11b..fe4caac80ea87 100644 --- a/console/src/components/Services/Data/TablePermissions/Permissions.js +++ b/console/src/components/Services/Data/TablePermissions/Permissions.js @@ -94,7 +94,7 @@ class Permissions extends Component { if (!currentTableSchema) { // throw a 404 exception - throw new NotFoundError('404 Not Found'); + throw new NotFoundError(); } const styles = require('../TableModify/ModifyTable.scss'); diff --git a/console/src/components/Services/Data/TableRelationships/Relationships.js b/console/src/components/Services/Data/TableRelationships/Relationships.js index 6185ed5906e4d..5a9387451fd9c 100644 --- a/console/src/components/Services/Data/TableRelationships/Relationships.js +++ b/console/src/components/Services/Data/TableRelationships/Relationships.js @@ -334,7 +334,7 @@ class Relationships extends Component { if (!tableSchema) { // throw a 404 exception - throw new NotFoundError('404 Not Found'); + throw new NotFoundError(); } let alert = null; diff --git a/console/src/components/Services/Data/TableRelationships/RelationshipsView.js b/console/src/components/Services/Data/TableRelationships/RelationshipsView.js index c6d79416ba8d1..7f19249a36239 100644 --- a/console/src/components/Services/Data/TableRelationships/RelationshipsView.js +++ b/console/src/components/Services/Data/TableRelationships/RelationshipsView.js @@ -10,6 +10,7 @@ import { setTable, UPDATE_REMOTE_SCHEMA_MANUAL_REL } from '../DataActions'; import Button from '../../../Common/Button/Button'; import AddManualRelationship from './AddManualRelationship'; import RelationshipEditor from './RelationshipEditor'; +import { NotFoundError } from '../../../Error/PageNotFound'; class RelationshipsView extends Component { componentDidMount() { @@ -43,6 +44,12 @@ class RelationshipsView extends Component { const tableSchema = allSchemas.find( t => t.table_name === tableName && t.table_schema === currentSchema ); + + if (!tableSchema) { + // throw a 404 exception + throw new NotFoundError(); + } + let alert = null; if (ongoingRequest) { alert = ( diff --git a/console/src/components/Services/EventTrigger/Modify/Modify.js b/console/src/components/Services/EventTrigger/Modify/Modify.js index 10bef08c746aa..eddb8a0181d3c 100644 --- a/console/src/components/Services/EventTrigger/Modify/Modify.js +++ b/console/src/components/Services/EventTrigger/Modify/Modify.js @@ -43,7 +43,7 @@ class Modify extends React.Component { if (!currentTrigger) { // throw a 404 exception - throw new NotFoundError('404 Not Found'); + throw new NotFoundError(); } const { diff --git a/console/src/components/Services/EventTrigger/PendingEvents/ViewTable.js b/console/src/components/Services/EventTrigger/PendingEvents/ViewTable.js index de020f45c4ab1..4d7f306e6ef42 100644 --- a/console/src/components/Services/EventTrigger/PendingEvents/ViewTable.js +++ b/console/src/components/Services/EventTrigger/PendingEvents/ViewTable.js @@ -134,7 +134,7 @@ class ViewTable extends Component { const currentTrigger = triggerList.find(s => s.name === triggerName); if (!currentTrigger) { // throw a 404 exception - throw new NotFoundError('404 Not Found'); + throw new NotFoundError(); } // Is this a view diff --git a/console/src/components/Services/EventTrigger/ProcessedEvents/ViewTable.js b/console/src/components/Services/EventTrigger/ProcessedEvents/ViewTable.js index 96759db8a3726..cd1576ffb00dc 100644 --- a/console/src/components/Services/EventTrigger/ProcessedEvents/ViewTable.js +++ b/console/src/components/Services/EventTrigger/ProcessedEvents/ViewTable.js @@ -145,7 +145,7 @@ class ViewTable extends Component { const currentTrigger = triggerList.find(s => s.name === triggerName); if (!currentTrigger) { // throw a 404 exception - throw new NotFoundError('404 Not Found'); + throw new NotFoundError(); } // Is this a view const isView = false; diff --git a/console/src/components/Services/EventTrigger/RunningEvents/ViewTable.js b/console/src/components/Services/EventTrigger/RunningEvents/ViewTable.js index def15462defaf..4a4770cc70c91 100644 --- a/console/src/components/Services/EventTrigger/RunningEvents/ViewTable.js +++ b/console/src/components/Services/EventTrigger/RunningEvents/ViewTable.js @@ -135,7 +135,7 @@ class ViewTable extends Component { const currentTrigger = triggerList.find(s => s.name === triggerName); if (!currentTrigger) { // throw a 404 exception - throw new NotFoundError('404 Not Found'); + throw new NotFoundError(); } // Is this a view const isView = false; diff --git a/console/src/components/Services/EventTrigger/StreamingLogs/Logs.js b/console/src/components/Services/EventTrigger/StreamingLogs/Logs.js index 90fcb03244442..b4cf01c3c8ce4 100644 --- a/console/src/components/Services/EventTrigger/StreamingLogs/Logs.js +++ b/console/src/components/Services/EventTrigger/StreamingLogs/Logs.js @@ -122,7 +122,7 @@ class StreamingLogs extends Component { const currentTrigger = triggerList.find(s => s.name === triggerName); if (!currentTrigger) { // throw a 404 exception - throw new NotFoundError('404 Not Found'); + throw new NotFoundError(); } const invocationColumns = [ From 78e56d12a937b6a33bbb9574d7af8b636b231859 Mon Sep 17 00:00:00 2001 From: rikinsk Date: Wed, 12 Jun 2019 00:09:26 +0530 Subject: [PATCH 08/12] . --- .../Data/TableModify/ModifyActions.js | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/console/src/components/Services/Data/TableModify/ModifyActions.js b/console/src/components/Services/Data/TableModify/ModifyActions.js index 0cde79866f2a9..18cb72b933aa1 100644 --- a/console/src/components/Services/Data/TableModify/ModifyActions.js +++ b/console/src/components/Services/Data/TableModify/ModifyActions.js @@ -315,14 +315,14 @@ const saveForeignKeys = (index, tableSchema, columns) => { alter table "${schemaName}"."${tableName}" drop constraint "${generatedConstraintName}", add constraint "${constraintName}" foreign key (${Object.keys(oldConstraint.column_mapping) - .map(lc => `"${lc}"`) - .join(', ')}) + .map(lc => `"${lc}"`) + .join(', ')}) references "${oldConstraint.ref_table_table_schema}"."${ - oldConstraint.ref_table - }" + oldConstraint.ref_table +}" (${Object.values(oldConstraint.column_mapping) - .map(rc => `"${rc}"`) - .join(', ')}) + .map(rc => `"${rc}"`) + .join(', ')}) on update ${pgConfTypes[oldConstraint.on_update]} on delete ${pgConfTypes[oldConstraint.on_delete]}; `; @@ -571,10 +571,11 @@ const deleteTableSql = tableName => { const errorMsg = 'Deleting table failed'; const customOnSuccess = () => { - dispatch(updateSchemaInfo()).then(() => { - dispatch(_push('/')); - }); + dispatch(updateSchemaInfo()); + + dispatch(_push('/')); }; + const customOnError = err => { dispatch({ type: UPDATE_MIGRATION_STATUS_ERROR, data: err }); }; @@ -1206,24 +1207,24 @@ const saveColumnChangesSql = (colName, column) => { const schemaChangesUp = originalColType !== colType ? [ - { - type: 'run_sql', - args: { - sql: columnChangesUpQuery, - }, + { + type: 'run_sql', + args: { + sql: columnChangesUpQuery, }, - ] + }, + ] : []; const schemaChangesDown = originalColType !== colType ? [ - { - type: 'run_sql', - args: { - sql: columnChangesDownQuery, - }, + { + type: 'run_sql', + args: { + sql: columnChangesDownQuery, }, - ] + }, + ] : []; /* column default up/down migration */ From 781db2a8e097250b7cde748e50395491e2de8600 Mon Sep 17 00:00:00 2001 From: rikinsk Date: Thu, 13 Jun 2019 17:49:52 +0530 Subject: [PATCH 09/12] fix unwanted 404s --- .../Services/CustomResolver/Add/addResolverReducer.js | 5 +++-- console/src/components/Services/Data/Schema/Actions.js | 9 +++++---- .../src/components/Services/EventTrigger/EventActions.js | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/console/src/components/Services/CustomResolver/Add/addResolverReducer.js b/console/src/components/Services/CustomResolver/Add/addResolverReducer.js index c8444759e42bd..a57c3041db619 100644 --- a/console/src/components/Services/CustomResolver/Add/addResolverReducer.js +++ b/console/src/components/Services/CustomResolver/Add/addResolverReducer.js @@ -197,8 +197,9 @@ const addResolver = () => { const customOnSuccess = data => { Promise.all([ dispatch({ type: RESET }), - dispatch(push(`${prefixUrl}/manage/${resolveObj.name}/details`)), - dispatch(fetchResolvers()), + dispatch(fetchResolvers()).then(() => { + dispatch(push(`${prefixUrl}/manage/${resolveObj.name}/details`)); + }), dispatch({ type: getHeaderEvents.RESET_HEADER, data: data }), ]); }; diff --git a/console/src/components/Services/Data/Schema/Actions.js b/console/src/components/Services/Data/Schema/Actions.js index 04cdf1da3594b..435e1e6bdd014 100644 --- a/console/src/components/Services/Data/Schema/Actions.js +++ b/console/src/components/Services/Data/Schema/Actions.js @@ -43,10 +43,11 @@ export const createNewSchema = (schemaName, successCb, errorCb) => { const errorMsg = 'Error creating schema'; const customOnSuccess = () => { - dispatch(fetchSchemaList()); - if (successCb) { - successCb(); - } + dispatch(fetchSchemaList()).then(() => { + if (successCb) { + successCb(); + } + }); }; const customOnError = () => { if (errorCb) { diff --git a/console/src/components/Services/EventTrigger/EventActions.js b/console/src/components/Services/EventTrigger/EventActions.js index c8ebfe502ee28..815b511703c97 100644 --- a/console/src/components/Services/EventTrigger/EventActions.js +++ b/console/src/components/Services/EventTrigger/EventActions.js @@ -469,6 +469,7 @@ const deleteTrigger = triggerName => { // dispatch({ type: REQUEST_SUCCESS }); dispatch({ type: REQUEST_COMPLETE }); // modify trigger action dispatch(showSuccessNotification('Trigger Deleted')); + dispatch(push('/manage/triggers')); // remove this trigger from state const existingTriggers = getState().triggers.triggerList.filter( trigger => trigger.name !== triggerName @@ -477,7 +478,6 @@ const deleteTrigger = triggerName => { type: LOAD_TRIGGER_LIST, triggerList: existingTriggers, }); - dispatch(push('/manage/triggers')); return; }; const customOnError = () => { From 2276e4f990f4056cfe2f22fbdf8f9734a14872d2 Mon Sep 17 00:00:00 2001 From: rikinsk Date: Thu, 13 Jun 2019 18:06:13 +0530 Subject: [PATCH 10/12] fix 404s --- .../Services/Data/Function/customFunctionReducer.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/console/src/components/Services/Data/Function/customFunctionReducer.js b/console/src/components/Services/Data/Function/customFunctionReducer.js index cc35f35adf25e..f1b0c9968c243 100644 --- a/console/src/components/Services/Data/Function/customFunctionReducer.js +++ b/console/src/components/Services/Data/Function/customFunctionReducer.js @@ -275,12 +275,9 @@ const unTrackCustomFunction = () => { const errorMsg = 'Delete custom function failed'; const customOnSuccess = () => { - // dispatch({ type: REQUEST_SUCCESS }); - Promise.all([ - dispatch({ type: RESET }), - dispatch(_push('/')), - dispatch(fetchTrackedFunctions()), - ]); + dispatch(_push(`/schema/${currentSchema}`)); + dispatch({ type: RESET }); + dispatch(fetchTrackedFunctions()); }; const customOnError = error => { Promise.all([ From 88227cace5cac205cfadc4bd3c693add1bf0dac6 Mon Sep 17 00:00:00 2001 From: rikinsk Date: Thu, 13 Jun 2019 22:38:29 +0530 Subject: [PATCH 11/12] . --- .../CustomResolver/Add/addResolverReducer.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/console/src/components/Services/CustomResolver/Add/addResolverReducer.js b/console/src/components/Services/CustomResolver/Add/addResolverReducer.js index a57c3041db619..fce47eaaa7a2b 100644 --- a/console/src/components/Services/CustomResolver/Add/addResolverReducer.js +++ b/console/src/components/Services/CustomResolver/Add/addResolverReducer.js @@ -397,15 +397,10 @@ const modifyResolver = () => { const customOnSuccess = data => { // dispatch({ type: REQUEST_SUCCESS }); - Promise.all([ - dispatch({ type: RESET, data: data }), - dispatch(fetchResolvers()), - ]).then(() => { - return Promise.all([ - dispatch(fetchResolver(schemaName)), - dispatch(push(`${prefixUrl}/manage/${trimmedName}/details`)), - ]); - }); + dispatch({ type: RESET, data: data }); + dispatch(push(`${prefixUrl}/manage/${trimmedName}/details`)); + dispatch(fetchResolvers()); + dispatch(fetchResolver(schemaName)); }; const customOnError = error => { Promise.all([dispatch({ type: MODIFY_RESOLVER_FAIL, data: error })]); From b7a3f48804eed2e9dec5196f2d21c6f62dee680a Mon Sep 17 00:00:00 2001 From: rikinsk Date: Sat, 15 Jun 2019 13:21:18 +0530 Subject: [PATCH 12/12] . --- .../CustomResolver/Add/addResolverReducer.js | 161 +----------------- 1 file changed, 9 insertions(+), 152 deletions(-) diff --git a/console/src/components/Services/CustomResolver/Add/addResolverReducer.js b/console/src/components/Services/CustomResolver/Add/addResolverReducer.js index fce47eaaa7a2b..5da285dfc4620 100644 --- a/console/src/components/Services/CustomResolver/Add/addResolverReducer.js +++ b/console/src/components/Services/CustomResolver/Add/addResolverReducer.js @@ -305,21 +305,19 @@ const deleteResolver = () => { const modifyResolver = () => { return (dispatch, getState) => { const currState = getState().customResolverData.addData; + const remoteSchemaName = currState.name.trim().replace(/ +/g, ''); // const url = Endpoints.getSchema; const upQueryArgs = []; const downQueryArgs = []; - const migrationName = - 'update_remote_schema_' + currState.name.trim().replace(/ +/g, ''); - const schemaName = currState.name.trim().replace(/ +/g, ''); + const migrationName = 'update_remote_schema_' + remoteSchemaName; const deleteResolverUp = { type: 'remove_remote_schema', args: { name: currState.editState.originalName, }, }; - const trimmedName = currState.name.trim().replace(/ +/g, ''); const resolveObj = { - name: trimmedName, + name: remoteSchemaName, definition: { url: currState.manualUrl, url_from_env: currState.envName, @@ -350,7 +348,7 @@ const modifyResolver = () => { const deleteResolverDown = { type: 'remove_remote_schema', args: { - name: trimmedName, + name: remoteSchemaName, }, }; const resolveDownObj = { @@ -398,9 +396,11 @@ const modifyResolver = () => { const customOnSuccess = data => { // dispatch({ type: REQUEST_SUCCESS }); dispatch({ type: RESET, data: data }); - dispatch(push(`${prefixUrl}/manage/${trimmedName}/details`)); - dispatch(fetchResolvers()); - dispatch(fetchResolver(schemaName)); + dispatch(push(`${prefixUrl}/manage/schemas`)); // Hack to avoid 404 + dispatch(fetchResolvers()).then(() => { + dispatch(push(`${prefixUrl}/manage/${remoteSchemaName}/details`)); + }); + dispatch(fetchResolver(remoteSchemaName)); }; const customOnError = error => { Promise.all([dispatch({ type: MODIFY_RESOLVER_FAIL, data: error })]); @@ -422,149 +422,6 @@ const modifyResolver = () => { }; }; -/* -const modifyResolver = () => { - return (dispatch, getState) => { - const currState = getState().customResolverData.addData; - // const url = Endpoints.getSchema; - let upQueryArgs = []; - let downQueryArgs = []; - const migrationName = 'update_add_schema_' + currState.name.trim(); - const schemaName = currState.name.trim(); - const deleteResolverUp = { - type: 'remove_remote_schema', - args: { - name: currState.editState.originalName, - }, - }; - - upQueryArgs.push(deleteResolverUp); - - // Delete the new one and create the old one - const resolveDownObj = { - name: currState.editState.originalName, - url: currState.editState.originalUrl, - url_from_env: currState.editState.originalEnvUrl, - headers: [], - }; - - resolveDownObj.headers = [...currState.editState.originalHeaders]; - if (resolveDownObj.url) { - delete resolveDownObj.url_from_env; - } else { - delete resolveDownObj.url; - } - - const createResolverDown = { - type: 'add_remote_schema', - args: { - ...resolveDownObj, - }, - }; - downQueryArgs.push(createResolverDown); - - let upQuery = { - type: 'bulk', - args: upQueryArgs, - }; - let downQuery = { - type: 'bulk', - args: downQueryArgs, - }; - const requestMsg = 'Modifying schema...'; - const successMsg = 'Schema modified'; - const errorMsg = 'Modify schema failed'; - - const customOnSuccess = () => { - // dispatch({ type: REQUEST_SUCCESS }); - // Do the modify thing here - upQueryArgs = []; - downQueryArgs = []; - const resolveObj = { - name: currState.name.trim(), - url: currState.manualUrl, - url_from_env: currState.envName, - headers: [], - }; - - resolveObj.headers = [ - ...getReqHeader(getState().customResolverData.headerData.headers), - ]; - if (resolveObj.url) { - delete resolveObj.url_from_env; - } else { - delete resolveObj.url; - } - - const createResolverUp = { - type: 'add_remote_schema', - args: { - ...resolveObj, - }, - }; - upQueryArgs.push(createResolverUp); - - const deleteResolverDown = { - type: 'remove_remote_schema', - args: { - name: currState.name, - }, - }; - downQueryArgs.push(deleteResolverDown); - - upQuery = { - type: 'bulk', - args: upQueryArgs, - }; - downQuery = { - type: 'bulk', - args: downQueryArgs, - }; - - const tOnSuccess = () => { - Promise.all([ - dispatch({ type: RESET }), - dispatch(fetchResolvers()), - ]).then(() => { - return dispatch(fetchResolver(schemaName)); - }); - }; - const tOnError = error => { - Promise.all([dispatch({ type: MODIFY_RESOLVER_FAIL, data: error })]); - }; - - return dispatch( - makeRequest( - upQuery.args, - downQuery.args, - migrationName, - tOnSuccess, - tOnError, - requestMsg, - successMsg, - errorMsg - ) - ); - }; - const customOnError = error => { - Promise.all([dispatch({ type: MODIFY_RESOLVER_FAIL, data: error })]); - }; - - dispatch({ type: MODIFYING_RESOLVER }); - return dispatch( - makeRequest( - upQuery.args, - downQuery.args, - migrationName, - customOnSuccess, - customOnError, - requestMsg - ) - ); - }; -}; -*/ - const addResolverReducer = (state = addState, action) => { switch (action.type) { case MANUAL_URL_CHANGED: