summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/clusters_list/graphql/cache_update.js
blob: dd633820952d67badd14c963d4502b96e48fca7c (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
import produce from 'immer';
import { getAgentConfigPath } from '../clusters_util';

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

  const data = produce(sourceData, (draftData) => {
    const configuration = {
      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,
  });
}