diff options
Diffstat (limited to 'app/assets/javascripts/clusters_list/graphql/cache_update.js')
-rw-r--r-- | app/assets/javascripts/clusters_list/graphql/cache_update.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/app/assets/javascripts/clusters_list/graphql/cache_update.js b/app/assets/javascripts/clusters_list/graphql/cache_update.js new file mode 100644 index 00000000000..dd633820952 --- /dev/null +++ b/app/assets/javascripts/clusters_list/graphql/cache_update.js @@ -0,0 +1,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, + }); +} |