Skip to content

Commit 19078a1

Browse files
authored
Merge pull request #4279 from atmire/w2p-130484_bitstreams-tables-keep-being-duplicated-9.0
Fix bitstream tables being duplicated
2 parents 5719f06 + f9b58ec commit 19078a1

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/app/item-page/edit-item-page/item-bitstreams/item-bitstreams.component.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {
3030
map,
3131
switchMap,
3232
take,
33-
tap,
3433
} from 'rxjs/operators';
3534
import { AlertComponent } from 'src/app/shared/alert/alert.component';
3635
import { AlertType } from 'src/app/shared/alert/alert-type';
@@ -239,15 +238,28 @@ export class ItemBitstreamsComponent extends AbstractItemUpdateComponent impleme
239238
this.itemService.getBundles(this.item.id, new PaginatedSearchOptions({ pagination: this.bundlesOptions })).pipe(
240239
getFirstSucceededRemoteData(),
241240
getRemoteDataPayload(),
242-
tap((bundlesPL: PaginatedList<Bundle>) =>
243-
this.showLoadMoreLink$.next(bundlesPL.pageInfo.currentPage < bundlesPL.pageInfo.totalPages),
244-
),
245-
map((bundlePage: PaginatedList<Bundle>) => bundlePage.page),
246-
).subscribe((bundles: Bundle[]) => {
247-
this.bundlesSubject.next([...this.bundlesSubject.getValue(), ...bundles]);
241+
).subscribe((bundles: PaginatedList<Bundle>) => {
242+
this.updateBundles(bundles);
248243
});
249244
}
250245

246+
/**
247+
* Update the subject containing the bundles with the provided bundles.
248+
* Also updates the showLoadMoreLink observable so it does not show up when it is no longer necessary.
249+
*/
250+
updateBundles(newBundlesPL: PaginatedList<Bundle>) {
251+
const currentBundles = this.bundlesSubject.getValue();
252+
253+
// Only add bundles to the bundle subject if they are not present yet
254+
const bundlesToAdd = newBundlesPL.page
255+
.filter(bundleToAdd => !currentBundles.some(currentBundle => currentBundle.id === bundleToAdd.id));
256+
257+
const updatedBundles = [...currentBundles, ...bundlesToAdd];
258+
259+
this.showLoadMoreLink$.next(updatedBundles.length < newBundlesPL.totalElements);
260+
this.bundlesSubject.next(updatedBundles);
261+
}
262+
251263

252264
/**
253265
* Submit the current changes

0 commit comments

Comments
 (0)