<commit_before>import {defaultRuleConfigs, DEFAULT_RULE_ID} from 'src/kapacitor/constants';
import _ from 'lodash';

export default function rules(state = {}, action) {
  switch (action.type) {
    case 'LOAD_DEFAULT_RULE': {
      const {queryID} = action.payload;
      return Object.assign({}, state, {
        [DEFAULT_RULE_ID]: {
          id: DEFAULT_RULE_ID,
          queryID,
          trigger: 'threshold',
          values: defaultRuleConfigs.threshold,
          message: '',
          alerts: [],
          every: '30s',
          name: 'My Rule',
        },
      });
    }

    case 'LOAD_RULES': {
      const theRules = action.payload.rules;
      const ruleIDs = theRules.map(r => r.id);
      return _.zipObject(ruleIDs, theRules);
    }

    case 'LOAD_RULE': {
      const {rule} = action.payload;
      return Object.assign({}, state, {
        [rule.id]: rule,
      });
    }

    case 'CHOOSE_TRIGGER': {
      const trigger = action.payload.trigger;
      const ruleID = action.payload.ruleID;
      return Object.assign({}, state, {
        [ruleID]: Object.assign({}, state[ruleID], {
          trigger: trigger.toLowerCase(),
          values: defaultRuleConfigs[trigger.toLowerCase()],
        }),
      });
    }

    case 'UPDATE_RULE_VALUES': {
      const {ruleID, trigger, values} = action.payload;
      return Object.assign({}, state, {<commit_msg>Changes default rule name to "Untitled Rule"<commit_after>import {defaultRuleConfigs, DEFAULT_RULE_ID} from 'src/kapacitor/constants';
import _ from 'lodash';

export default function rules(state = {}, action) {
  switch (action.type) {
    case 'LOAD_DEFAULT_RULE': {
      const {queryID} = action.payload;
      return Object.assign({}, state, {
        [DEFAULT_RULE_ID]: {
          id: DEFAULT_RULE_ID,
          queryID,
          trigger: 'threshold',
          values: defaultRuleConfigs.threshold,
          message: '',
          alerts: [],
          every: '30s',
          name: 'Untitled Rule',
        },
      });
    }

    case 'LOAD_RULES': {
      const theRules = action.payload.rules;
      const ruleIDs = theRules.map(r => r.id);
      return _.zipObject(ruleIDs, theRules);
    }

    case 'LOAD_RULE': {
      const {rule} = action.payload;
      return Object.assign({}, state, {
        [rule.id]: rule,
      });
    }

    case 'CHOOSE_TRIGGER': {
      const trigger = action.payload.trigger;
      const ruleID = action.payload.ruleID;
      return Object.assign({}, state, {
        [ruleID]: Object.assign({}, state[ruleID], {
          trigger: trigger.toLowerCase(),
          values: defaultRuleConfigs[trigger.toLowerCase()],
        }),
      });
    }

    case 'UPDATE_RULE_VALUES': {
      const {ruleID, trigger, values} = action.payload;
      return Object.assign({}, state, {
{'fraction_non_alphanumeric': 0.1375133594584966, 'fraction_numerical': 0.0014250089063056644, 'mean_word_length': 2.3230769230769233, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '229070', 'n_tokens_mistral': 859, 'n_tokens_neox': 856, 'n_words': 182}