From 5a9b7be1febcb0698a2a31144c64b159cbfe302a Mon Sep 17 00:00:00 2001 From: Janelle Law Date: Wed, 27 Apr 2022 17:19:48 -0400 Subject: [PATCH] fix(labels): Prevent duplicate labels POST call (#424) * fix(labels): Prevent duplicate labels POST call * Refresh labels only for same target --- src/app/Recordings/ActiveRecordingsTable.tsx | 18 +++++++++++++++--- src/app/Shared/Services/Api.service.tsx | 4 +++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/app/Recordings/ActiveRecordingsTable.tsx b/src/app/Recordings/ActiveRecordingsTable.tsx index c1cda45c7..584c68382 100644 --- a/src/app/Recordings/ActiveRecordingsTable.tsx +++ b/src/app/Recordings/ActiveRecordingsTable.tsx @@ -193,9 +193,21 @@ export const ActiveRecordingsTable: React.FunctionComponent { addSubscription( - context.notificationChannel.messages(NotificationCategory.RecordingMetadataUpdated) - .subscribe(v => setRecordings(old => old.map( - o => o.name == v.message.recordingName ? { ...o, metadata: { labels: v.message.metadata.labels } } : o))) + combineLatest([ + context.target.target(), + context.notificationChannel.messages(NotificationCategory.RecordingMetadataUpdated), + ]) + .subscribe(parts => { + const currentTarget = parts[0]; + const event = parts[1]; + if (currentTarget.connectUrl != event.message.target) { + return; + } + setRecordings(old => old.map( + o => o.name == event.message.recordingName + ? { ...o, metadata: { labels: event.message.metadata.labels } } + : o)); + }) ); }, [addSubscription, context, context.notificationChannel, setRecordings]); diff --git a/src/app/Shared/Services/Api.service.tsx b/src/app/Shared/Services/Api.service.tsx index 42298243a..e8a86494c 100644 --- a/src/app/Shared/Services/Api.service.tsx +++ b/src/app/Shared/Services/Api.service.tsx @@ -536,7 +536,9 @@ export class ApiService { } postTargetRecordingMetadata(recordingName: string, labels: RecordingLabel[]): Observable { - return this.target.target().pipe(concatMap(target => + return this.target.target().pipe( + first(), + concatMap(target => this.sendRequest( 'beta', `targets/${encodeURIComponent(target.connectUrl)}/recordings/${encodeURIComponent(recordingName)}/metadata/labels`, {