Skip to content

Commit

Permalink
fix location cache issue in agent form
Browse files Browse the repository at this point in the history
  • Loading branch information
lukavdplas committed Oct 4, 2024
1 parent 6e4c189 commit 0c33239
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 42 deletions.
32 changes: 5 additions & 27 deletions frontend/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1057,14 +1057,7 @@ export type DataEntryAgentDescriptionQueryVariables = Exact<{
}>;


export type DataEntryAgentDescriptionQuery = { __typename?: 'Query', agentDescription?: { __typename?: 'AgentDescriptionType', id: string, isGroup: boolean, gender?: { __typename?: 'AgentDescriptionGenderType', id: string, gender: Gender, sourceMention: SourceMention, note: string } | null, location?: { __typename?: 'AgentDescriptionLocationType', id: string, sourceMention: SourceMention, note: string, location: { __typename?: 'SpaceDescriptionType', id: string } } | null, source: { __typename?: 'SourceType', id: string } } | null };

export type LocationsInSourceListQueryVariables = Exact<{
id: Scalars['ID']['input'];
}>;


export type LocationsInSourceListQuery = { __typename?: 'Query', spaceDescriptions: Array<{ __typename?: 'SpaceDescriptionType', id: string, name: string }> };
export type DataEntryAgentDescriptionQuery = { __typename?: 'Query', agentDescription?: { __typename?: 'AgentDescriptionType', id: string, isGroup: boolean, gender?: { __typename?: 'AgentDescriptionGenderType', id: string, gender: Gender, sourceMention: SourceMention, note: string } | null, location?: { __typename?: 'AgentDescriptionLocationType', id: string, sourceMention: SourceMention, note: string, location: { __typename?: 'SpaceDescriptionType', id: string } } | null, source: { __typename?: 'SourceType', id: string, spaces: Array<{ __typename?: 'SpaceDescriptionType', id: string, name: string }> } } | null };

export type DataEntryAgentEpisodesQueryVariables = Exact<{
id: Scalars['ID']['input'];
Expand Down Expand Up @@ -1437,6 +1430,10 @@ export const DataEntryAgentDescriptionDocument = gql`
}
source {
id
spaces {
id
name
}
}
}
}
Expand All @@ -1448,25 +1445,6 @@ export const DataEntryAgentDescriptionDocument = gql`
export class DataEntryAgentDescriptionGQL extends Apollo.Query<DataEntryAgentDescriptionQuery, DataEntryAgentDescriptionQueryVariables> {
override document = DataEntryAgentDescriptionDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
}
export const LocationsInSourceListDocument = gql`
query LocationsInSourceList($id: ID!) {
spaceDescriptions(sourceId: $id) {
id
name
}
}
`;

@Injectable({
providedIn: 'root'
})
export class LocationsInSourceListGQL extends Apollo.Query<LocationsInSourceListQuery, LocationsInSourceListQueryVariables> {
override document = LocationsInSourceListDocument;

constructor(apollo: Apollo.Apollo) {
super(apollo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ <h3>Location</h3>
<select class="form-select" id="input-location"
[formControl]="form.controls.location.controls.location">
<ng-container *ngIf="locations$ | async as locationData">
<option *ngFor="let location of locationData.spaceDescriptions"
<option *ngFor="let location of locationData"
[value]="location.id">
{{location.name}}
</option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import {
DataEntryUpdateAgentMutation,
Gender,
SourceMention,
LocationsInSourceListGQL,
LocationsInSourceListQuery,
UpdateAgentInput,
} from 'generated/graphql';
import { Observable, map, switchMap, shareReplay, filter, debounceTime, distinctUntilChanged, withLatestFrom, BehaviorSubject, tap, skip } from 'rxjs';
Expand Down Expand Up @@ -48,11 +46,11 @@ export class AgentDescriptionFormComponent implements OnDestroy {
location: new FormControl<string | null>(null),
sourceMention: new FormControl<SourceMention>(SourceMention.Direct),
note: new FormControl<string>('', { updateOn: 'blur' }),
})
}),
});

isGroup$: Observable<boolean>;
locations$: Observable<LocationsInSourceListQuery>;
locations$: Observable<{ id: string, name: string }[]>;

status$ = new BehaviorSubject<FormStatus>('idle');

Expand All @@ -62,7 +60,6 @@ export class AgentDescriptionFormComponent implements OnDestroy {

constructor(
private agentQuery: DataEntryAgentDescriptionGQL,
private locationsQuery: LocationsInSourceListGQL,
private agentMutation: DataEntryUpdateAgentGQL,
private toastService: ToastService,
private formService: FormService,
Expand All @@ -78,10 +75,8 @@ export class AgentDescriptionFormComponent implements OnDestroy {
map(result => result.agentDescription?.isGroup || false),
);
this.locations$ = this.data$.pipe(
map(data => data.agentDescription?.source.id),
map(data => data.agentDescription?.source.spaces),
filter(_.negate(_.isUndefined)),
switchMap(id => this.locationsQuery.watch({ id }).valueChanges),
map(result => result.data),
shareReplay(1),
);
this.data$.subscribe(this.updateFormData.bind(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ query DataEntryAgentDescription($id: ID!) {
}
source {
id
spaces {
id
name
}
}
}
}

This file was deleted.

0 comments on commit 0c33239

Please sign in to comment.