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

export default {
  [types.SET_MAIN_ENDPOINT](state, endpoint) {
    state.endpoint = endpoint;
  },

  [types.SET_IS_DELETE_DISABLED](state, isDeleteDisabled) {
    state.isDeleteDisabled = isDeleteDisabled;
  },

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

  [types.TOGGLE_MAIN_LOADING](state) {
    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: Boolean(element.destroy_path),
    }));
  },

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

    listToUpdate.isLoading = !listToUpdate.isLoading;
  },
};