Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Angular] Migrate Input to Signal Input #25691

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,53 +18,53 @@
-%>
<div class="d-flex justify-content-center">
<div class="col-8">
@if (user) {
@if (user()) {
<div>
<h2>
<span>__jhiTranslateTag__('userManagement.detail.title')</span> [<strong>{{ user.login }}</strong>]
<span>__jhiTranslateTag__('userManagement.detail.title')</span> [<strong>{{ user()!.login }}</strong>]
</h2>

<dl class="row-md jh-entity-details">
<dt><span>__jhiTranslateTag__('userManagement.login')</span></dt>
<dd>
<span>{{ user.login }}</span>
@if (user.activated) {
<span>{{ user()!.login }}</span>
@if (user()!.activated) {
<span class="badge bg-success">__jhiTranslateTag__('userManagement.activated')</span>
} @else {
<span class="badge bg-danger">__jhiTranslateTag__('userManagement.deactivated')</span>
}
</dd>

<dt><span>__jhiTranslateTag__('userManagement.firstName')</span></dt>
<dd>{{ user.firstName }}</dd>
<dd>{{ user()!.firstName }}</dd>

<dt><span>__jhiTranslateTag__('userManagement.lastName')</span></dt>
<dd>{{ user.lastName }}</dd>
<dd>{{ user()!.lastName }}</dd>

<dt><span>__jhiTranslateTag__('userManagement.email')</span></dt>
<dd>{{ user.email }}</dd>
<dd>{{ user()!.email }}</dd>
<%_ if (enableTranslation) { _%>

<dt><span>__jhiTranslateTag__('userManagement.langKey')</span></dt>
<dd>{{ user.langKey }}</dd>
<dd>{{ user()!.langKey }}</dd>
<%_ } _%>

<dt><span>__jhiTranslateTag__('userManagement.createdBy')</span></dt>
<dd>{{ user.createdBy }}</dd>
<dd>{{ user()!.createdBy }}</dd>

<dt><span>__jhiTranslateTag__('userManagement.createdDate')</span></dt>
<dd>{{ user.createdDate | date: 'dd/MM/yy HH:mm' }}</dd>
<dd>{{ user()!.createdDate | date: 'dd/MM/yy HH:mm' }}</dd>

<dt><span>__jhiTranslateTag__('userManagement.lastModifiedBy')</span></dt>
<dd>{{ user.lastModifiedBy }}</dd>
<dd>{{ user()!.lastModifiedBy }}</dd>

<dt><span>__jhiTranslateTag__('userManagement.lastModifiedDate')</span></dt>
<dd>{{ user.lastModifiedDate | date: 'dd/MM/yy HH:mm' }}</dd>
<dd>{{ user()!.lastModifiedDate | date: 'dd/MM/yy HH:mm' }}</dd>

<dt><span>__jhiTranslateTag__('userManagement.profiles')</span></dt>
<dd>
<ul class="list-unstyled">
@for (authority of user.authorities; track $index) {
@for (authority of user()!.authorities; track $index) {
<li>
<span class="badge bg-info">{{ authority }}</span>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('User Management Detail Component', () => {
const instance = await harness.navigateByUrl('/', UserManagementDetailComponent);

// THEN
expect(instance.user).toEqual(
expect(instance.user()).toEqual(
expect.objectContaining({
id: <%- tsKeyId %>,
login: 'user',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
import { Component, Input } from '@angular/core';
import { Component, input } from '@angular/core';
import { RouterModule } from '@angular/router';
import SharedModule from 'app/shared/shared.module';

Expand All @@ -29,5 +29,5 @@ import { User } from '../user-management.model';
imports: [RouterModule, SharedModule],
})
export default class UserManagementDetailComponent {
@Input() user: User | null = null;
user = input<User | null>(null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-%>
<div class="d-flex justify-content-center">
<div class="col-8">
@if (<%= entityInstance %>) {
@if (<%= entityInstance %>()) {
<div>
<h2 data-cy="<%= entityInstance %>DetailsHeading"><span>__jhiTranslateTag__('<%- i18nKeyPrefix %>.detail.title')</span></h2>

Expand All @@ -37,31 +37,31 @@ _%>
<dd>
<%_ if (field.fieldIsEnum) { _%>
<%# TODO: import enum and use its key as label _%>
<span>__jhiTranslateTagEnum__('<%= frontendAppName %>.<%= fieldType %>', { "value": "<%= entityInstance %>.<%= fieldName %> ?? 'null'" })</span>
<span>__jhiTranslateTagEnum__('<%= frontendAppName %>.<%= fieldType %>', { "value": "<%= entityInstance %>()!.<%= fieldName %> ?? 'null'" })</span>
<%_ } else if (field.fieldTypeBinary && field.blobContentTypeImage) { _%>
@if (<%= entityInstance %>.<%= fieldName %>) {
@if (<%= entityInstance %>()!.<%= fieldName %>) {
<div>
<a (click)="openFile(<%= entityInstance %>.<%= fieldName %>, <%= entityInstance %>.<%= fieldName %>ContentType)">
<img [src]="'data:' + <%= entityInstance %>.<%= fieldName %>ContentType + ';base64,' + <%= entityInstance %>.<%= fieldName %>" style="max-width: 100%;" alt="<%= entityInstance %>"/>
<a (click)="openFile(<%= entityInstance %>()!.<%= fieldName %> ?? '', <%= entityInstance %>()!.<%= fieldName %>ContentType)">
<img [src]="'data:' + <%= entityInstance %>()!.<%= fieldName %>ContentType + ';base64,' + <%= entityInstance %>()!.<%= fieldName %>" style="max-width: 100%;" alt="<%= entityInstance %>"/>
</a>
{{ <%= entityInstance %>.<%= fieldName %>ContentType }}, {{ byteSize(<%= entityInstance %>.<%= fieldName %>) }}
{{ <%= entityInstance %>()!.<%= fieldName %>ContentType }}, {{ byteSize(<%= entityInstance %>()!.<%= fieldName %> ?? '') }}
</div>
}
<%_ } else if (field.fieldTypeBinary && field.blobContentTypeAny) { _%>
@if (<%= entityInstance %>.<%= fieldName %>) {
@if (<%= entityInstance %>()!.<%= fieldName %>) {
<div>
<a (click)="openFile(<%= entityInstance %>.<%= fieldName %>, <%= entityInstance %>.<%= fieldName %>ContentType)">__jhiTranslateTag__('entity.action.open')</a>
{{ <%= entityInstance %>.<%= fieldName %>ContentType }}, {{ byteSize(<%= entityInstance %>.<%= fieldName %>) }}
<a (click)="openFile(<%= entityInstance %>()!.<%= fieldName %> ?? '', <%= entityInstance %>()!.<%= fieldName %>ContentType)">__jhiTranslateTag__('entity.action.open')</a>
{{ <%= entityInstance %>()!.<%= fieldName %>ContentType }}, {{ byteSize(<%= entityInstance %>()!.<%= fieldName %> ?? '') }}
</div>
}
<%_ } else if (field.fieldTypeDuration) { _%>
<span>{{ <%= entityInstance %>.<%= fieldName %> | duration }} ({{<%= entityInstance %>.<%= fieldName %> }})</span>
<span>{{ <%= entityInstance %>()!.<%= fieldName %> | duration }} ({{<%= entityInstance %>()!.<%= fieldName %> }})</span>
<%_ } else if (field.fieldTypeTimed) { _%>
<span>{{ <%= entityInstance %>.<%= fieldName %> | formatMediumDatetime }}</span>
<span>{{ <%= entityInstance %>()!.<%= fieldName %> | formatMediumDatetime }}</span>
<%_ } else if (field.fieldTypeLocalDate) { _%>
<span>{{ <%= entityInstance %>.<%= fieldName %> | formatMediumDate }}</span>
<span>{{ <%= entityInstance %>()!.<%= fieldName %> | formatMediumDate }}</span>
<%_ } else { _%>
<span>{{ <%= entityInstance %>.<%= fieldName %> }}</span>
<span>{{ <%= entityInstance %>()!.<%= fieldName %> }}</span>
<%_ } _%>
</dd>
<%_ } _%>
Expand All @@ -79,25 +79,25 @@ _%>
<dd>
<%_ if (relationship.otherEntityUser) { _%>
<%_ if (relationship.collection) { _%>
@for (<%= relationshipFieldName %> of <%= entityInstance %>.<%= relationshipFieldNamePlural %>; track $index; let last = $last) {
@for (<%= relationshipFieldName %> of <%= entityInstance %>()!.<%= relationshipFieldNamePlural %>; track $index; let last = $last) {
<span>
{{ <%= relationshipFieldName %>.<%= otherEntityField %> }}{{ last ? '' : ', ' }}
</span>
}
<%_ } else { _%>
<span>{{ <%= entityInstance %>.<%= relationshipFieldName %>?.<%= otherEntityField %> }}</span>
<span>{{ <%= entityInstance %>()!.<%= relationshipFieldName %>?.<%= otherEntityField %> }}</span>
<%_ } _%>
<%_ } else { _%>
<%_ if (relationship.collection) { _%>
@for (<%= relationshipFieldName %> of <%= entityInstance %>.<%= relationshipFieldNamePlural %>; track $index; let last = $last) {
@for (<%= relationshipFieldName %> of <%= entityInstance %>()!.<%= relationshipFieldNamePlural %>; track $index; let last = $last) {
<span>
<a [routerLink]="['/<%= relationship.otherEntity.entityPage %>', <%= relationshipFieldName %>.<%= relationship.otherEntity.primaryKey.name %>, 'view']">{{ <%= relationshipFieldName %>.<%= otherEntityField %> }}</a>{{ last ? '' : ', ' }}
<a [routerLink]="['/<%= relationship.otherEntity.entityPage %>', <%= relationshipFieldName %>.<%= relationship.otherEntity.primaryKey.name %>, 'view']">{{ <%= relationshipFieldName %>?.<%= otherEntityField %> }}</a>{{ last ? '' : ', ' }}
</span>
}
<%_ } else { _%>
@if (<%= entityInstance + '.' + relationshipFieldName %>) {
@if (<%= entityInstance + '()!.' + relationshipFieldName %>) {
<div>
<a [routerLink]="['/<%= relationship.otherEntity.entityPage %>', <%= entityInstance + '.' + relationshipFieldName + '.' + relationship.otherEntity.primaryKey.name %>, 'view']">{{ <%= entityInstance %>.<%= relationshipFieldName %>.<%= otherEntityField %> }}</a>
<a [routerLink]="['/<%= relationship.otherEntity.entityPage %>', <%= entityInstance + '()!.' + relationshipFieldName + '?.' + relationship.otherEntity.primaryKey.name %>, 'view']">{{ <%= entityInstance %>()!.<%= relationshipFieldName %>?.<%= otherEntityField %> }}</a>
</div>
}
<%_ } _%>
Expand All @@ -118,7 +118,7 @@ _%>
<%_ if (!readOnly && updatableEntity) { _%>

<button type="button"
[routerLink]="['/<%= entityPage %>', <%= entityInstance %>.<%= primaryKey.name %>, 'edit']"
[routerLink]="['/<%= entityPage %>', <%= entityInstance %>()!.<%= primaryKey.name %>, 'edit']"
class="btn btn-primary">
<fa-icon icon="pencil-alt"></fa-icon>&nbsp;<span>__jhiTranslateTag__('entity.action.edit')</span>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('<%= entityAngularName %> Management Detail Component', () => {
const instance = await harness.navigateByUrl('/', <%= entityAngularName %>DetailComponent);

// THEN
expect(instance.<%= entityInstance %>).toEqual(expect.objectContaining(<%- testEntity %>));
expect(instance.<%= entityInstance %>()).toEqual(expect.objectContaining(<%- testEntity %>));
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
import { Component, <% if (anyFieldIsBlobDerived) { %>inject, <% } %>Input } from '@angular/core';
import { Component, <% if (anyFieldIsBlobDerived) { %>inject, <% } %>input } from '@angular/core';
import { RouterModule } from '@angular/router';

import SharedModule from 'app/shared/shared.module';
Expand All @@ -33,7 +33,7 @@ import { DataUtils } from 'app/core/util/data-util.service';
imports: [SharedModule, RouterModule, DurationPipe, FormatMediumDatetimePipe, FormatMediumDatePipe],
})
export class <%= entityAngularName %>DetailComponent {
@Input() <%= entityInstance %>: I<%= entityAngularName %> | null = null;
<%= entityInstance %> = input<I<%= entityAngularName %> | null>(null);

<%_ if (anyFieldIsBlobDerived) { _%>
protected dataUtils = inject(DataUtils);
Expand Down