garrensmith commented on a change in pull request #986: Refactor map/reduce views to use Redux URL: https://github.com/apache/couchdb-fauxton/pull/986#discussion_r142065307
########## File path: app/addons/documents/index-editor/components/IndexEditor.js ########## @@ -0,0 +1,170 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +import React, { Component } from "react"; +import ReactDOM from "react-dom"; +import app from "../../../../app"; +import FauxtonAPI from "../../../../core/api"; +import ReactComponents from "../../../components/react-components"; +import Stores from "../stores"; +import Actions from "../actions"; +import DesignDocSelector from './DesignDocSelector'; +import ReduceEditor from './ReduceEditor'; + +const getDocUrl = app.helpers.getDocUrl; +const CodeEditorPanel = ReactComponents.CodeEditorPanel; +const store = Stores.indexEditorStore; +const ConfirmButton = ReactComponents.ConfirmButton; +const LoadLines = ReactComponents.LoadLines; + +export default class IndexEditor extends Component { + + constructor(props) { + super(props); + this.state = this.getStoreState(); + } + + getStoreState() { + return { + database: store.getDatabase(), + isNewView: store.isNewView(), + viewName: store.getViewName(), + designDocs: store.getDesignDocs(), + designDocList: store.getAvailableDesignDocs(), + originalViewName: store.getOriginalViewName(), + originalDesignDocName: store.getOriginalDesignDocName(), + newDesignDoc: store.isNewDesignDoc(), + designDocId: store.getDesignDocId(), + newDesignDocName: store.getNewDesignDocName(), + saveDesignDoc: store.getSaveDesignDoc(), + map: store.getMap(), + isLoading: store.isLoading() + }; + } + + onChange() { + this.setState(this.getStoreState()); + } + + componentDidMount() { + store.on('change', this.onChange, this); + } + + componentWillUnmount() { + store.off('change', this.onChange); + } + + // the code editor is a standalone component, so if the user goes from one edit view page to another, we need to + // force an update of the editor panel + componentDidUpdate(prevProps, prevState) { + if (this.state.map !== prevState.map && this.refs.mapEditor) { + this.refs.mapEditor.update(); + } + } + + saveView(el) { + el.preventDefault(); + + if (!this.refs.designDocSelector.validate()) { + return; + } + + Actions.saveView({ + database: this.state.database, + newView: this.state.isNewView, + viewName: this.state.viewName, + designDoc: this.state.saveDesignDoc, + designDocId: this.state.designDocId, + newDesignDoc: this.state.newDesignDoc, + originalViewName: this.state.originalViewName, + originalDesignDocName: this.state.originalDesignDocName, + map: this.refs.mapEditor.getValue(), + reduce: this.refs.reduceEditor.getReduceValue(), + designDocs: this.state.designDocs + }); + } + + viewChange(el) { + Actions.changeViewName(el.target.value); + } + + updateMapCode(code) { + Actions.updateMapCode(code); + } + + render() { + if (this.state.isLoading) { + return ( + <div className="define-view"> + <LoadLines /> + </div> + ); + } + + var pageHeader = (this.state.isNewView) ? 'New View' : 'Edit View'; Review comment: Can you make these all `const` ---------------------------------------------------------------- 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
