diff --git a/frontend/src/app/data-entry/agent-form/agent-episodes-form/agent-episodes-form.component.ts b/frontend/src/app/data-entry/agent-form/agent-episodes-form/agent-episodes-form.component.ts index e8c27358..04d6add1 100644 --- a/frontend/src/app/data-entry/agent-form/agent-episodes-form/agent-episodes-form.component.ts +++ b/frontend/src/app/data-entry/agent-form/agent-episodes-form/agent-episodes-form.component.ts @@ -15,7 +15,6 @@ import { FormStatus } from '../../shared/types'; import { MutationResult } from 'apollo-angular'; import { differenceBy } from '@shared/utils'; -const REFETCH_QUERIES = ['DataEntryAgentEpisodes']; @Component({ selector: 'lc-agent-episodes-form', @@ -83,7 +82,7 @@ export class AgentEpisodesFormComponent implements OnDestroy { entityType: Entity.Agent, }; this.addMutation.mutate({ input }, { - refetchQueries: REFETCH_QUERIES, + update: (cache) => this.updateCache(episodeID, agentID, cache), }).pipe( tap(() => this.status$.next('loading')) ).subscribe(this.mutationObserver); @@ -95,7 +94,9 @@ export class AgentEpisodesFormComponent implements OnDestroy { episode: episodeID, entityType: Entity.Agent, }; - this.removeMutation.mutate(data, { refetchQueries: REFETCH_QUERIES }).pipe( + this.removeMutation.mutate(data, { + update: (cache) => this.updateCache(episodeID, agentID, cache), + }).pipe( tap(() => this.status$.next('loading')) ).subscribe(this.mutationObserver) } @@ -109,6 +110,12 @@ export class AgentEpisodesFormComponent implements OnDestroy { this.status$.next('error'); } + private updateCache(episodeID: string, agentID: string, cache: any) { + cache.evict({ id: cache.identify({ __typename: "EpisodeType", id: episodeID }) }); + cache.evict({ id: cache.identify({ __typename: "AgentDescriptionType", id: agentID }) }); + cache.gc(); + } + private availableEpisodes( data: DataEntryAgentEpisodesQuery ): { name: string, id: string }[] { diff --git a/frontend/src/app/data-entry/episode-form/episode-entities-form/episode-entities-form.component.ts b/frontend/src/app/data-entry/episode-form/episode-entities-form/episode-entities-form.component.ts index cc292fb0..c39a7c54 100644 --- a/frontend/src/app/data-entry/episode-form/episode-entities-form/episode-entities-form.component.ts +++ b/frontend/src/app/data-entry/episode-form/episode-entities-form/episode-entities-form.component.ts @@ -144,8 +144,8 @@ export class EpisodeEntitiesFormComponent implements OnChanges, OnDestroy { onError(error: any) { console.error(error); this.toastService.show({ - header: 'Creating agent failed', - body: 'Could not create agent', + header: `Adding ${this.entityName} failed`, + body: `Could not add ${this.entityName}`, type: 'danger', }) this.status$.next('error');