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

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

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

export function removeArtifactFromStore(store, deletedArtifactId, query, variables) {
  if (hasErrors(deletedArtifactId)) return;

  const sourceData = store.readQuery({
    query,
    variables,
  });

  const data = produce(sourceData, (draftData) => {
    draftData.project.jobs.nodes = draftData.project.jobs.nodes.map((jobNode) => {
      return {
        ...jobNode,
        artifacts: {
          ...jobNode.artifacts,
          nodes: jobNode.artifacts.nodes.filter(({ id }) => id !== deletedArtifactId),
        },
      };
    });
  });

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