summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/registry/stores/mutations.js
blob: 208c3c39866b0a1cbb11b5cedb399a6102e77794 (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
import * as types from './mutation_types';
import { parseIntPagination, normalizeHeaders } from '../../lib/utils/common_utils';

export default {

  [types.SET_MAIN_ENDPOINT](state, endpoint) {
    Object.assign(state, { endpoint });
  },

  [types.SET_REPOS_LIST](state, list) {
    Object.assign(state, {
      repos: list.map(el => ({
        canDelete: !!el.destroy_path,
        destroyPath: el.destroy_path,
        id: el.id,
        isLoading: false,
        list: [],
        location: el.location,
        name: el.path,
        tagsPath: el.tags_path,
      })),
    });
  },

  [types.TOGGLE_MAIN_LOADING](state) {
    Object.assign(state, { isLoading: !state.isLoading });
  },

  [types.SET_REGISTRY_LIST](state, { repo, resp, headers }) {
    const listToUpdate = state.repos.find(el => el.id === repo.id);

    const normalizedHeaders = normalizeHeaders(headers);
    const pagination = parseIntPagination(normalizedHeaders);

    listToUpdate.pagination = pagination;

    listToUpdate.list = resp.map(element => ({
      tag: element.name,
      revision: element.revision,
      shortRevision: element.short_revision,
      size: element.total_size,
      layers: element.layers,
      location: element.location,
      createdAt: element.created_at,
      destroyPath: element.destroy_path,
      canDelete: !!element.destroy_path,
    }));
  },

  [types.TOGGLE_REGISTRY_LIST_LOADING](state, list) {
    const listToUpdate = state.repos.find(el => el.id === list.id);
    listToUpdate.isLoading = !listToUpdate.isLoading;
  },
};