You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by gi...@git.apache.org on 2017/08/07 12:44:13 UTC

[GitHub] garrensmith commented on a change in pull request #947: WIP: Refactor CORS addon

garrensmith commented on a change in pull request #947: WIP: Refactor CORS addon
URL: https://github.com/apache/couchdb-fauxton/pull/947#discussion_r131641946
 
 

 ##########
 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);
 
 Review comment:
   Could you rather use https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf
 
----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services