debian-mirror-gitlab/app/assets/javascripts/artifacts/graphql/cache_update.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

31 lines
706 B
JavaScript
Raw Normal View History

2023-01-13 00:05:48 +05: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,
});
}