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

zehnder 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 ae73d7270c Popup to ensure saving when creating a new chart (#3991)
ae73d7270c is described below

commit ae73d7270c7791684fd0b489dcd83f350fe406b7
Author: Jacqueline Höllig <[email protected]>
AuthorDate: Fri Nov 28 15:33:54 2025 +0100

    Popup to ensure saving when creating a new chart (#3991)
    
    Co-authored-by: Philipp Zehnder <[email protected]>
---
 .../support/utils/dataExplorer/DataExplorerBtns.ts |  3 ++
 .../utils/dataExplorer/DataExplorerUtils.ts        |  1 +
 .../data-explorer-chart-container.component.ts     |  8 ++--
 .../chart-panel-can-deactivate-guard.service.ts    |  9 +++-
 .../data-explorer-chart-view.component.html        |  1 +
 .../data-explorer-chart-view.component.ts          | 56 ++++++++++++++++++++--
 ...data-explorer-widget-data-settings.component.ts |  5 ++
 ui/src/app/data-explorer/data-explorer.module.ts   |  1 +
 8 files changed, 77 insertions(+), 7 deletions(-)

diff --git a/ui/cypress/support/utils/dataExplorer/DataExplorerBtns.ts 
b/ui/cypress/support/utils/dataExplorer/DataExplorerBtns.ts
index bbbbf0687f..f2407e8151 100644
--- a/ui/cypress/support/utils/dataExplorer/DataExplorerBtns.ts
+++ b/ui/cypress/support/utils/dataExplorer/DataExplorerBtns.ts
@@ -24,6 +24,9 @@ export class DataExplorerBtns {
     public static saveDataViewButton() {
         return cy.dataCy('save-data-view-btn', { timeout: 10000 });
     }
+    public static confirmSave() {
+        return cy.dataCy('confirm-delete', { timeout: 10000 });
+    }
 
     public static saveDataViewBtn() {
         return cy.dataCy('save-data-view');
diff --git a/ui/cypress/support/utils/dataExplorer/DataExplorerUtils.ts 
b/ui/cypress/support/utils/dataExplorer/DataExplorerUtils.ts
index ec053df06b..8f55d2cc2f 100644
--- a/ui/cypress/support/utils/dataExplorer/DataExplorerUtils.ts
+++ b/ui/cypress/support/utils/dataExplorer/DataExplorerUtils.ts
@@ -339,6 +339,7 @@ export class DataExplorerUtils {
         DataExplorerBtns.saveDataViewButton().click({
             force: true,
         });
+        DataExplorerBtns.confirmSave().click();
     }
 
     public static saveDashboardConfiguration() {
diff --git 
a/ui/src/app/data-explorer-shared/components/chart-container/data-explorer-chart-container.component.ts
 
b/ui/src/app/data-explorer-shared/components/chart-container/data-explorer-chart-container.component.ts
index 8c5c007a1b..584696694a 100644
--- 
a/ui/src/app/data-explorer-shared/components/chart-container/data-explorer-chart-container.component.ts
+++ 
b/ui/src/app/data-explorer-shared/components/chart-container/data-explorer-chart-container.component.ts
@@ -236,9 +236,11 @@ export class DataExplorerChartContainerComponent
     }
 
     chooseWidget(widgetTypeId: string) {
-        const widgetToDisplay =
-            this.chartRegistryService.getChartTemplate(widgetTypeId);
-        this.loadComponent(widgetToDisplay.widgetComponent);
+        if (widgetTypeId != undefined) {
+            const widgetToDisplay =
+                this.chartRegistryService.getChartTemplate(widgetTypeId);
+            this.loadComponent(widgetToDisplay.widgetComponent);
+        }
     }
 
     loadComponent(widgetToDisplay) {
diff --git 
a/ui/src/app/data-explorer-shared/services/chart-panel-can-deactivate-guard.service.ts
 
b/ui/src/app/data-explorer-shared/services/chart-panel-can-deactivate-guard.service.ts
index d7b12cfe97..77b885fcaa 100644
--- 
a/ui/src/app/data-explorer-shared/services/chart-panel-can-deactivate-guard.service.ts
+++ 
b/ui/src/app/data-explorer-shared/services/chart-panel-can-deactivate-guard.service.ts
@@ -28,12 +28,19 @@ import { SupportsUnsavedChangeDialog } from 
'../models/dataview-dashboard.model'
 @Injectable({ providedIn: 'root' })
 export class ChartPanelCanDeactivateGuard {
     constructor(private router: Router) {}
+    checkQueryParams(queryParams: { [key: string]: any }): boolean {
+        const { editMode, startDate, endDate } = queryParams;
+        return editMode && startDate && endDate;
+    }
     canDeactivate(
         component: SupportsUnsavedChangeDialog,
         route: ActivatedRouteSnapshot,
         state: RouterStateSnapshot,
     ): Observable<boolean> | boolean {
-        if (!this.router.getCurrentNavigation().extras?.state?.omitConfirm) {
+        if (
+            this.checkQueryParams(route.queryParams) ||
+            !this.router.getCurrentNavigation().extras?.state?.omitConfirm
+        ) {
             return component.confirmLeaveDialog(route, state);
         } else {
             return true;
diff --git 
a/ui/src/app/data-explorer/components/chart-view/data-explorer-chart-view.component.html
 
b/ui/src/app/data-explorer/components/chart-view/data-explorer-chart-view.component.html
index 1273803b2b..15adc5ecbc 100644
--- 
a/ui/src/app/data-explorer/components/chart-view/data-explorer-chart-view.component.html
+++ 
b/ui/src/app/data-explorer/components/chart-view/data-explorer-chart-view.component.html
@@ -63,6 +63,7 @@
                                 <sp-data-explorer-designer-panel
                                     [currentlyConfiguredWidget]="dataView"
                                     [dataLakeMeasure]="dataLakeMeasure"
+                                    (addWidgetEmitter)="onAddWidget($event)"
                                     fxFlex="100"
                                 >
                                 </sp-data-explorer-designer-panel>
diff --git 
a/ui/src/app/data-explorer/components/chart-view/data-explorer-chart-view.component.ts
 
b/ui/src/app/data-explorer/components/chart-view/data-explorer-chart-view.component.ts
index e32fe3cc06..c374c0fd2a 100644
--- 
a/ui/src/app/data-explorer/components/chart-view/data-explorer-chart-view.component.ts
+++ 
b/ui/src/app/data-explorer/components/chart-view/data-explorer-chart-view.component.ts
@@ -29,6 +29,8 @@ import {
     DashboardConfig,
     DataExplorerWidgetModel,
     DataLakeMeasure,
+    EventPropertyUnion,
+    FieldConfig,
     LinkageData,
     TimeSettings,
 } from '@streampipes/platform-services';
@@ -58,6 +60,8 @@ import { ResizeEchartsService } from 
'../../../data-explorer-shared/services/res
 import { AssetDialogComponent } from '../../dialog/asset-dialog.component';
 import { AuthService } from '../../../services/auth.service';
 import { UserRole } from '../../../_enums/user-role.enum';
+import { Tuple2 } from 'src/app/core-model/base/Tuple2';
+import { ChartFieldProviderService } from 
'src/app/data-explorer-shared/services/chart-field-provider.service';
 
 @Component({
     selector: 'sp-data-explorer-data-view',
@@ -97,7 +101,7 @@ export class DataExplorerChartViewComponent
     private dialogService = inject(DialogService);
     private currentUserService = inject(CurrentUserService);
     private authService = inject(AuthService);
-
+    private fieldProvider = inject(ChartFieldProviderService);
     private assetSaveService = inject(AssetSaveService);
 
     currentUser$: Subscription;
@@ -125,10 +129,50 @@ export class DataExplorerChartViewComponent
         } else {
             this.createWidget();
             this.timeSettings = this.makeDefaultTimeSettings();
+            this.dataView.timeSettings = this.timeSettings;
             this.afterDataViewLoaded();
         }
     }
 
+    onAddWidget(event: Tuple2<DataLakeMeasure, DataExplorerWidgetModel>) {
+        if (!this.originalDataView?.visualizationConfig) {
+            this.setDefaultValuesOnOriginalDataViewForNewCharts();
+        }
+    }
+
+    setDefaultValuesOnOriginalDataViewForNewCharts() {
+        //Change original Data View if default Config does not exist
+        this.originalDataView = JSON.parse(JSON.stringify(this.dataView));
+        this.originalDataView.elementId = undefined;
+        this.originalDataView.rev = undefined;
+        this.originalDataView.widgetId = undefined;
+        //Set default
+        this.originalDataView.dataConfig.sourceConfigs[0].queryConfig.order ??=
+            'DESC';
+        this.addAllFields();
+    }
+
+    addAllFields() {
+        
this.originalDataView.dataConfig.sourceConfigs[0].measure.eventSchema.eventProperties.forEach(
+            property => {
+                if (this.fieldProvider.isDimensionProperty(property)) {
+                    this.addField(property);
+                }
+            },
+        );
+    }
+
+    addField(property: EventPropertyUnion) {
+        const selection: FieldConfig = {
+            runtimeName: property.runtimeName,
+            selected: false,
+            numeric: this.fieldProvider.isNumber(property),
+        };
+        
this.originalDataView.dataConfig.sourceConfigs[0].queryConfig.groupBy.push(
+            selection,
+        );
+    }
+
     loadDataView(dataViewId: string): void {
         this.dataViewLoaded = false;
         this.dataViewService
@@ -183,8 +227,13 @@ export class DataExplorerChartViewComponent
     }
 
     setShouldShowConfirm(): boolean {
-        const originalTimeSettings = this.originalDataView
-            .timeSettings as TimeSettings;
+        let originalTimeSettings: TimeSettings;
+        if (this.originalDataView?.timeSettings) {
+            originalTimeSettings = this.originalDataView
+                .timeSettings as TimeSettings;
+        } else {
+            originalTimeSettings = this.dataView.timeSettings as TimeSettings;
+        }
         const currentTimeSettings = this.dataView.timeSettings as TimeSettings;
         return this.detectChangesService.shouldShowConfirm(
             this.originalDataView,
@@ -212,6 +261,7 @@ export class DataExplorerChartViewComponent
             createdAtEpochMs: Date.now(),
             lastModifiedEpochMs: Date.now(),
         };
+
         this.dataView = { ...this.dataView };
     }
 
diff --git 
a/ui/src/app/data-explorer/components/chart-view/designer-panel/data-settings/data-explorer-widget-data-settings.component.ts
 
b/ui/src/app/data-explorer/components/chart-view/designer-panel/data-settings/data-explorer-widget-data-settings.component.ts
index 9bcaac512d..445c3d3202 100644
--- 
a/ui/src/app/data-explorer/components/chart-view/designer-panel/data-settings/data-explorer-widget-data-settings.component.ts
+++ 
b/ui/src/app/data-explorer/components/chart-view/designer-panel/data-settings/data-explorer-widget-data-settings.component.ts
@@ -191,6 +191,11 @@ export class DataExplorerWidgetDataSettingsComponent 
implements OnInit {
                 widgetId: this.currentlyConfiguredWidget.elementId,
                 newWidgetTypeId: this.currentlyConfiguredWidget.widgetType,
             });
+
+            this.createWidgetEmitter.emit({
+                a: this.dataLakeMeasure,
+                b: this.currentlyConfiguredWidget,
+            });
         }
     }
 
diff --git a/ui/src/app/data-explorer/data-explorer.module.ts 
b/ui/src/app/data-explorer/data-explorer.module.ts
index 87f584497f..e35f0a553a 100644
--- a/ui/src/app/data-explorer/data-explorer.module.ts
+++ b/ui/src/app/data-explorer/data-explorer.module.ts
@@ -147,6 +147,7 @@ import { AssetDialogComponent } from 
'./dialog/asset-dialog.component';
                     {
                         path: 'chart',
                         component: DataExplorerChartViewComponent,
+                        canDeactivate: [ChartPanelCanDeactivateGuard],
                     },
                     {
                         path: 'chart/:id',

Reply via email to