summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/import_projects/store/mutations.js
blob: b88de0268e70a16e0cd3fe945a120b157745ddd4 (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
import Vue from 'vue';
import * as types from './mutation_types';

export default {
  [types.SET_INITIAL_DATA](state, data) {
    Object.assign(state, data);
  },

  [types.REQUEST_REPOS](state) {
    state.isLoadingRepos = true;
  },

  [types.RECEIVE_REPOS_SUCCESS](state, { importedProjects, providerRepos, namespaces }) {
    state.isLoadingRepos = false;

    state.importedProjects = importedProjects;
    state.providerRepos = providerRepos;
    state.namespaces = namespaces;
  },

  [types.RECEIVE_REPOS_ERROR](state) {
    state.isLoadingRepos = false;
  },

  [types.REQUEST_IMPORT](state, repoId) {
    state.reposBeingImported.push(repoId);
  },

  [types.RECEIVE_IMPORT_SUCCESS](state, { importedProject, repoId }) {
    const existingRepoIndex = state.reposBeingImported.indexOf(repoId);
    if (state.reposBeingImported.includes(repoId))
      state.reposBeingImported.splice(existingRepoIndex, 1);

    const providerRepoIndex = state.providerRepos.findIndex(
      providerRepo => providerRepo.id === repoId,
    );
    state.providerRepos.splice(providerRepoIndex, 1);
    state.importedProjects.unshift(importedProject);
  },

  [types.RECEIVE_IMPORT_ERROR](state, repoId) {
    const repoIndex = state.reposBeingImported.indexOf(repoId);
    if (state.reposBeingImported.includes(repoId)) state.reposBeingImported.splice(repoIndex, 1);
  },

  [types.RECEIVE_JOBS_SUCCESS](state, updatedProjects) {
    updatedProjects.forEach(updatedProject => {
      const existingProject = state.importedProjects.find(
        importedProject => importedProject.id === updatedProject.id,
      );

      Vue.set(existingProject, 'importStatus', updatedProject.importStatus);
    });
  },
};