Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cache_update.js « graphql « clusters_list « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4d12bc8151cf6480e5855c5dd4f4556315a1b146 (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
import produce from 'immer';
import { getAgentConfigPath } from '../clusters_util';

export const hasErrors = ({ errors = [] }) => errors?.length;

export function addAgentToStore(store, createClusterAgent, query, variables) {
  if (!hasErrors(createClusterAgent)) {
    const { clusterAgent } = createClusterAgent;
    const sourceData = store.readQuery({
      query,
      variables,
    });

    const data = produce(sourceData, (draftData) => {
      const configuration = {
        id: clusterAgent.id,
        name: clusterAgent.name,
        path: getAgentConfigPath(clusterAgent.name),
        webPath: clusterAgent.webPath,
        __typename: 'TreeEntry',
      };

      draftData.project.clusterAgents.nodes.push(clusterAgent);
      draftData.project.clusterAgents.count += 1;
      draftData.project.repository.tree.trees.nodes.push(configuration);
    });

    store.writeQuery({
      query,
      variables,
      data,
    });
  }
}

export function addAgentConfigToStore(
  store,
  clusterAgentTokenCreate,
  clusterAgent,
  query,
  variables,
) {
  if (!hasErrors(clusterAgentTokenCreate)) {
    const sourceData = store.readQuery({
      query,
      variables,
    });

    const data = produce(sourceData, (draftData) => {
      const configuration = {
        agentName: clusterAgent.name,
        __typename: 'AgentConfiguration',
      };

      draftData.project.clusterAgents.nodes.push(clusterAgent);
      draftData.project.agentConfigurations.nodes.push(configuration);
    });

    store.writeQuery({
      query,
      variables,
      data,
    });
  }
}