Skip to content

Commit 4ef0b91

Browse files
authored
angular: convert isLoading/isSaving to signals (#31718)
1 parent 67b1f0b commit 4ef0b91

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.html.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
<span>__jhiTranslateTag__('<%- i18nKeyPrefix %>.home.title')</span>
2222

2323
<div class="d-flex justify-content-end">
24-
<button class="btn btn-info me-2" (click)="load()" [disabled]="isLoading">
25-
<fa-icon icon="sync" [animation]="isLoading ? 'spin' : undefined" />
24+
<button class="btn btn-info me-2" (click)="load()" [disabled]="isLoading()">
25+
<fa-icon icon="sync" [animation]="isLoading() ? 'spin' : undefined" />
2626
<span>__jhiTranslateTag__('<%- i18nKeyPrefix %>.home.refreshListLabel')</span>
2727
</button>
2828
<%_ if (!readOnly) { _%>

generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.ts.ejs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { Component, computed, effect, inject, OnInit, signal, WritableSignal } f
3434
import { HttpHeaders } from '@angular/common/http';
3535
<%_ } _%>
3636
import { ActivatedRoute, Data, ParamMap, Router, RouterLink } from '@angular/router';
37-
import { combineLatest<%_ if (!readOnly) { _%>, filter<%_ } _%>, Observable, Subscription, tap } from 'rxjs';
37+
import { combineLatest<%_ if (!readOnly) { _%>, filter<%_ } _%>, finalize, Observable, Subscription, tap } from 'rxjs';
3838
<%_ if (!readOnly) { _%>
3939
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
4040
<%_ } _%>
@@ -137,7 +137,7 @@ export class <%= componentName %> implements OnInit {
137137
<%_ } _%>
138138
subscription: Subscription | null = null;
139139
<%= entityInstancePlural %> = signal<I<%= entityAngularName %>[]>([]);
140-
isLoading = false;
140+
isLoading = signal(false);
141141

142142
sortState = sortStateSignal({});
143143
<%_ if (searchEngineAny) { _%>
@@ -365,7 +365,7 @@ export class <%= componentName %> implements OnInit {
365365
} = this;
366366
<%_ } _%>
367367
368-
this.isLoading = true;
368+
this.isLoading.set(true);
369369
<%_ if (paginationPagination) { _%>
370370
const pageToLoad: number = page;
371371
<%_ } _%>
@@ -403,13 +403,13 @@ export class <%= componentName %> implements OnInit {
403403
if (this.currentSearch && this.currentSearch !== '') {
404404
return this.<%= entityInstance %>Service.search(queryObject)
405405
.pipe(
406-
tap(() => this.isLoading = false)
406+
finalize(() => this.isLoading.set(false))
407407
);
408408
} else {
409409
<%_ } _%>
410410
return this.<%= entityInstance %>Service.query(queryObject)
411411
.pipe(
412-
tap(() => this.isLoading = false)
412+
finalize(() => this.isLoading.set(false))
413413
);
414414
<%_ if (searchEngineAny) { _%>
415415
}

generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/update/_entityFile_-update.html.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ _%>
216216
<fa-icon icon="ban" />&nbsp;<span>__jhiTranslateTag__('entity.action.cancel')</span>
217217
</button>
218218
219-
<button type="submit" id="save-entity" data-cy="entityCreateSaveButton" [disabled]="editForm.invalid || isSaving" class="btn btn-primary">
219+
<button type="submit" id="save-entity" data-cy="entityCreateSaveButton" [disabled]="editForm.invalid || isSaving()" class="btn btn-primary">
220220
<fa-icon icon="save" />&nbsp;<span>__jhiTranslateTag__('entity.action.save')</span>
221221
</button>
222222
</div>

generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/update/_entityFile_-update.spec.ts.ejs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,15 @@ describe('<%= entityAngularName %> Management Update Component', () => {
185185
186186
// WHEN
187187
comp.save();
188-
expect(comp.isSaving).toEqual(true);
188+
expect(comp.isSaving()).toEqual(true);
189189
saveSubject.next(new HttpResponse({ body: <%= entityInstance %> }));
190190
saveSubject.complete();
191191
192192
// THEN
193193
expect(<%= entityInstance %>FormService.get<%= entityAngularName %>).toHaveBeenCalled();
194194
expect(comp.previousState).toHaveBeenCalled();
195195
expect(<%= entityInstance %>Service.update).toHaveBeenCalledWith(expect.objectContaining(<%= entityInstance %>));
196-
expect(comp.isSaving).toEqual(false);
196+
expect(comp.isSaving()).toEqual(false);
197197
});
198198
199199
<%_ } _%>
@@ -209,14 +209,14 @@ describe('<%= entityAngularName %> Management Update Component', () => {
209209

210210
// WHEN
211211
comp.save();
212-
expect(comp.isSaving).toEqual(true);
212+
expect(comp.isSaving()).toEqual(true);
213213
saveSubject.next(new HttpResponse({ body: <%= entityInstance %> }));
214214
saveSubject.complete();
215215

216216
// THEN
217217
expect(<%= entityInstance %>FormService.get<%= entityAngularName %>).toHaveBeenCalled();
218218
expect(<%= entityInstance %>Service.create).toHaveBeenCalled();
219-
expect(comp.isSaving).toEqual(false);
219+
expect(comp.isSaving()).toEqual(false);
220220
expect(comp.previousState).toHaveBeenCalled();
221221
});
222222
<%_ if (updatableEntity) { _%>
@@ -232,12 +232,12 @@ describe('<%= entityAngularName %> Management Update Component', () => {
232232
233233
// WHEN
234234
comp.save();
235-
expect(comp.isSaving).toEqual(true);
235+
expect(comp.isSaving()).toEqual(true);
236236
saveSubject.error('This is an error!');
237237
238238
// THEN
239239
expect(<%= entityInstance %>Service.update).toHaveBeenCalled();
240-
expect(comp.isSaving).toEqual(false);
240+
expect(comp.isSaving()).toEqual(false);
241241
expect(comp.previousState).not.toHaveBeenCalled();
242242
});
243243
<%_ } _%>

generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/update/_entityFile_-update.ts.ejs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import { <%- importedType %> } from '<%- importedPath %>';
6767
TranslateDirective, TranslateModule,<%_ } _%>NgbModule, FontAwesomeModule, AlertError, ReactiveFormsModule],
6868
})
6969
export class <%= entityAngularName %>Update implements OnInit {
70-
isSaving = false;
70+
isSaving = signal(false);
7171
<%= entityInstance %>: I<%= entityAngularName %> | null = null;
7272
<%_ enumImports.forEach( (importedPath, importedType) => { _%>
7373
<%- this._.lowerFirst(importedType) %>Values = Object.keys(<%- importedType %>);
@@ -164,7 +164,7 @@ _%>
164164
}
165165

166166
save(): void {
167-
this.isSaving = true;
167+
this.isSaving.set(true);
168168
const <%= entityInstance %> = this.<%= entityInstance %>FormService.get<%= entityAngularName %>(this.editForm);
169169
<%_ if (updatableEntity) { _%>
170170
if (<%= entityInstance %>.<%= primaryKey.name %> === null) {
@@ -193,7 +193,7 @@ _%>
193193
}
194194

195195
protected onSaveFinalize(): void {
196-
this.isSaving = false;
196+
this.isSaving.set(false);
197197
}
198198

199199
protected updateForm(<%= entityInstance %>: I<%= entityAngularName %>): void {

0 commit comments

Comments
 (0)