summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/error_tracking/store/list/mutations.js
blob: 82d747e83f80d551ded0ec110f1a5d5ea9d8a939 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import AccessorUtils from '~/lib/utils/accessor';
import * as types from './mutation_types';

export default {
  [types.SET_ERRORS](state, data) {
    state.errors = convertObjectPropsToCamelCase(data, { deep: true });
  },
  [types.SET_LOADING](state, loading) {
    state.loading = loading;
  },
  [types.SET_INDEX_PATH](state, path) {
    state.indexPath = path;
  },
  [types.ADD_RECENT_SEARCH](state, searchTerm) {
    if (searchTerm.length === 0) {
      return;
    }
    // remove any existing item, then add it to the start of the list
    const recentSearches = state.recentSearches.filter((s) => s !== searchTerm);
    recentSearches.unshift(searchTerm);
    // only keep the last 5
    state.recentSearches = recentSearches.slice(0, 5);

    if (AccessorUtils.isLocalStorageAccessSafe()) {
      localStorage.setItem(
        `recent-searches${state.indexPath}`,
        JSON.stringify(state.recentSearches),
      );
    }
  },
  [types.CLEAR_RECENT_SEARCHES](state) {
    state.recentSearches = [];
    if (AccessorUtils.isLocalStorageAccessSafe()) {
      localStorage.removeItem(`recent-searches${state.indexPath}`);
    }
  },
  [types.LOAD_RECENT_SEARCHES](state) {
    const recentSearches = localStorage.getItem(`recent-searches${state.indexPath}`) || [];
    try {
      state.recentSearches = JSON.parse(recentSearches);
    } catch (e) {
      state.recentSearches = [];
      throw e;
    }
  },
  [types.SET_PAGINATION](state, pagination) {
    state.pagination = pagination;
  },
  [types.SET_CURSOR](state, cursor) {
    state.cursor = cursor;
  },
  [types.SET_SORT_FIELD](state, field) {
    state.sortField = field;
  },
  [types.SET_SEARCH_QUERY](state, query) {
    state.searchQuery = query;
  },
  [types.SET_ENDPOINT](state, endpoint) {
    state.endpoint = endpoint;
  },
  [types.REMOVE_IGNORED_RESOLVED_ERRORS](state, error) {
    state.errors = state.errors.filter((err) => err.id !== error);
  },
  [types.SET_STATUS_FILTER](state, query) {
    state.statusFilter = query;
  },
};