Skip to content

Commit

Permalink
chore(block-editor): Use the new angular syntax (#29449)
Browse files Browse the repository at this point in the history
### Parent Issue

#29448

### Proposed Changes
- Use the new Angular syntax to improve performance and code
maintainability.

### Checklist
- [x] Tests
- [x] Translations
- [x] Security Implications Contemplated (add notes if applicable)
  • Loading branch information
nicobytes authored Aug 6, 2024
1 parent e4a3722 commit 2dfeb40
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
formControlName="generatedText"
pInputTextarea></textarea>

<dot-copy-button
*ngIf="generatedText.value"
[copy]="generatedText.value"
customClass="p-button-rounded" />
@if (generatedText.value) {
<dot-copy-button
[copy]="generatedText.value"
customClass="p-button-rounded" />
}
</div>
}
@if (vm.status === ComponentStatus.LOADING) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Observable } from 'rxjs';

import { AsyncPipe, NgIf } from '@angular/common';
import { AsyncPipe } from '@angular/common';
import { Component, DestroyRef, ElementRef, inject, OnInit, ViewChild } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
Expand Down Expand Up @@ -44,7 +44,6 @@ interface AIContentForm {
ButtonModule,
TooltipModule,
SkeletonModule,
NgIf,
AsyncPipe,
DotEmptyContainerComponent,
ConfirmDialogModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<ng-container [ngSwitch]="type">
<ng-container *ngSwitchCase="'image'">
@switch (type) {
@case ('image') {
<img [src]="src || file.objectURL" [alt]="file.name" />
</ng-container>
<ng-container *ngSwitchCase="'video'">
}
@case ('video') {
<video controls preload="metadata">
<source [src]="src || file.objectURL" />
</video>
</ng-container>
<p *ngSwitchDefault>Select an accepted asset type</p>
</ng-container>
}
@default {
<p>Select an accepted asset type</p>
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
<ng-container [ngSwitch]="type">
<div *ngSwitchCase="'video'" class="placeholder-container">
<div class="preview-container__video">
<video class="video" src="" controls></video>
</div>

<div class="preview-container__loading">
<div>
<dot-spinner size="30px"></dot-spinner>
Uploading video, wait until finished.
@switch (type) {
@case ('video') {
<div class="placeholder-container">
<div class="preview-container__video">
<video class="video" src="" controls></video>
</div>
<div class="preview-container__loading">
<div>
<dot-spinner size="30px"></dot-spinner>
Uploading video, wait until finished.
</div>
<button
(click)="cancel.emit(true)"
class="p-button-md p-button-outlined"
pButton
label="Cancel"></button>
</div>
<button
(click)="cancel.emit(true)"
class="p-button-md p-button-outlined"
pButton
label="Cancel"></button>
</div>
</div>
<span *ngSwitchDefault class="default-message">Uploading...</span>
</ng-container>
}
@default {
<span class="default-message">Uploading...</span>
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CommonModule } from '@angular/common';
import { ChangeDetectionStrategy, Component, EventEmitter, Output, Input } from '@angular/core';

import { ButtonModule } from 'primeng/button';
Expand All @@ -11,7 +10,7 @@ import { DotSpinnerModule } from '@dotcms/ui';
styleUrls: ['./upload-placeholder.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [CommonModule, ButtonModule, DotSpinnerModule]
imports: [ButtonModule, DotSpinnerModule]
})
export class UploadPlaceholderComponent {
@Output() cancel = new EventEmitter<boolean>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,57 @@
<form *ngIf="form" (ngSubmit)="onSubmit()" [ngClass]="options?.customClass" [formGroup]="form">
<div *ngFor="let control of dynamicControls" [ngClass]="control.type" class="field form-row">
<ng-container [ngSwitch]="control.type">
<ng-container *ngSwitchCase="'checkbox'">
<p-checkbox
[formControlName]="control.key"
[binary]="true"
[id]="control.key"></p-checkbox>
<label [checkIsRequiredControl]="control.key" [for]="control.key" dotFieldRequired>
{{ control.label | titlecase }}
</label>
</ng-container>
<ng-container *ngSwitchDefault>
<label
[ngClass]="{ 'p-label-input-required': control.required }"
[for]="control.key">
{{ control.label | titlecase }}
</label>
<input
*ngSwitchDefault
[formControlName]="control.key"
[id]="control.key"
[type]="control.type"
[min]="control.min"
[style]="{ width: '100%', fontSize: '14px', height: '40px' }"
#group
pInputText
type="control.type" />
</ng-container>
</ng-container>
<span
*ngIf="form.controls[control.key].invalid && form.controls[control.key].dirty"
class="error-message">
This field is required
</span>
</div>

<div class="form-action">
<button
(click)="hide.emit(true)"
[style]="{ width: '120px' }"
class="p-button-outlined"
pButton
type="button"
label="CANCEL"></button>
<button
[disabled]="form.invalid"
[style]="{ padding: '11.5px 24px' }"
class="p-button"
pButton
type="submit"
label="APPLY"></button>
</div>
</form>
@if (form) {
<form (ngSubmit)="onSubmit()" [ngClass]="options?.customClass" [formGroup]="form">
@for (control of dynamicControls; track control) {
<div [ngClass]="control.type" class="field form-row">
@switch (control.type) {
@case ('checkbox') {
<p-checkbox
[formControlName]="control.key"
[binary]="true"
[id]="control.key"></p-checkbox>
<label
[checkIsRequiredControl]="control.key"
[for]="control.key"
dotFieldRequired>
{{ control.label | titlecase }}
</label>
}
@default {
<label
[ngClass]="{ 'p-label-input-required': control.required }"
[for]="control.key">
{{ control.label | titlecase }}
</label>
<input
[formControlName]="control.key"
[id]="control.key"
[type]="control.type"
[min]="control.min"
[style]="{ width: '100%', fontSize: '14px', height: '40px' }"
#group
pInputText
type="control.type" />
}
}
@if (form.controls[control.key].invalid && form.controls[control.key].dirty) {
<span class="error-message">This field is required</span>
}
</div>
}
<div class="form-action">
<button
(click)="hide.emit(true)"
[style]="{ width: '120px' }"
class="p-button-outlined"
pButton
type="button"
label="CANCEL"></button>
<button
[disabled]="form.invalid"
[style]="{ padding: '11.5px 24px' }"
class="p-button"
pButton
type="submit"
label="APPLY"></button>
</div>
</form>
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,44 @@
</div>
</div>

<hr *ngIf="showSuggestions || currentLink" class="divider" />
@if (showSuggestions || currentLink) {
<hr class="divider" />
}

<div *ngIf="currentLink && !showSuggestions" class="info-container">
<a [href]="currentLink" class="url-container" target="_blank">
<span [style]="{ fontSize: '32px' }" class="material-icons">language</span>
<span class="truncate">{{ currentLink }}</span>
</a>

<div class="field-checkbox">
<div class="checkbox-container">
<p-checkbox
[binary]="true"
id="editor-input-checkbox"
formControlName="blank"></p-checkbox>
@if (currentLink && !showSuggestions) {
<div class="info-container">
<a [href]="currentLink" class="url-container" target="_blank">
<span [style]="{ fontSize: '32px' }" class="material-icons">language</span>
<span class="truncate">{{ currentLink }}</span>
</a>
<div class="field-checkbox">
<div class="checkbox-container">
<p-checkbox
[binary]="true"
id="editor-input-checkbox"
formControlName="blank"></p-checkbox>
</div>
<label for="editor-input-checkbox">Open link in new window</label>
</div>
<label for="editor-input-checkbox">Open link in new window</label>
</div>
</div>
}
</form>

<!-- Suggestions -->
<dot-suggestion-page
*ngIf="showSuggestions"
(back)="resetForm()"
[items]="items"
[loading]="loading"
[title]="noResultsTitle"
#suggestions></dot-suggestion-page>
@if (showSuggestions) {
<dot-suggestion-page
(back)="resetForm()"
[items]="items"
[loading]="loading"
[title]="noResultsTitle"
#suggestions></dot-suggestion-page>
}

<!-- Form Actions -->
<dot-form-actions
*ngIf="!showSuggestions && currentLink"
(hide)="hide.emit($event)"
(remove)="removeLink.emit($event)"
[link]="currentLink"></dot-form-actions>
@if (!showSuggestions && currentLink) {
<dot-form-actions
(hide)="hide.emit($event)"
(remove)="removeLink.emit($event)"
[link]="currentLink"></dot-form-actions>
}
</div>
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<div *ngIf="link.length">
<div class="form-actions">
<button
(click)="copy()"
[style]="{ width: '50%' }"
pButton
type="button"
label="COPY LINK"
class="p-button-outlined"></button>
<button
(click)="remove.emit(true)"
[style]="{ width: '50%' }"
pButton
type="button"
label="REMOVE LINK"
class="p-button-outlined p-button-danger"></button>
@if (link.length) {
<div>
<div class="form-actions">
<button
(click)="copy()"
[style]="{ width: '50%' }"
pButton
type="button"
label="COPY LINK"
class="p-button-outlined"></button>
<button
(click)="remove.emit(true)"
[style]="{ width: '50%' }"
pButton
type="button"
label="REMOVE LINK"
class="p-button-outlined p-button-danger"></button>
</div>
</div>
</div>
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
<div *ngIf="items.length; else loading ? loadingBlock : emptyBlock">
<dot-suggestion-list #list>
<dot-suggestions-list-item
*ngFor="let item of items; let i = index"
[command]="item.command"
[index]="i"
[label]="item.label"
[url]="item.icon"
[data]="item.data"
[page]="true"></dot-suggestions-list-item>
</dot-suggestion-list>
</div>

<ng-template #loadingBlock>
<dot-suggestion-loading-list></dot-suggestion-loading-list>
</ng-template>

<ng-template #emptyBlock>
<dot-empty-message
(back)="handleBackButton()"
[title]="title"
[showBackBtn]="true"></dot-empty-message>
</ng-template>
@if (items.length) {
<div>
<dot-suggestion-list #list>
@for (item of items; track item; let i = $index) {
<dot-suggestions-list-item
[command]="item.command"
[index]="i"
[label]="item.label"
[url]="item.icon"
[data]="item.data"
[page]="true"></dot-suggestions-list-item>
}
</dot-suggestion-list>
</div>
} @else {
@if (loading) {
<dot-suggestion-loading-list />
} @else {
<dot-empty-message (back)="handleBackButton()" [title]="title" [showBackBtn]="true" />
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<div (mousedown)="preventDeSelection($event)" class="bubble-menu" id="bubble-menu">
<ng-container *ngIf="selected">
@if (selected) {
<button (click)="toggleChangeTo.emit()" class="btn-dropdown">{{ selected }}</button>
<div class="divider"></div>
</ng-container>
<ng-container *ngFor="let item of items; let i = index">
}
@for (item of items; track item; let i = $index) {
<dot-bubble-menu-button
(click)="command.emit(item)"
[active]="item.active"
[item]="item"></dot-bubble-menu-button>
<div *ngIf="item.divider" class="divider"></div>
</ng-container>
@if (item.divider) {
<div class="divider"></div>
}
}
</div>
Loading

0 comments on commit 2dfeb40

Please sign in to comment.