Fix: allow removing dead document links from UI, validate via API (#8081)

This commit is contained in:
shamoon
2024-10-28 10:39:17 -07:00
committed by GitHub
parent d4a20c7e30
commit 35907313e8
5 changed files with 70 additions and 9 deletions

View File

@@ -41,9 +41,15 @@
<ng-template ng-label-tmp let-document="item">
<div class="d-flex align-items-center">
<button class="btn p-0 lh-1" *ngIf="!disabled" (click)="unselect(document)" title="Remove link" i18n-title><i-bs name="x"></i-bs></button>
<a routerLink="/documents/{{document.id}}" class="badge bg-light text-primary" (mousedown)="$event.stopImmediatePropagation();" title="Open link" i18n-title>
<i-bs width="0.9em" height="0.9em" name="file-text"></i-bs>&nbsp;<span>{{document.title}}</span>
</a>
@if (document.title) {
<a routerLink="/documents/{{document.id}}" class="badge bg-light text-primary" (mousedown)="$event.stopImmediatePropagation();" title="Open link" i18n-title>
<i-bs width="0.9em" height="0.9em" name="file-text"></i-bs>&nbsp;<span>{{document.title}}</span>
</a>
} @else {
<span class="badge bg-light text-muted" (click)="unselect(document)" title="Remove link" i18n-title>
<i-bs width="0.9em" height="0.9em" name="exclamation-triangle-fill"></i-bs>&nbsp;<span i18n>Not found</span>
</span>
}
</div>
</ng-template>
<ng-template ng-loadingspinner-tmp>

View File

@@ -71,9 +71,9 @@ export class DocumentLinkComponent
.pipe(takeUntil(this.unsubscribeNotifier))
.subscribe((documentResults) => {
this.loading = false
this.selectedDocuments = documentIDs
.map((id) => documentResults.results.find((d) => d.id === id))
.filter((d) => d)
this.selectedDocuments = documentIDs.map((id) =>
documentResults.results.find((d) => d.id === id)
)
super.writeValue(documentIDs)
})
}
@@ -114,7 +114,7 @@ export class DocumentLinkComponent
unselect(document: Document): void {
this.selectedDocuments = this.selectedDocuments.filter(
(d) => d.id !== document.id
(d) => d && d.id !== document.id
)
this.onChange(this.selectedDocuments.map((d) => d.id))
}