From 9310a4734d940ac825889dde2523b9747b942291 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 1 May 2018 16:16:41 +0200 Subject: [PATCH 1/9] Fix viewing/editing empty org contact email --- .../src/routes/Configure/components/OrganizationSettings.js | 3 +-- client/coral-framework/utils/index.js | 6 +++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/client/coral-admin/src/routes/Configure/components/OrganizationSettings.js b/client/coral-admin/src/routes/Configure/components/OrganizationSettings.js index 2bbe1a230..f3daeffc2 100644 --- a/client/coral-admin/src/routes/Configure/components/OrganizationSettings.js +++ b/client/coral-admin/src/routes/Configure/components/OrganizationSettings.js @@ -84,7 +84,6 @@ class OrganizationSettings extends React.Component { render() { const { settings, slotPassthrough, canSave } = this.props; const hasErrors = this.state.errors.length; - return (

{t('configure.organization_info_copy')}

@@ -125,7 +124,7 @@ class OrganizationSettings extends React.Component { [styles.editable]: this.state.editing, })} onChange={this.updateEmail} - value={settings.organizationContactEmail} + value={settings.organizationContactEmail || ''} id={t('configure.organization_contact_email')} readOnly={!this.state.editing} /> diff --git a/client/coral-framework/utils/index.js b/client/coral-framework/utils/index.js index 66792b9b3..8dc8fe113 100644 --- a/client/coral-framework/utils/index.js +++ b/client/coral-framework/utils/index.js @@ -237,7 +237,11 @@ export function getTotalReactionsCount(actionSummaries) { // Like lodash merge but does not recurse into arrays. export function mergeExcludingArrays(objValue, srcValue) { - if (typeof srcValue === 'object' && !Array.isArray(srcValue)) { + if ( + typeof srcValue === 'object' && + !Array.isArray(srcValue) && + srcValue !== null + ) { return assignWith({}, objValue, srcValue, mergeExcludingArrays); } return srcValue; From e8cd938b65059b21b77bd5f169ee180c258df86c Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 1 May 2018 16:18:17 +0200 Subject: [PATCH 2/9] Move next route out of state --- .../src/routes/Configure/containers/Configure.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/client/coral-admin/src/routes/Configure/containers/Configure.js b/client/coral-admin/src/routes/Configure/containers/Configure.js index 7f0951154..73e643343 100644 --- a/client/coral-admin/src/routes/Configure/containers/Configure.js +++ b/client/coral-admin/src/routes/Configure/containers/Configure.js @@ -20,7 +20,7 @@ import OrganizationSettings from './OrganizationSettings'; import { withRouter } from 'react-router'; class ConfigureContainer extends React.Component { - state = { nextRoute: '' }; + nextRoute = ''; savePending = async () => { await this.props.updateSettings(this.props.pending); @@ -40,10 +40,9 @@ class ConfigureContainer extends React.Component { }; gotoNextRoute = () => { - const { nextRoute } = this.state; - if (nextRoute) { - this.props.router.push(nextRoute); - this.setState({ nextRoute: '' }); + if (this.nextRoute) { + this.props.router.push(this.nextRoute); + this.nextRoute = ''; } }; @@ -51,7 +50,7 @@ class ConfigureContainer extends React.Component { const nextRoute = `/admin/configure/${section}`; if (this.shouldShowSaveDialog()) { - await this.setState({ nextRoute }); + this.nextRoute = nextRoute; this.props.showSaveDialog(); } else { // Just go to the section @@ -65,7 +64,7 @@ class ConfigureContainer extends React.Component { routeLeave = ({ pathname }) => { if (this.shouldShowSaveDialog()) { - this.setState({ nextRoute: pathname }); + this.nextRoute = pathname; this.props.showSaveDialog(); return false; } From fd3f5e511625a83d451547f05840834e878ed657 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 1 May 2018 16:19:47 +0200 Subject: [PATCH 3/9] Cleanup leave hook --- .../src/routes/Configure/containers/Configure.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client/coral-admin/src/routes/Configure/containers/Configure.js b/client/coral-admin/src/routes/Configure/containers/Configure.js index 73e643343..4910a2ec4 100644 --- a/client/coral-admin/src/routes/Configure/containers/Configure.js +++ b/client/coral-admin/src/routes/Configure/containers/Configure.js @@ -21,6 +21,7 @@ import { withRouter } from 'react-router'; class ConfigureContainer extends React.Component { nextRoute = ''; + unregisterLeaveHook = null; savePending = async () => { await this.props.updateSettings(this.props.pending); @@ -71,7 +72,14 @@ class ConfigureContainer extends React.Component { }; componentDidMount() { - this.props.router.setRouteLeaveHook(this.props.route, this.routeLeave); + this.unregisterLeaveHook = this.props.router.setRouteLeaveHook( + this.props.route, + this.routeLeave + ); + } + + componentWillUnmount() { + this.unregisterLeaveHook(); } render() { From 2af3a94ce476d6aab1cfbfaa966b15a459f82858 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 1 May 2018 16:29:40 +0200 Subject: [PATCH 4/9] No dialog when switching sections --- .../src/routes/Configure/containers/Configure.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/client/coral-admin/src/routes/Configure/containers/Configure.js b/client/coral-admin/src/routes/Configure/containers/Configure.js index 4910a2ec4..6cba60524 100644 --- a/client/coral-admin/src/routes/Configure/containers/Configure.js +++ b/client/coral-admin/src/routes/Configure/containers/Configure.js @@ -49,14 +49,7 @@ class ConfigureContainer extends React.Component { handleSectionChange = async section => { const nextRoute = `/admin/configure/${section}`; - - if (this.shouldShowSaveDialog()) { - this.nextRoute = nextRoute; - this.props.showSaveDialog(); - } else { - // Just go to the section - this.props.router.push(nextRoute); - } + this.props.router.push(nextRoute); }; shouldShowSaveDialog = () => { From 68b1670a55c7832a0e146880ecf2e37b2e315525 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 1 May 2018 16:33:21 +0200 Subject: [PATCH 5/9] Prevent reload or closing tab or window with pending data --- .../src/routes/Configure/containers/Configure.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/client/coral-admin/src/routes/Configure/containers/Configure.js b/client/coral-admin/src/routes/Configure/containers/Configure.js index 6cba60524..c4b8bc0ca 100644 --- a/client/coral-admin/src/routes/Configure/containers/Configure.js +++ b/client/coral-admin/src/routes/Configure/containers/Configure.js @@ -52,12 +52,20 @@ class ConfigureContainer extends React.Component { this.props.router.push(nextRoute); }; - shouldShowSaveDialog = () => { + navigationPrompt = e => { + if (this.hasPendingData()) { + const confirmationMessage = 'Changes that you made may not be saved.'; + e.returnValue = confirmationMessage; // Gecko, Trident, Chrome 34+ + return confirmationMessage; // Gecko, WebKit, Chrome <34 + } + }; + + hasPendingData = () => { return !!Object.keys(this.props.pending).length; }; routeLeave = ({ pathname }) => { - if (this.shouldShowSaveDialog()) { + if (this.hasPendingData()) { this.nextRoute = pathname; this.props.showSaveDialog(); return false; @@ -69,10 +77,12 @@ class ConfigureContainer extends React.Component { this.props.route, this.routeLeave ); + window.addEventListener('beforeunload', this.navigationPrompt); } componentWillUnmount() { this.unregisterLeaveHook(); + window.removeEventListener('beforeunload', this.navigationPrompt); } render() { From 74821a4d4c36094d81204d8a088f7315e3efab67 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 1 May 2018 18:14:07 +0200 Subject: [PATCH 6/9] Readd save dialog on section change --- .../src/routes/Configure/containers/Configure.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/client/coral-admin/src/routes/Configure/containers/Configure.js b/client/coral-admin/src/routes/Configure/containers/Configure.js index c4b8bc0ca..3d2789974 100644 --- a/client/coral-admin/src/routes/Configure/containers/Configure.js +++ b/client/coral-admin/src/routes/Configure/containers/Configure.js @@ -49,7 +49,13 @@ class ConfigureContainer extends React.Component { handleSectionChange = async section => { const nextRoute = `/admin/configure/${section}`; - this.props.router.push(nextRoute); + if (this.hasPendingData()) { + this.nextRoute = nextRoute; + this.props.showSaveDialog(); + } else { + // Just go to the section + this.props.router.push(nextRoute); + } }; navigationPrompt = e => { From 06682225c892802ba36af4afdfdab54333974621 Mon Sep 17 00:00:00 2001 From: Kim Gardner Date: Tue, 1 May 2018 13:25:33 -0400 Subject: [PATCH 7/9] Fix error message --- locales/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locales/en.yml b/locales/en.yml index ff0d7e487..393d01e23 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -250,7 +250,7 @@ en: ALREADY_EXISTS: "Resource already exists" INVALID_ASSET_URL: "Assert URL is invalid" CANNOT_IGNORE_STAFF: "Cannot ignore Staff members." - email: "Not a valid E-Mail" + email: "Please enter a valid email." confirm_password: "Passwords don't match. Please check again" network_error: "Failed to connect to server. Check your internet connection and try again." email_not_verified: "Email address {0} not verified." From b014225b73bbad8b286340531a3604f50e1d9ae5 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Tue, 1 May 2018 12:02:39 -0600 Subject: [PATCH 8/9] fixes for index creation --- models/index.js | 34 +++++++++++++++++++++ models/schema/index.js | 15 +-------- plugin-api/beta/server/getReactionConfig.js | 2 +- services/mongoose.js | 6 +--- 4 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 models/index.js diff --git a/models/index.js b/models/index.js new file mode 100644 index 000000000..c783f43e7 --- /dev/null +++ b/models/index.js @@ -0,0 +1,34 @@ +const { reduce } = require('lodash'); +const { CREATE_MONGO_INDEXES } = require('../config'); + +const Action = require('./action'); +const Asset = require('./asset'); +const Comment = require('./comment'); +const Migration = require('./migration'); +const Setting = require('./setting'); +const User = require('./user'); + +const schema = { Action, Asset, Comment, Migration, Setting, User }; + +// Provide the schema to each of the plugins so that they can add in indexes if +// it is enabled. +if (CREATE_MONGO_INDEXES) { + const plugins = require('../services/plugins'); + + // Remap all of the models to their driver reference via the `collection` + // field. + const collections = reduce( + schema, + (collections, model, modelName) => { + collections[modelName] = model.collection; + return collections; + }, + {} + ); + + // Defer the instantiation of the index caller functions when we're creating + // indexes. + plugins.defer('server', 'indexes', ({ indexes }) => { + indexes(collections); + }); +} diff --git a/models/schema/index.js b/models/schema/index.js index 976b437c0..c33402078 100644 --- a/models/schema/index.js +++ b/models/schema/index.js @@ -1,5 +1,3 @@ -const { CREATE_MONGO_INDEXES } = require('../../config'); - const Action = require('./action'); const Asset = require('./asset'); const Comment = require('./comment'); @@ -7,15 +5,4 @@ const Migration = require('./migration'); const Setting = require('./setting'); const User = require('./user'); -const schema = { Action, Asset, Comment, Migration, Setting, User }; - -// Provide the schema to each of the plugins so that they can add in indexes if -// it is enabled. -if (CREATE_MONGO_INDEXES) { - const plugins = require('../../services/plugins'); - plugins.get('server', 'indexes').map(({ indexes }) => { - indexes(schema); - }); -} - -module.exports = schema; +module.exports = { Action, Asset, Comment, Migration, Setting, User }; diff --git a/plugin-api/beta/server/getReactionConfig.js b/plugin-api/beta/server/getReactionConfig.js index da075d76c..68dc3dd5d 100644 --- a/plugin-api/beta/server/getReactionConfig.js +++ b/plugin-api/beta/server/getReactionConfig.js @@ -128,7 +128,7 @@ function getReactionConfig(reaction) { return { typeDefs, indexes: ({ Comment }) => { - Comment.index( + Comment.ensureIndex( { created_at: 1, [`action_counts.${sc(reaction)}`]: 1, diff --git a/services/mongoose.js b/services/mongoose.js index 4e242cf47..48cd34012 100644 --- a/services/mongoose.js +++ b/services/mongoose.js @@ -63,10 +63,6 @@ module.exports = mongoose; // here. No point also in importing this if we're not actually doing any // indexing now. if (CREATE_MONGO_INDEXES) { - require('../models/action'); - require('../models/asset'); - require('../models/comment'); - require('../models/setting'); - require('../models/user'); + require('../models'); require('./migration'); } From d12310026bcc02847f05d21d766b837e8c4ed881 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Tue, 1 May 2018 15:41:05 -0600 Subject: [PATCH 9/9] Fixes to shema loading --- models/index.js | 34 ------------------ plugin-api/beta/server/getReactionConfig.js | 38 ++++++++------------- services/mongoose.js | 7 +++- 3 files changed, 20 insertions(+), 59 deletions(-) delete mode 100644 models/index.js diff --git a/models/index.js b/models/index.js deleted file mode 100644 index c783f43e7..000000000 --- a/models/index.js +++ /dev/null @@ -1,34 +0,0 @@ -const { reduce } = require('lodash'); -const { CREATE_MONGO_INDEXES } = require('../config'); - -const Action = require('./action'); -const Asset = require('./asset'); -const Comment = require('./comment'); -const Migration = require('./migration'); -const Setting = require('./setting'); -const User = require('./user'); - -const schema = { Action, Asset, Comment, Migration, Setting, User }; - -// Provide the schema to each of the plugins so that they can add in indexes if -// it is enabled. -if (CREATE_MONGO_INDEXES) { - const plugins = require('../services/plugins'); - - // Remap all of the models to their driver reference via the `collection` - // field. - const collections = reduce( - schema, - (collections, model, modelName) => { - collections[modelName] = model.collection; - return collections; - }, - {} - ); - - // Defer the instantiation of the index caller functions when we're creating - // indexes. - plugins.defer('server', 'indexes', ({ indexes }) => { - indexes(collections); - }); -} diff --git a/plugin-api/beta/server/getReactionConfig.js b/plugin-api/beta/server/getReactionConfig.js index 68dc3dd5d..e90a06122 100644 --- a/plugin-api/beta/server/getReactionConfig.js +++ b/plugin-api/beta/server/getReactionConfig.js @@ -2,23 +2,24 @@ const { SEARCH_OTHER_USERS } = require('../../../perms/constants'); const { ErrNotFound, ErrAlreadyExists } = require('../../../errors'); const pluralize = require('pluralize'); const sc = require('snake-case'); -// const { CREATE_MONGO_INDEXES } = require('../../../config'); +const { CREATE_MONGO_INDEXES } = require('../../../config'); +const Comment = require('models/comment'); function getReactionConfig(reaction) { reaction = reaction.toLowerCase(); - // if (CREATE_MONGO_INDEXES) { - // // Create the index on the comment model based on the reaction config. - // CommentModel.collection.createIndex( - // { - // created_at: 1, - // [`action_counts.${sc(reaction)}`]: 1, - // }, - // { - // background: true, - // } - // ); - // } + if (CREATE_MONGO_INDEXES) { + // Create the index on the comment model based on the reaction config. + Comment.collection.createIndex( + { + created_at: 1, + [`action_counts.${sc(reaction)}`]: 1, + }, + { + background: true, + } + ); + } const reactionPlural = pluralize(reaction); const Reaction = reaction.charAt(0).toUpperCase() + reaction.slice(1); @@ -127,17 +128,6 @@ function getReactionConfig(reaction) { return { typeDefs, - indexes: ({ Comment }) => { - Comment.ensureIndex( - { - created_at: 1, - [`action_counts.${sc(reaction)}`]: 1, - }, - { - background: true, - } - ); - }, context: { Sort: () => ({ Comments: { diff --git a/services/mongoose.js b/services/mongoose.js index 48cd34012..167b0d45b 100644 --- a/services/mongoose.js +++ b/services/mongoose.js @@ -63,6 +63,11 @@ module.exports = mongoose; // here. No point also in importing this if we're not actually doing any // indexing now. if (CREATE_MONGO_INDEXES) { - require('../models'); + require('../models/action'); + require('../models/asset'); + require('../models/comment'); + require('../models/migration'); + require('../models/setting'); + require('../models/user'); require('./migration'); }