export default function mangoquery()

in app/addons/documents/mango/mango.reducers.js [145:239]


export default function mangoquery(state = initialState, action) {
  const { options } = action;
  switch (action.type) {

    case ActionTypes.MANGO_SET_DB:
      return {
        ...state,
        database: options.database,
        historyKey: options.database ? options.database.id : 'default'
      };

    case ActionTypes.MANGO_LOAD_QUERY_HISTORY:
      const hist = loadQueryHistory(options.databaseName);
      return {
        ...state,
        history: hist,
        historyKey: options.databaseName + '_queryhistory',
        queryFindCode: JSON.parse(hist[0].value),
      };

    case ActionTypes.MANGO_NEW_QUERY_FIND_CODE:
      return {
        ...state,
        queryFindCode: options.queryCode,
        history: updateQueryHistory(state, options.queryCode)
      };

    case ActionTypes.MANGO_RESET:
      return {
        ...state,
        getLoadingIndexes: options.isLoading
      };

    case ActionTypes.MANGO_LOAD_INDEX_TEMPLATES:
      const templates = loadIndexTemplates();
      return {
        ...state,
        queryIndexTemplates: templates,
        queryIndexCode: JSON.parse(templates[0].value),
      };

    case ActionTypes.MANGO_NEW_QUERY_CREATE_INDEX_TEMPLATE:
      return {
        ...state,
        queryIndexCode: options.code,
        queryIndexTemplates: updateQueryIndexTemplates(state, options.code, options.label)
      };

    case ActionTypes.MANGO_SHOW_EXPLAIN_RESULTS:
      return {
        ...state,
        explainPlan: options.explainPlan
      };

    case ActionTypes.MANGO_HIDE_EXPLAIN_RESULTS:
      return {
        ...state,
        explainPlan: false
      };

    case ActionTypes.MANGO_SET_EXECUTION_STATS_SUPPORTED:
      return {
        ...state,
        executionStatsSupported: true,
      };

    case ActionTypes.SET_EXPLAIN_VIEW_FORMAT:
      return {
        ...state,
        explainViewFormat: options,
      };

    case ActionTypes.SHOW_EXPLAIN_REASONS_MODAL:
      return {
        ...state,
        isReasonsModalVisible: true
      };

    case ActionTypes.HIDE_EXPLAIN_REASONS_MODAL:
      return {
        ...state,
        isReasonsModalVisible: false
      };

    case ActionTypes.EXPLAIN_RESULTS_REDUX_RESET_STATE:
      return {
        ...state,
        explainPlan: undefined,
        isReasonsModalVisible: false
      };

    default:
      return state;
  }
}