This is an automated email from the ASF dual-hosted git repository. garren pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/couchdb-fauxton.git
commit bcc74be1828e2b42dafcfad294e507813d7b6967 Author: Antonio Maranhao <[email protected]> AuthorDate: Fri Jul 12 11:28:11 2019 -0400 Allow overriding actions in cors addon After upgrading to Babel 7, it's no longer possible to override properties of an imported module. To workaround this, explicit functions were added to make the override possible. --- app/addons/cors/__tests__/actions.test.js | 2 +- app/addons/cors/actions.js | 35 ++++++++++++++++++++++------- app/addons/cors/components/CORSContainer.js | 15 +++++-------- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/app/addons/cors/__tests__/actions.test.js b/app/addons/cors/__tests__/actions.test.js index 15f1f15..1ad1034 100644 --- a/app/addons/cors/__tests__/actions.test.js +++ b/app/addons/cors/__tests__/actions.test.js @@ -11,7 +11,7 @@ // the License. import utils from "../../../../test/mocha/testUtils"; import FauxtonAPI from "../../../core/api"; -import * as Actions from "../actions"; +import Actions from "../actions"; import * as CorsAPI from "../api"; import sinon from "sinon"; diff --git a/app/addons/cors/actions.js b/app/addons/cors/actions.js index eb05dab..6fa4b00 100644 --- a/app/addons/cors/actions.js +++ b/app/addons/cors/actions.js @@ -14,7 +14,7 @@ import FauxtonAPI from "../../core/api"; import ActionTypes from "./actiontypes"; import * as CorsAPI from "./api"; -export const fetchAndLoadCORSOptions = (url, node) => (dispatch) => { +const fetchAndLoadCORSOptions = (url, node) => (dispatch) => { const fetchCors = CorsAPI.fetchCORSConfig(url); const fetchHttp = CorsAPI.fetchHttpdConfig(url); @@ -33,21 +33,21 @@ export const fetchAndLoadCORSOptions = (url, node) => (dispatch) => { }); }; -export const showLoadingBars = () => { +const showLoadingBars = () => { return { type: ActionTypes.CORS_SET_IS_LOADING, isLoading: true }; }; -export const hideLoadingBars = () => { +const hideLoadingBars = () => { return { type: ActionTypes.CORS_SET_IS_LOADING, isLoading: false }; }; -export const loadCORSOptions = (options) => { +const loadCORSOptions = (options) => { return { type: ActionTypes.EDIT_CORS, options: options, @@ -55,20 +55,20 @@ export const loadCORSOptions = (options) => { }; }; -export const showDomainDeleteConfirmation = (domain) => { +const showDomainDeleteConfirmation = (domain) => { return { type: ActionTypes.CORS_SHOW_DELETE_DOMAIN_MODAL, domainToDelete: domain }; }; -export const hideDomainDeleteConfirmation = () => { +const hideDomainDeleteConfirmation = () => { return { type: ActionTypes.CORS_HIDE_DELETE_DOMAIN_MODAL }; }; -export const saveCors = (url, options) => (dispatch) => { +const saveCors = (url, options) => (dispatch) => { const promises = []; promises.push(CorsAPI.updateEnableCorsToHttpd(url, options.node, options.corsEnabled)); @@ -101,10 +101,29 @@ const errorReason = (error) => { return 'Reason: ' + ((error && error.message) || 'n/a'); }; -export const sanitizeOrigins = (origins) => { +const sanitizeOrigins = (origins) => { if (_.isEmpty(origins)) { return ''; } return origins.join(','); }; + +const Actions = { + fetchAndLoadCORSOptions, + showLoadingBars, + hideLoadingBars, + showDomainDeleteConfirmation, + hideDomainDeleteConfirmation, + loadCORSOptions, + sanitizeOrigins, + saveCors, + overrideFetchAndLoadCORSOptions: (newFn) => { + Actions.fetchAndLoadCORSOptions = newFn; + }, + overrideSaveCors: (newFn) => { + Actions.saveCors = newFn; + } +}; + +export default Actions; diff --git a/app/addons/cors/components/CORSContainer.js b/app/addons/cors/components/CORSContainer.js index eece5ee..4e5de7d 100644 --- a/app/addons/cors/components/CORSContainer.js +++ b/app/addons/cors/components/CORSContainer.js @@ -1,9 +1,6 @@ import { connect } from 'react-redux'; import CORSScreen from './CORSScreen'; -import { - saveCors, showLoadingBars, fetchAndLoadCORSOptions, - showDomainDeleteConfirmation, hideDomainDeleteConfirmation -} from '../actions'; +import Actions from '../actions'; const mapStateToProps = ({ cors }) => { return { @@ -20,20 +17,20 @@ const mapStateToProps = ({ cors }) => { const mapDispatchToProps = (dispatch, ownProps) => { return { saveCORS: (options) => { - dispatch(showLoadingBars()); - dispatch(saveCors(ownProps.url, options)); + dispatch(Actions.showLoadingBars()); + dispatch(Actions.saveCors(ownProps.url, options)); }, fetchAndLoadCORSOptions: () => { - dispatch(fetchAndLoadCORSOptions(ownProps.url, ownProps.node)); + dispatch(Actions.fetchAndLoadCORSOptions(ownProps.url, ownProps.node)); }, showDeleteDomainConfirmation: (domain) => { - dispatch(showDomainDeleteConfirmation(domain)); + dispatch(Actions.showDomainDeleteConfirmation(domain)); }, hideDeleteDomainConfirmation: () => { - dispatch(hideDomainDeleteConfirmation()); + dispatch(Actions.hideDomainDeleteConfirmation()); } }; };
