Skip to content

Commit

Permalink
angular: convert entity array to signal
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Dec 17, 2024
1 parent a72908f commit 901ae0c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<<%= jhiPrefixDashed %>-filter [filters]="filters"></<%= jhiPrefixDashed %>-filter>
<%_ } _%>

@if ((<%= entityInstancePlural %>?.length ?? 0) === 0) {
@if (<%= entityInstancePlural %>().length === 0) {
<div class="alert alert-warning" id="no-result">
<span>__jhiTranslateTag__('<%- i18nKeyPrefix %>.home.notFound')</span>
</div>
Expand Down Expand Up @@ -101,7 +101,7 @@
</tr>
</thead>
<tbody<% if (paginationInfiniteScroll) { %> 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 %>)) {
<tr data-cy="entityTable">
<%_
const routerLink = ` [routerLink]="['/${ entityPage }', ${entityInstance}.${primaryKey.name}, 'view']"`;
Expand Down Expand Up @@ -218,7 +218,7 @@ _%>
</div>
}
<%_ if (paginationPagination) { _%>
@if (<%= entityInstancePlural %> && <%= entityInstancePlural %>.length > 0) {
@if (<%= entityInstancePlural %>().length > 0) {
<div>
<div class="d-flex justify-content-center">
<<%= jhiPrefixDashed %>-item-count [params]="{ page: page, totalItems: totalItems, itemsPerPage: itemsPerPage }"></<%= jhiPrefixDashed %>-item-count>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
limitations under the License.
-%>
<%_
const entityArrayOptionalChainSymbol = '?.';
const order = 'desc';
const testEntityPrimaryKey = tsPrimaryKeySamples[0];
const testEntityPrimaryKey2 = tsPrimaryKeySamples[1];
Expand Down Expand Up @@ -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 %>', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class <%= componentName %> implements OnInit {

<%_ } _%>
subscription: Subscription | null = null;
<%= entityInstancePlural %>?: I<%= entityAngularName %>[];
<%= entityInstancePlural %> = signal<I<%= entityAngularName %>[]>([]);
isLoading = false;

sortState = sortStateSignal({});
Expand Down Expand Up @@ -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 %>()));
}
}),
<%_ } _%>
Expand All @@ -187,7 +189,7 @@ export class <%= componentName %> implements OnInit {

<%_ if (paginationInfiniteScroll) { _%>
reset(): void {
this.<%= entityInstancePlural %> = [];
this.<%= entityInstancePlural %>.set([]);
}

loadNextPage(): void {
Expand Down Expand Up @@ -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);
<%_ } _%>
}

Expand All @@ -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) { _%>
Expand Down

0 comments on commit 901ae0c

Please sign in to comment.