From 1d8024c90c585dcfa54a48dc0d830928c43531f8 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Tue, 17 Dec 2024 05:38:52 -0300 Subject: [PATCH] angular: convert entity array to signal (#28220) --- .../list/_entityFile_.component.html.ejs | 6 +++--- .../list/_entityFile_.component.spec.ts.ejs | 3 +-- .../list/_entityFile_.component.ts.ejs | 14 ++++++++------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.component.html.ejs b/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.component.html.ejs index 18319f8e954e..6116e28cd709 100644 --- a/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.component.html.ejs +++ b/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.component.html.ejs @@ -64,7 +64,7 @@ <<%= jhiPrefixDashed %>-filter [filters]="filters">-filter> <%_ } _%> -@if ((<%= entityInstancePlural %>?.length ?? 0) === 0) { +@if (<%= entityInstancePlural %>().length === 0) {
__jhiTranslateTag__('<%- i18nKeyPrefix %>.home.notFound')
@@ -101,7 +101,7 @@ infinite-scroll (scrolled)="loadNextPage()" [infiniteScrollDisabled]="!hasMorePage()" [infiniteScrollDistance]="0"<% } %>> - @for (<%= entityInstance %> of <%= entityInstancePlural %>; track track<%= primaryKey.nameCapitalized %>(<%= entityInstance %>)) { + @for (<%= entityInstance %> of <%= entityInstancePlural %>(); track track<%= primaryKey.nameCapitalized %>(<%= entityInstance %>)) { <%_ const routerLink = ` [routerLink]="['/${ entityPage }', ${entityInstance}.${primaryKey.name}, 'view']"`; @@ -218,7 +218,7 @@ _%> } <%_ if (paginationPagination) { _%> -@if (<%= entityInstancePlural %> && <%= entityInstancePlural %>.length > 0) { +@if (<%= entityInstancePlural %>().length > 0) {
<<%= jhiPrefixDashed %>-item-count [params]="{ page: page, totalItems: totalItems, itemsPerPage: itemsPerPage }">-item-count> diff --git a/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.component.spec.ts.ejs b/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.component.spec.ts.ejs index 993881549954..b160e71afe35 100644 --- a/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.component.spec.ts.ejs +++ b/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.component.spec.ts.ejs @@ -17,7 +17,6 @@ limitations under the License. -%> <%_ -const entityArrayOptionalChainSymbol = '?.'; const order = 'desc'; const testEntityPrimaryKey = tsPrimaryKeySamples[0]; const testEntityPrimaryKey2 = tsPrimaryKeySamples[1]; @@ -131,7 +130,7 @@ describe('<%= entityAngularName %> Management Component', () => { // THEN expect(service.query).toHaveBeenCalled(); - expect(comp.<%= entityInstancePlural %><%= entityArrayOptionalChainSymbol %>[0]).toEqual(expect.objectContaining(<%- testEntityPrimaryKey %>)); + expect(comp.<%= entityInstancePlural %>()[0]).toEqual(expect.objectContaining(<%- testEntityPrimaryKey %>)); }); describe('track<%= primaryKey.nameCapitalized %>', () => { diff --git a/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.component.ts.ejs b/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.component.ts.ejs index c0fe58bb4cc7..beec8070f10e 100644 --- a/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.component.ts.ejs +++ b/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.component.ts.ejs @@ -122,7 +122,7 @@ export class <%= componentName %> implements OnInit { <%_ } _%> subscription: Subscription | null = null; - <%= entityInstancePlural %>?: I<%= entityAngularName %>[]; + <%= entityInstancePlural %> = signal[]>([]); isLoading = false; sortState = sortStateSignal({}); @@ -173,8 +173,10 @@ export class <%= componentName %> implements OnInit { tap(() => this.load()), <%_ } else { _%> tap(() => { - if (!this.<%= entityInstancePlural %> || this.<%= entityInstancePlural %>.length === 0) { + if (this.<%= entityInstancePlural %>().length === 0) { this.load(); + } else { + this.<%= entityInstancePlural %>.set(this.refineData(this.<%= entityInstancePlural %>())); } }), <%_ } _%> @@ -187,7 +189,7 @@ export class <%= componentName %> implements OnInit { <%_ if (paginationInfiniteScroll) { _%> reset(): void { - this.<%= entityInstancePlural %> = []; + this.<%= entityInstancePlural %>.set([]); } loadNextPage(): void { @@ -289,9 +291,9 @@ export class <%= componentName %> implements OnInit { <%_ } _%> const dataFromBody = this.fillComponentAttributesFromResponseBody(response.body); <%_ if (paginationNo) { _%> - this.<%= entityInstancePlural %> = this.refineData(dataFromBody); + this.<%= entityInstancePlural %>.set(this.refineData(dataFromBody)); <%_ } else { _%> - this.<%= entityInstancePlural %> = dataFromBody; + this.<%= entityInstancePlural %>.set(dataFromBody); <%_ } _%> } @@ -306,7 +308,7 @@ export class <%= componentName %> implements OnInit { <%_ if (paginationInfiniteScroll) { _%> // If there is previous link, data is a infinite scroll pagination content. if (this.links().prev) { - const <%= entityInstancePlural %>New = this.<%= entityInstancePlural %> ?? []; + const <%= entityInstancePlural %>New = this.<%= entityInstancePlural %>(); if (data) { for (const d of data) { <%_ if (primaryKey) { _%>