You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2026/03/26 12:57:41 UTC
(streampipes) branch 4303-migrate-splabelconfigurationcomponent-to-angular-signals updated: refactor: migrate label configuration to signals
This is an automated email from the ASF dual-hosted git repository.
zehnder pushed a commit to branch 4303-migrate-splabelconfigurationcomponent-to-angular-signals
in repository https://gitbox.apache.org/repos/asf/streampipes.git
The following commit(s) were added to refs/heads/4303-migrate-splabelconfigurationcomponent-to-angular-signals by this push:
new 0f927b82e4 refactor: migrate label configuration to signals
0f927b82e4 is described below
commit 0f927b82e4a1e64ee1a876f74412edee60256b5d
Author: Philipp Zehnder <te...@users.noreply.github.com>
AuthorDate: Thu Mar 26 13:57:10 2026 +0100
refactor: migrate label configuration to signals
---
.../edit-label/edit-label.component.html | 19 +++---
.../edit-label/edit-label.component.ts | 79 ++++++++++++++--------
.../label-configuration.component.html | 10 +--
.../label-configuration.component.ts | 23 +++++--
4 files changed, 84 insertions(+), 47 deletions(-)
diff --git a/ui/src/app/configuration/label-configuration/edit-label/edit-label.component.html b/ui/src/app/configuration/label-configuration/edit-label/edit-label.component.html
index b5ece854f3..124f23f58f 100644
--- a/ui/src/app/configuration/label-configuration/edit-label/edit-label.component.html
+++ b/ui/src/app/configuration/label-configuration/edit-label/edit-label.component.html
@@ -19,7 +19,7 @@
<div
fxLayout="column"
class="form-field-small mt-10"
- [ngClass]="editMode ? '' : 'create-label'"
+ [ngClass]="editMode() ? '' : 'create-label'"
>
<div
fxLayout="row"
@@ -27,14 +27,14 @@
fxLayoutGap="10px"
fxLayoutAlign="start center"
>
- @if (label && showPreview) {
+ @if (showPreview()) {
<sp-form-field [level]="3" label="" class="mt-xs">
<sp-label
variant="solid"
size="medium"
shape="pill"
- [labelText]="label.label"
- [color]="label.color"
+ [labelText]="draftLabel().label"
+ [color]="draftLabel().color"
></sp-label>
</sp-form-field>
}
@@ -42,7 +42,8 @@
<mat-form-field color="accent" appearance="outline">
<input
matInput
- [(ngModel)]="label.label"
+ [ngModel]="draftLabel().label"
+ (ngModelChange)="updateLabelName($event)"
data-cy="label-name"
/>
</mat-form-field>
@@ -51,16 +52,18 @@
<mat-form-field color="accent" appearance="outline">
<input
matInput
- [(ngModel)]="label.description"
+ [ngModel]="draftLabel().description"
+ (ngModelChange)="updateDescription($event)"
data-cy="label-description"
/>
</mat-form-field>
</sp-form-field>
<sp-form-field [level]="3" [label]="'Color' | translate">
<input
- [(colorPicker)]="label.color"
+ [colorPicker]="draftLabel().color"
+ (colorPickerChange)="updateColor($event)"
[cpPosition]="'bottom'"
- [style.background]="label.color"
+ [style.background]="draftLabel().color"
/>
</sp-form-field>
<div fxFlex fxLayoutAlign="end center">
diff --git a/ui/src/app/configuration/label-configuration/edit-label/edit-label.component.ts b/ui/src/app/configuration/label-configuration/edit-label/edit-label.component.ts
index 64c5eeba5e..ab82504fa1 100644
--- a/ui/src/app/configuration/label-configuration/edit-label/edit-label.component.ts
+++ b/ui/src/app/configuration/label-configuration/edit-label/edit-label.component.ts
@@ -18,11 +18,11 @@
import {
Component,
- EventEmitter,
+ effect,
inject,
- Input,
- OnInit,
- Output,
+ input,
+ output,
+ signal,
} from '@angular/core';
import { SpLabel } from '@streampipes/platform-services';
import {
@@ -66,39 +66,64 @@ import { TranslatePipe } from '@ngx-translate/core';
TranslatePipe,
],
})
-export class SpEditLabelComponent implements OnInit {
+export class SpEditLabelComponent {
private colorizationService = inject(SpColorizationService);
- @Input()
- editMode = false;
+ readonly editMode = input(false);
- @Input()
- label: SpLabel;
+ readonly label = input<SpLabel | undefined>(undefined);
- @Input()
- showPreview = true;
+ readonly showPreview = input(true);
- @Output()
- cancelEmitter: EventEmitter<void> = new EventEmitter<void>();
+ readonly cancelEmitter = output<void>();
- @Output()
- saveEmitter: EventEmitter<SpLabel> = new EventEmitter<SpLabel>();
+ readonly saveEmitter = output<SpLabel>();
- ngOnInit(): void {
- if (!this.label) {
- this.label = {
- color: this.colorizationService.generateRandomColor(),
- label: 'New label',
- description: '',
- };
- }
+ readonly draftLabel = signal<SpLabel>(this.createDefaultLabel());
+
+ constructor() {
+ effect(() => {
+ const label = this.label();
+ this.draftLabel.set(
+ label ? { ...label } : this.createDefaultLabel(),
+ );
+ });
}
saveLabel(): void {
- this.saveEmitter.emit(this.label);
- if (this.showPreview) {
- this.label.color = this.colorizationService.generateRandomColor();
- console.log(this.label.color);
+ this.saveEmitter.emit({ ...this.draftLabel() });
+ if (this.showPreview()) {
+ this.draftLabel.update(label => ({
+ ...label,
+ color: this.colorizationService.generateRandomColor(),
+ }));
}
}
+
+ updateLabelName(label: string): void {
+ this.updateDraftLabel({ label });
+ }
+
+ updateDescription(description: string): void {
+ this.updateDraftLabel({ description });
+ }
+
+ updateColor(color: string): void {
+ this.updateDraftLabel({ color });
+ }
+
+ private updateDraftLabel(partial: Partial<SpLabel>): void {
+ this.draftLabel.update(label => ({
+ ...label,
+ ...partial,
+ }));
+ }
+
+ private createDefaultLabel(): SpLabel {
+ return {
+ color: this.colorizationService.generateRandomColor(),
+ label: 'New label',
+ description: '',
+ };
+ }
}
diff --git a/ui/src/app/configuration/label-configuration/label-configuration.component.html b/ui/src/app/configuration/label-configuration/label-configuration.component.html
index b69a045cc8..5420df12f5 100644
--- a/ui/src/app/configuration/label-configuration/label-configuration.component.html
+++ b/ui/src/app/configuration/label-configuration/label-configuration.component.html
@@ -36,16 +36,16 @@
mat-flat-button
color="accent"
data-cy="new-label-button"
- (click)="createLabelMode = true"
+ (click)="createLabelMode.set(true)"
>
<i class="material-icons">add</i
><span> {{ 'New' | translate }}</span>
</button>
</div>
- @if (createLabelMode) {
+ @if (createLabelMode()) {
<div class="mb-10">
<sp-edit-label
- (cancelEmitter)="createLabelMode = false"
+ (cancelEmitter)="createLabelMode.set(false)"
(saveEmitter)="saveLabel($event)"
></sp-edit-label>
</div>
@@ -89,7 +89,7 @@
[showPreview]="false"
[label]="label"
(cancelEmitter)="removeEditedLabel(label._id)"
- (saveEmitter)="updateLabel(label)"
+ (saveEmitter)="updateLabel($event)"
></sp-edit-label>
}
</td>
@@ -103,7 +103,7 @@
mat-icon-button
color="accent"
[matTooltip]="'Edit label' | translate"
- (click)="editedLabels.push(label._id)"
+ (click)="addEditedLabel(label._id)"
>
<mat-icon>edit</mat-icon>
</button>
diff --git a/ui/src/app/configuration/label-configuration/label-configuration.component.ts b/ui/src/app/configuration/label-configuration/label-configuration.component.ts
index 1206f7d41e..960edf19b3 100644
--- a/ui/src/app/configuration/label-configuration/label-configuration.component.ts
+++ b/ui/src/app/configuration/label-configuration/label-configuration.component.ts
@@ -16,7 +16,7 @@
*
*/
-import { Component, OnInit, ViewChild, inject } from '@angular/core';
+import { Component, OnInit, ViewChild, inject, signal } from '@angular/core';
import { SpConfigurationTabsService } from '../configuration-tabs.service';
import { LabelsService, SpLabel } from '@streampipes/platform-services';
import { SpConfigurationRoutes } from '../configuration.breadcrumb';
@@ -83,7 +83,7 @@ export class SpLabelConfigurationComponent implements OnInit {
tabs: SpNavigationItem[] = [];
allLabels: SpLabel[] = [];
- createLabelMode = false;
+ readonly createLabelMode = signal(false);
dataSource: MatTableDataSource<SpLabel> = new MatTableDataSource<SpLabel>();
@@ -91,9 +91,9 @@ export class SpLabelConfigurationComponent implements OnInit {
sort: MatSort;
displayedColumns = ['name', 'description', 'actions'];
- labelsinUse = [];
+ labelsinUse: string[] = [];
- editedLabels: string[] = [];
+ readonly editedLabels = signal<string[]>([]);
ngOnInit(): void {
this.tabs = this.tabService.getTabs();
@@ -118,7 +118,10 @@ export class SpLabelConfigurationComponent implements OnInit {
}
saveLabel(label: SpLabel): void {
- this.labelsService.addLabel(label).subscribe(() => this.reloadLabels());
+ this.labelsService.addLabel(label).subscribe(() => {
+ this.createLabelMode.set(false);
+ this.reloadLabels();
+ });
}
updateLabel(label: SpLabel): void {
@@ -135,10 +138,16 @@ export class SpLabelConfigurationComponent implements OnInit {
}
removeEditedLabel(labelId: string): void {
- this.editedLabels.splice(this.editedLabels.indexOf(labelId), 1);
+ this.editedLabels.update(labels => labels.filter(id => id !== labelId));
}
isEditMode(labelId: string): boolean {
- return this.editedLabels.find(l => l === labelId) !== undefined;
+ return this.editedLabels().includes(labelId);
+ }
+
+ addEditedLabel(labelId: string): void {
+ this.editedLabels.update(labels =>
+ labels.includes(labelId) ? labels : [...labels, labelId],
+ );
}
}