You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2026/06/10 18:04:29 UTC

(streampipes) branch dev updated: fix(#4539): Use correct elementId for deeply cloned widgets (#4540)

This is an automated email from the ASF dual-hosted git repository.

dominikriemer pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to refs/heads/dev by this push:
     new e9c88fdf40 fix(#4539): Use correct elementId for deeply cloned widgets (#4540)
e9c88fdf40 is described below

commit e9c88fdf40540ab00a179c3cc2e078aeb76aae33
Author: Dominik Riemer <do...@gmail.com>
AuthorDate: Wed Jun 10 20:04:22 2026 +0200

    fix(#4539): Use correct elementId for deeply cloned widgets (#4540)
---
 .../clone-dashboard-dialog.component.html          | 87 +++++++++++-----------
 .../clone-dashboard-dialog.component.ts            | 71 +++++++++++++-----
 2 files changed, 94 insertions(+), 64 deletions(-)

diff --git a/ui/src/app/dashboard/dialogs/clone-dashboard/clone-dashboard-dialog.component.html b/ui/src/app/dashboard/dialogs/clone-dashboard/clone-dashboard-dialog.component.html
index 7fa58ea7cd..a752aba63c 100644
--- a/ui/src/app/dashboard/dialogs/clone-dashboard/clone-dashboard-dialog.component.html
+++ b/ui/src/app/dashboard/dialogs/clone-dashboard/clone-dashboard-dialog.component.html
@@ -25,37 +25,37 @@
                     fxLayout="column"
                     style="margin: 5px; width: 100%"
                 >
-                    <!-- Name -->
-                    <mat-form-field
-                        class="w-100"
-                        floatLabel="auto"
-                        color="accent"
+                    <sp-form-field
+                        [level]="3"
+                        [label]="'New dashboard title' | translate"
                     >
-                        <mat-label
-                            >{{ 'New dashboard title' | translate }}
-                        </mat-label>
-                        <input
-                            id="dvname"
-                            #dvname="ngModel"
-                            required
-                            matInput
-                            data-cy="clone-data-view-name"
-                            [(ngModel)]="form.name"
-                        />
-                        <mat-error
-                            >{{ 'Title must not be empty' | translate }}
-                        </mat-error>
-                    </mat-form-field>
+                        <mat-form-field class="w-100" floatLabel="auto">
+                            <input
+                                id="dvname"
+                                #dvname="ngModel"
+                                required
+                                matInput
+                                data-cy="clone-data-view-name"
+                                [(ngModel)]="form.name"
+                            />
+                            <mat-error
+                                >{{ 'Title must not be empty' | translate }}
+                            </mat-error>
+                        </mat-form-field>
+                    </sp-form-field>
 
-                    <!-- Description (optional) -->
-                    <mat-form-field class="w-100" color="accent">
-                        <mat-label>{{ 'Description' | translate }}</mat-label>
-                        <input
-                            matInput
-                            [(ngModel)]="form.description"
-                            data-cy="clone-data-view-description"
-                        />
-                    </mat-form-field>
+                    <sp-form-field
+                        [level]="3"
+                        [label]="'Description' | translate"
+                    >
+                        <mat-form-field class="w-100" color="accent">
+                            <input
+                                matInput
+                                [(ngModel)]="form.description"
+                                data-cy="clone-data-view-description"
+                            />
+                        </mat-form-field>
+                    </sp-form-field>
 
                     <!-- Deep clone -->
                     <div class="mt-10" fxLayout="column">
@@ -102,22 +102,21 @@
                                         fxLayout="column"
                                         class="widget-edit p-10"
                                     >
-                                        <mat-form-field
-                                            class="w-100"
-                                            color="accent"
+                                        <sp-form-field
+                                            [level]="3"
+                                            [label]="'Chart Name' | translate"
                                         >
-                                            <mat-label
-                                                >{{ 'Chart Name' | translate }}
-                                            </mat-label>
-                                            <input
-                                                matInput
-                                                [(ngModel)]="
-                                                    w.cloned
-                                                        .baseAppearanceConfig
-                                                        .widgetTitle
-                                                "
-                                            />
-                                        </mat-form-field>
+                                            <mat-form-field class="w-100">
+                                                <input
+                                                    matInput
+                                                    [(ngModel)]="
+                                                        w.cloned
+                                                            .baseAppearanceConfig
+                                                            .widgetTitle
+                                                    "
+                                                />
+                                            </mat-form-field>
+                                        </sp-form-field>
                                     </div>
                                 </mat-expansion-panel>
                             }
diff --git a/ui/src/app/dashboard/dialogs/clone-dashboard/clone-dashboard-dialog.component.ts b/ui/src/app/dashboard/dialogs/clone-dashboard/clone-dashboard-dialog.component.ts
index 09ad3fc186..29ab64dc2b 100644
--- a/ui/src/app/dashboard/dialogs/clone-dashboard/clone-dashboard-dialog.component.ts
+++ b/ui/src/app/dashboard/dialogs/clone-dashboard/clone-dashboard-dialog.component.ts
@@ -19,16 +19,17 @@
 import { Component, inject, Input, OnInit } from '@angular/core';
 import {
     ChartService,
+    ClientDashboardItem,
     CompositeDashboard,
     Dashboard,
     DashboardService,
     DataExplorerWidgetModel,
 } from '@streampipes/platform-services';
-import { DialogRef } from '@streampipes/shared-ui';
+import { DialogRef, FormFieldComponent } from '@streampipes/shared-ui';
 import { IdGeneratorService } from '../../../core-services/id-generator/id-generator.service';
 import { Observable, zip } from 'rxjs';
 import { TranslatePipe, TranslateService } from '@ngx-translate/core';
-import { MatError, MatFormField, MatLabel } from '@angular/material/form-field';
+import { MatError, MatFormField } from '@angular/material/form-field';
 import { MatInput } from '@angular/material/input';
 import { FormsModule } from '@angular/forms';
 import { MatCheckbox } from '@angular/material/checkbox';
@@ -61,7 +62,6 @@ export interface WidgetClone {
         LayoutDirective,
         FlexDirective,
         MatFormField,
-        MatLabel,
         MatInput,
         FormsModule,
         MatError,
@@ -76,6 +76,7 @@ export interface WidgetClone {
         LayoutAlignDirective,
         MatProgressSpinner,
         TranslatePipe,
+        FormFieldComponent,
     ],
 })
 export class CloneDashboardDialogComponent implements OnInit {
@@ -138,25 +139,20 @@ export class CloneDashboardDialogComponent implements OnInit {
         clonedDashboard.name = this.form.name;
         clonedDashboard.description = this.form.description;
         if (this.form.deepClone) {
-            clonedDashboard.widgets.forEach((widget, index) => {
-                const widgetElementId =
-                    this.idGeneratorService.generateWithPrefix(
-                        CloneDashboardDialogComponent.ChartPrefix,
-                        6,
-                    );
-                const clonedWidget = clonedWidgets.find(
-                    w => w.elementId === widget.id,
+            const widgetCloneMap = new Map<string, DataExplorerWidgetModel>();
+
+            clonedDashboard.widgets.forEach(widget => {
+                this.remapWidgetReference(
+                    widget,
+                    clonedWidgets,
+                    widgetCloneMap,
+                    this.form.allowWidgetEdits,
                 );
-                if (clonedWidget !== undefined) {
-                    clonedWidgets[index].elementId = widgetElementId;
-                    clonedWidgets[index].metadata.createdAtEpochMs = Date.now();
-                    clonedWidgets[index].metadata.lastModifiedEpochMs =
-                        Date.now();
-                    clonedWidgets[index].rev = undefined;
-                }
-                widget.id = widgetElementId;
             });
-            widget$ = clonedWidgets.map(w => this.chartService.saveChart(w));
+
+            widget$ = Array.from(widgetCloneMap.values()).map(w =>
+                this.chartService.saveChart(w),
+            );
         }
         zip([
             ...widget$,
@@ -165,4 +161,39 @@ export class CloneDashboardDialogComponent implements OnInit {
             this.dialogRef.close(true);
         });
     }
+
+    private remapWidgetReference(
+        dashboardWidget: ClientDashboardItem,
+        clonedWidgets: DataExplorerWidgetModel[],
+        widgetCloneMap: Map<string, DataExplorerWidgetModel>,
+        keepWidgetTitle: boolean,
+    ): void {
+        const sourceWidgetId = dashboardWidget.dataViewElementId;
+        if (widgetCloneMap.has(sourceWidgetId)) {
+            dashboardWidget.dataViewElementId =
+                widgetCloneMap.get(sourceWidgetId).elementId;
+            return;
+        }
+
+        const clonedWidget = clonedWidgets.find(
+            widget => widget.elementId === sourceWidgetId,
+        );
+        if (clonedWidget === undefined) {
+            return;
+        }
+
+        clonedWidget.elementId = this.idGeneratorService.generateWithPrefix(
+            CloneDashboardDialogComponent.ChartPrefix,
+            6,
+        );
+        clonedWidget.metadata.createdAtEpochMs = Date.now();
+        clonedWidget.metadata.lastModifiedEpochMs = Date.now();
+        if (!keepWidgetTitle) {
+            clonedWidget.baseAppearanceConfig.widgetTitle = `${clonedWidget.baseAppearanceConfig.widgetTitle} (${this.translate.instant('Copy')})`;
+        }
+        clonedWidget.rev = undefined;
+
+        widgetCloneMap.set(sourceWidgetId, clonedWidget);
+        dashboardWidget.dataViewElementId = clonedWidget.elementId;
+    }
 }