[ACS-8001] handle unsubscription

This commit is contained in:
Mykyta Maliarchuk
2024-07-30 09:36:57 +02:00
committed by Mykyta Maliarchuk
parent 80e9616bb0
commit 0e4519353e
@@ -204,11 +204,14 @@ export class ContentMetadataComponent implements OnChanges, OnInit, OnDestroy {
}); });
if (this.displayPredictions) { if (this.displayPredictions) {
this.predictionService.predictionStatusUpdated$.pipe(takeUntil(this.onDestroy$)).subscribe(({key, previousValue}) => { this.predictionService.predictionStatusUpdated$.pipe(takeUntil(this.onDestroy$)).subscribe(({ key, previousValue }) => {
this.cardViewContentUpdateService.onPredictionStatusChanged([{key, previousValue}]); this.cardViewContentUpdateService.onPredictionStatusChanged([{ key, previousValue }]);
this.nodesApiService.getNode(this.node.id).subscribe((node) => { this.nodesApiService
Object.assign(this.node, node); .getNode(this.node.id)
}); .pipe(takeUntil(this.onDestroy$))
.subscribe((node) => {
Object.assign(this.node, node);
});
}); });
} }
@@ -423,7 +426,9 @@ export class ContentMetadataComponent implements OnChanges, OnInit, OnDestroy {
.subscribe((result: any) => { .subscribe((result: any) => {
if (result) { if (result) {
if (this.displayPredictions) { if (this.displayPredictions) {
this.cardViewContentUpdateService.onPredictionStatusChanged(Object.keys(this.changedProperties['properties']).map(key => ({key}))); this.cardViewContentUpdateService.onPredictionStatusChanged(
Object.keys(this.changedProperties['properties']).map((key) => ({ key }))
);
} }
this.updateUndefinedNodeProperties(result.updatedNode); this.updateUndefinedNodeProperties(result.updatedNode);
if (this.hasContentTypeChanged(this.changedProperties)) { if (this.hasContentTypeChanged(this.changedProperties)) {
@@ -471,22 +476,34 @@ export class ContentMetadataComponent implements OnChanges, OnInit, OnDestroy {
requests['predictions'] = this.loadPredictionsForNode(this.node.id); requests['predictions'] = this.loadPredictionsForNode(this.node.id);
} }
forkJoin(requests).subscribe(({ predictions, properties, groupedProperties }: ({ predictions: Prediction[]; properties: CardViewItem[]; groupedProperties: CardViewGroup[] })) => { forkJoin(requests).subscribe(
if (loadBasicProps && properties) { ({
this.basicProperties$ = predictions predictions,
? of(properties.map(property => this.mapPredictionsToProperty(property, predictions))) properties,
: of(properties); groupedProperties
} }: {
predictions: Prediction[];
properties: CardViewItem[];
groupedProperties: CardViewGroup[];
}) => {
if (loadBasicProps && properties) {
this.basicProperties$ = predictions
? of(properties.map((property) => this.mapPredictionsToProperty(property, predictions)))
: of(properties);
}
if (loadGroupedProps && groupedProperties) { if (loadGroupedProps && groupedProperties) {
this.groupedProperties$ = predictions this.groupedProperties$ = predictions
? of(groupedProperties.map(group => { ? of(
group.properties = group.properties.map(property => this.mapPredictionsToProperty(property, predictions)); groupedProperties.map((group) => {
return group; group.properties = group.properties.map((property) => this.mapPredictionsToProperty(property, predictions));
})) return group;
: of(groupedProperties); })
)
: of(groupedProperties);
}
} }
}); );
if (this.displayTags && loadTags) { if (this.displayTags && loadTags) {
this.loadTagsForNode(node.id); this.loadTagsForNode(node.id);
@@ -585,15 +602,20 @@ export class ContentMetadataComponent implements OnChanges, OnInit, OnDestroy {
private mapPredictionsToProperty(property: CardViewItem, predictions: Prediction[]): CardViewItem { private mapPredictionsToProperty(property: CardViewItem, predictions: Prediction[]): CardViewItem {
const propertyKey = property.key.split('.')[1]; const propertyKey = property.key.split('.')[1];
const filteredPrediction = predictions.find(prediction => prediction.property === propertyKey && prediction.reviewStatus === ReviewStatus.UNREVIEWED && prediction.predictionValue === property.value); const filteredPrediction = predictions.find(
(prediction) =>
prediction.property === propertyKey &&
prediction.reviewStatus === ReviewStatus.UNREVIEWED &&
prediction.predictionValue === property.value
);
property.prediction = filteredPrediction || null; property.prediction = filteredPrediction || null;
return property; return property;
} }
private loadPredictionsForNode(nodeId: string): Observable<Prediction[]> { private loadPredictionsForNode(nodeId: string): Observable<Prediction[]> {
return this.predictionService.getPredictions(nodeId).pipe( return this.predictionService
map(predictionPaging => predictionPaging.list.entries.map(predictionEntry => predictionEntry.entry)) .getPredictions(nodeId)
); .pipe(map((predictionPaging) => predictionPaging.list.entries.map((predictionEntry) => predictionEntry.entry)));
} }
} }