Allow changing wordlist and domains using the updateSettings mutation

This commit is contained in:
Chi Vinh Le
2017-10-09 16:51:27 +07:00
parent 0a190a9838
commit c52e42c644
4 changed files with 66 additions and 6 deletions
+12 -1
View File
@@ -1,4 +1,15 @@
import update from 'immutability-helper';
import mapValues from 'lodash/mapValues';
// Map nested object leaves. Array objects are considered leaves.
function mapLeaves(o, mapper) {
return mapValues(o, (val) => {
if (typeof val === 'object' && !Array.isArray(val)) {
return mapLeaves(val, mapper);
}
return mapper(val);
});
}
export default {
mutations: {
@@ -33,7 +44,7 @@ export default {
updateQueries: {
TalkAdmin_Configure: (prev) => {
const updated = update(prev, {
settings: {$merge: input},
settings: mapLeaves(input, (leaf) => ({$set: leaf})),
});
return updated;
}
@@ -6,7 +6,7 @@ import withQuery from 'coral-framework/hocs/withQuery';
import {Spinner} from 'coral-ui';
import {notify} from 'coral-framework/actions/notification';
import PropTypes from 'prop-types';
import merge from 'lodash/merge';
import assignWith from 'lodash/assignWith';
import {withUpdateSettings} from 'coral-framework/graphql/mutations';
import {getErrorMessages, getDefinitionName} from 'coral-framework/utils';
import StreamSettings from './StreamSettings';
@@ -16,10 +16,20 @@ import {clearPending, setActiveSection} from '../../../actions/configure';
import Configure from '../components/Configure';
// Like lodash merge but does not recurse into arrays.
const mergeExcludingArrays = (objValue, srcValue) => {
if (typeof srcValue === 'object' && !Array.isArray(srcValue)) {
return assignWith({}, objValue, srcValue, mergeExcludingArrays);
}
return srcValue;
};
class ConfigureContainer extends Component {
// Merge current settings with pending settings.
getMergedSettings = (props = this.props) => merge({}, props.root.settings, props.pending);
getMergedSettings = (props = this.props) => {
return assignWith({}, props.root.settings, props.pending, mergeExcludingArrays);
}
// Cached merged settings.
mergedSettings = this.getMergedSettings();