garrensmith commented on a change in pull request #947: WIP: Refactor CORS addon
URL: https://github.com/apache/couchdb-fauxton/pull/947#discussion_r131642151
##########
File path: app/addons/cors/components/CORSScreen.js
##########
@@ -0,0 +1,150 @@
+import React, { Component } from "react";
+import app from "../../../app";
+import ReactComponents from "../../components/react-components";
+import FauxtonComponents from "../../fauxton/components";
+import Origins from "./Origins";
+import OriginInput from "./OriginInput";
+import OriginTable from "./OriginTable";
+
+const LoadLines = ReactComponents.LoadLines;
+const ConfirmationModal = FauxtonComponents.ConfirmationModal;
+
+export default class CORSScreen extends Component {
+
+ constructor (props) {
+ super(props);
+ }
+
+ componentDidMount() {
+ // const { dispatch, url } = this.props;
+ this.props.fetchAndLoadCORSOptions();
+ }
+
+ enableCorsChange () {
+ console.log("CORSScreen.enableCorsChange:", this.props.corsEnabled, 'to',
!this.props.corsEnabled);
+ if (this.props.corsEnabled && !_.isEmpty(this.props.origins)) {
+ const result =
window.confirm(app.i18n.en_US['cors-disable-cors-prompt']);
+ if (!result) { return; }
+ }
+ this.props.saveCORS({
+ corsEnabled: !this.props.corsEnabled,
+ origins: this.props.origins,
+ node: this.props.node
+ });
+ }
+
+ save () {
+ console.log(">>>>>>Actions.saveCors");
+ this.props.saveCORS({
+ corsEnabled: this.props.corsEnabled,
+ origins: this.props.origins,
+ node: this.props.node
+ });
+ }
+
+ originChange (isAllOrigins) {
+ if (isAllOrigins && !_.isEmpty(this.props.origins)) {
+ const result = window.confirm('Are you sure? Switching to all origin
domains will overwrite your specific origin domains.');
+ if (!result) { return; }
+ }
+ this.props.saveCORS({
+ corsEnabled: this.props.corsEnabled,
+ origins: isAllOrigins ? ['*'] : [],
+ node: this.props.node
+ });
+ console.log("exiting CORSScreen.originChange(isAllOrigins);");
+ }
+
+ addOrigin (origin) {
+ this.props.saveCORS({
+ corsEnabled: this.props.corsEnabled,
+ origins: this.props.origins.concat(origin),
+ node: this.props.node
+ });
+ console.log("exiting CORSScreen.addOrigin(origin);", origin);
+ }
+
+ updateOrigin (updatedOrigin, originalOrigin) {
+ const newOrigins = this.props.origins.slice();
+ const index = _.indexOf(newOrigins, originalOrigin);
+ if (index === -1) { return; }
+ newOrigins[index] = updatedOrigin;
+
+ this.props.saveCORS({
+ corsEnabled: this.props.corsEnabled,
+ origins: newOrigins,
+ node: this.props.node
+ });
+ console.log("exiting CORSScreen.updateOrigin(updatedOrigin,
originalOrigin);", updatedOrigin, originalOrigin);
+ }
+
+ deleteOrigin () {
+ console.log("CORSScreen deleteOrigin");
+ const index = _.indexOf(this.props.origins, this.props.domainToDelete);
+ if (index === -1) { return; }
+ const newOrigins = [
+ ...this.props.origins.slice(0, index),
+ ...this.props.origins.slice(index + 1)
+ ];
+ this.props.saveCORS({
+ corsEnabled: this.props.corsEnabled,
+ origins: newOrigins,
+ node: this.props.node
+ });
+ //newOrigins[index] = updatedOrigin;
+ console.log("exiting CORSScreen.deleteOrigin(this.props.domainToDelete);");
+ }
+
+ render () {
+ const isVisible = _.all([this.props.corsEnabled,
!this.props.isAllOrigins]);
Review comment:
Can you use
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services