garrensmith commented on a change in pull request #971: Refactor 
documents/mango addon to use Redux
URL: https://github.com/apache/couchdb-fauxton/pull/971#discussion_r138631567
 
 

 ##########
 File path: app/addons/documents/mango/mango.reducers.js
 ##########
 @@ -0,0 +1,164 @@
+// 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 app from "../../../app";
+import ActionTypes from "./mango.actiontypes";
+import MangoHelper from "./mango.helper";
+import constants from "./mango.constants";
+
+const defaultQueryIndexCode = {
+  "index": {
+    "fields": ["_id"]
+  },
+  "type": "json"
+};
+
+const defaultQueryFindCode = {
+  "selector": {
+    "_id": { "$gt": null }
+  }
+};
+
+const createSelectItem = (code) => {
+  // ensure we're working with a deserialized query object
+  const object = typeof code === "string" ? JSON.parse(code) : code;
+
+  const singleLineValue = JSON.stringify(object);
+  const multiLineValue = MangoHelper.formatCode(object);
+
+  return {
+    label: singleLineValue,
+    value: multiLineValue,
+    className: 'mango-select-entry'
+  };
+};
+
+const getDefaultHistory = () => {
+  return [createSelectItem(defaultQueryFindCode)];
+};
+
+const getDefaultQueryIndexTemplates = () => {
+  return constants.INDEX_TEMPLATES.map((el) => {
+    const item = createSelectItem(el.code);
+    item.label = el.label || item.label;
+    return item;
+  });
+};
+
+const HISTORY_LIMIT = 5;
+
+const initialState = {
+  queryFindCode: defaultQueryFindCode,
+  queryIndexCode: defaultQueryIndexCode,
+  queryFindCodeChanged: false,
+  explainPlan: undefined,
+  history: getDefaultHistory(),
+  historyKey: 'default',
+  queryIndexTemplates: getDefaultQueryIndexTemplates()
+};
+
+const loadQueryHistory = (databaseName) => {
+  const historyKey = databaseName + '_queryhistory';
+  return app.utils.localStorageGet(historyKey) || getDefaultHistory();
+};
+
+const updateQueryHistory = ({ historyKey, history }, queryCode, label) => {
+  //const history = getHistory();
 
 Review comment:
   I think we can remove
 
----------------------------------------------------------------
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

Reply via email to