From 89b0b622c0f9834697251b7cec1d565cd062bc6c Mon Sep 17 00:00:00 2001 From: Maksym Tsymbarov Date: Wed, 4 Nov 2026 12:21:03 +0100 Subject: [PATCH] PR comments fixes --- .../core/services/dashboard-utils.service.ts | 32 +++---------------- .../dashboard-page.component.ts | 12 +++++-- 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/ui-ngx/src/app/core/services/dashboard-utils.service.ts b/ui-ngx/src/app/core/services/dashboard-utils.service.ts index 8ca8532de5..0f162e3aef 100644 --- a/ui-ngx/src/app/core/services/dashboard-utils.service.ts +++ b/ui-ngx/src/app/core/services/dashboard-utils.service.ts @@ -696,7 +696,8 @@ export class DashboardUtilsService { widgetLayout.col = column; if (this.hasWidgetCollision(widgetLayout.row, widgetLayout.col, widgetLayout.sizeX, widgetLayout.sizeY, Object.values(layout.widgets))) { - this.widgetPossiblePosition(widgetLayout, layout); + this.widgetPossiblePosition(widgetLayout, Object.values(layout.widgets), + layout.gridSettings.minColumns || layout.gridSettings.columns || 0); } } else { row = 0; @@ -719,15 +720,13 @@ export class DashboardUtilsService { layout.widgets[widget.id] = widgetLayout; } - private widgetPossiblePosition(widgetLayout: WidgetLayout, layout: DashboardLayout) { + private widgetPossiblePosition(widgetLayout: WidgetLayout, widgetLayouts: WidgetLayout[], columns: number) { let bestRow = 0; let bestCol = 0; - let maxCol = layout.gridSettings.minColumns || layout.gridSettings.columns || 0; + let maxCol = columns; let maxRow = 0; - const widgetLayouts = Object.values(layout.widgets); - widgetLayouts.forEach(widget => { maxCol = Math.max(maxCol, widget.col + widget.sizeX); maxRow = Math.max(maxRow, widget.row + widget.sizeY); @@ -903,33 +902,12 @@ export class DashboardUtilsService { const placed: WidgetLayout[] = []; for (const widget of widgets) { if (this.hasWidgetCollision(widget.row, widget.col, widget.sizeX, widget.sizeY, placed)) { - this.findFreeWidgetPosition(widget, placed, columns); + this.widgetPossiblePosition(widget, placed, columns); } placed.push(widget); } } - private findFreeWidgetPosition(widgetLayout: WidgetLayout, widgetLayouts: WidgetLayout[], columns: number) { - let maxCol = columns; - let maxRow = 0; - widgetLayouts.forEach(widget => { - maxCol = Math.max(maxCol, widget.col + widget.sizeX); - maxRow = Math.max(maxRow, widget.row + widget.sizeY); - }); - for (let row = 0; row <= maxRow; row++) { - for (let col = 0; col + widgetLayout.sizeX <= maxCol; col++) { - if (!this.hasWidgetCollision(row, col, widgetLayout.sizeX, widgetLayout.sizeY, widgetLayouts)) { - widgetLayout.row = row; - widgetLayout.col = col; - return; - } - } - } - // Wider than the grid: park it on a fresh row. - widgetLayout.row = maxRow; - widgetLayout.col = 0; - } - public moveWidgets(layout: DashboardLayout, cols: number, rows: number) { cols = isDefinedAndNotNull(cols) ? Math.round(cols) : 0; rows = isDefinedAndNotNull(rows) ? Math.round(rows) : 0; diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts index 3dfda2c4b5..dbb7897873 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts @@ -1110,9 +1110,15 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC if (layoutsData) { if (this.isEdit && state !== this.dashboardCtx.state && Object.keys(layoutsData).some(l => { const layout: DashboardPageLayout = this.layouts[l]; - const breakpoint = (layout && layout.layoutCtx.breakpoint) || 'default'; - const layoutInfo: BreakpointLayoutInfo = layoutsData[l][breakpoint] || layoutsData[l].default; - return layoutInfo && this.dashboardUtils.hasCollidingWidgets(layoutInfo.widgetLayouts); + let breakpoint = (layout && layout.layoutCtx.breakpoint) || 'default'; + if (!layoutsData[l][breakpoint]) { + breakpoint = 'default'; + } + const layoutInfo: BreakpointLayoutInfo = layoutsData[l][breakpoint]; + if (!layoutInfo || (breakpoint !== 'default' && layoutInfo.gridSettings?.viewFormat === ViewFormatType.list)) { + return false; + } + return this.dashboardUtils.hasCollidingWidgets(layoutInfo.widgetLayouts); })) { this.store.dispatch(new ActionNotificationShow({ message: this.translate.instant('dashboard.state-widgets-overlap-warning'),