From da320b5fbc52fdc2facc67a55cbd129ed423545e Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Wed, 1 May 2024 16:27:35 +0200 Subject: [PATCH] Prevent ItemSearchResult from being recreated at every iteration --- .../item/item-list-element.component.html | 2 +- .../item/item-list-element.component.spec.ts | 1 + .../item/item-list-element.component.ts | 20 +++++++++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.html b/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.html index 7f8dde1c4ec..8ab6fae9e61 100644 --- a/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.html +++ b/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.html @@ -1,5 +1,5 @@ diff --git a/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.spec.ts b/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.spec.ts index 789a8a8905e..e5b7d56f66d 100644 --- a/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.spec.ts +++ b/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.spec.ts @@ -110,6 +110,7 @@ describe('ItemListElementComponent', () => { describe(`when the publication is rendered`, () => { beforeEach(() => { comp.object = mockItem; + comp.ngOnChanges(); fixture.detectChanges(); }); diff --git a/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.ts b/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.ts index 1ca0a48c900..20f2a23b78e 100644 --- a/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.ts +++ b/src/app/shared/object-list/item-list-element/item-types/item/item-list-element.component.ts @@ -1,7 +1,11 @@ -import { Component } from '@angular/core'; +import { + Component, + OnChanges, +} from '@angular/core'; import { Item } from '../../../../../core/shared/item.model'; import { ViewMode } from '../../../../../core/shared/view-mode.model'; +import { hasValue } from '../../../../empty.util'; import { ItemSearchResult } from '../../../../object-collection/shared/item-search-result.model'; import { listableObjectComponent } from '../../../../object-collection/shared/listable-object/listable-object.decorator'; import { ListableObjectComponentLoaderComponent } from '../../../../object-collection/shared/listable-object/listable-object-component-loader.component'; @@ -21,12 +25,16 @@ import { AbstractListableElementComponent } from '../../../../object-collection/ /** * The component for displaying a list element for an item of the type Publication */ -export class ItemListElementComponent extends AbstractListableElementComponent { +export class ItemListElementComponent extends AbstractListableElementComponent implements OnChanges { - transformItemToItemSearchResult(object: Item): ItemSearchResult { - const itemSearchResult = new ItemSearchResult(); - itemSearchResult.indexableObject = object; - return itemSearchResult; + itemSearchResult: ItemSearchResult; + + ngOnChanges(): void { + if (hasValue(this.object)) { + this.itemSearchResult = Object.assign(new ItemSearchResult(), { + indexableObject: this.object, + }); + } } }