From 4604c2fa5fd3834bf0bbb84d125a2125ffc4c702 Mon Sep 17 00:00:00 2001 From: JuanBerrocal Date: Thu, 23 Oct 2025 06:47:12 +0200 Subject: [PATCH 1/3] Let table original position when still overlaps after making all attemps --- .../components/export-button/export-button.business.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pods/toolbar/components/export-button/export-button.business.ts b/src/pods/toolbar/components/export-button/export-button.business.ts index 765b62f7..be5333eb 100644 --- a/src/pods/toolbar/components/export-button/export-button.business.ts +++ b/src/pods/toolbar/components/export-button/export-button.business.ts @@ -92,10 +92,10 @@ export const placeTableWithoutOverlap = ( ): TableVm => { let newTable = table; let attempts = 0; - + while ( doesTableOverlap(newTable, tables) && - attempts < TABLE_CONST.MAX_PLACEMENT_ATTEMPTS + attempts < TABLE_CONST.MAX_PLACEMENT_ATTEMPTS ) { newTable = { ...newTable, @@ -113,6 +113,12 @@ export const placeTableWithoutOverlap = ( attempts++; } + // If relocated table still overlaps, restore original posotion. + if (doesTableOverlap(newTable, tables)) { + newTable.x = table.x; + newTable.y = table.y; + } + return newTable; }; From 3892a50f80240bfd5b06c1d64f8619ddbcf43f95 Mon Sep 17 00:00:00 2001 From: JuanBerrocal Date: Tue, 28 Oct 2025 06:41:56 +0100 Subject: [PATCH 2/3] Fix code to pass test: should properly adjusts tables to avoid overlap in complex scenarios --- .../toolbar/components/export-button/export-button.business.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pods/toolbar/components/export-button/export-button.business.ts b/src/pods/toolbar/components/export-button/export-button.business.ts index be5333eb..8f7fd991 100644 --- a/src/pods/toolbar/components/export-button/export-button.business.ts +++ b/src/pods/toolbar/components/export-button/export-button.business.ts @@ -114,7 +114,7 @@ export const placeTableWithoutOverlap = ( } // If relocated table still overlaps, restore original posotion. - if (doesTableOverlap(newTable, tables)) { + if ((newTable.width) && (newTable.width > TABLE_CONST.TABLE_SHIFT_DISTANCE) && doesTableOverlap(newTable, tables)) { newTable.x = table.x; newTable.y = table.y; } From b73abe5e58dc48b2a0e4c3e0422baa89bef98834 Mon Sep 17 00:00:00 2001 From: JuanBerrocal Date: Sun, 16 Nov 2025 01:49:59 +0100 Subject: [PATCH 3/3] test finished --- .../export-button.business.spec.ts | 138 ++++++++++++++++++ .../export-button/export-button.business.ts | 4 +- 2 files changed, 140 insertions(+), 2 deletions(-) diff --git a/src/pods/toolbar/components/export-button/export-button.business.spec.ts b/src/pods/toolbar/components/export-button/export-button.business.spec.ts index 736380bf..b6805f19 100644 --- a/src/pods/toolbar/components/export-button/export-button.business.spec.ts +++ b/src/pods/toolbar/components/export-button/export-button.business.spec.ts @@ -1935,6 +1935,7 @@ describe('export-button.business', () => { // Act const result = placeAllTablesWithoutOverlap(tables); + // Assert result.forEach((table, index) => { @@ -1951,6 +1952,122 @@ describe('export-button.business', () => { } }); }); + + it('Wide tables shouldnt be on the left border overlapping other tables after relocating. ', () => { + // Arrange + const tables: TableVm[] = [ + { + id: '1', + fields: [ + { id: '1', PK: true, name: 'campo1', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '2', PK: true, name: 'campo2', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '3', PK: true, name: 'campo3', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '4', PK: true, name: 'campo4', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '5', PK: true, name: 'campo5', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '6', PK: true, name: 'campo6', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '7', PK: true, name: 'campo7', type: 'string', children: [], isCollapsed: false, isArray: false}, + ], + tableName: 'table1', + x: 100, + y: 300 + }, + { + id: '2', + fields: [ + { id: '1', PK: true, name: 'campo1', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '2', PK: true, name: 'campo2', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '3', PK: true, name: 'campo3', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '4', PK: true, name: 'campo4', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '5', PK: true, name: 'campo5', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '6', PK: true, name: 'campo6', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '7', PK: true, name: 'campo7', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '8', PK: true, name: 'campo8', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '9', PK: true, name: 'campo9', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '10', PK: true, name: 'campo10', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '11', PK: true, name: 'campo11', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '12', PK: true, name: 'campo12', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '13', PK: true, name: 'campo13', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '14', PK: true, name: 'campo14', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '15', PK: true, name: 'campo15', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '16', PK: true, name: 'campo16', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '17', PK: true, name: 'campo17', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '18', PK: true, name: 'campo18', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '19', PK: true, name: 'campo19', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '20', PK: true, name: 'campo20', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '21', PK: true, name: 'campo21', type: 'string', children: [], isCollapsed: false, isArray: false}, + { id: '22', PK: true, name: 'campo22', type: 'string', children: [], isCollapsed: false, isArray: false}, + ], + tableName: 'table2', + x: 450, + y: 100, + width: 780 + }, + { + id: '3', + fields: [], + tableName: 'table3', + x: 1200, + y: 700 + }, + { + id: '4', + fields: [], + tableName: 'table4', + x: 1500, + y: 100 + }, + { + id: '5', + fields: [], + tableName: 'table5', + x: 300, + y: 100, + }, + { + id: '6', + fields: [], + tableName: 'table6', + x: 100, + y: 150, + }, + { + id: '7', + fields: [], + tableName: 'table7', + x: 150, + y: 150, + }, + ]; + + // Act + const result = placeAllTablesWithoutOverlap(tables); + + + // Assert + result.forEach((table, index) => { + const tableWidth = table.width ?? TABLE_CONST.DEFAULT_TABLE_WIDTH; + const tableHeight = calculateTableHeight(table.fields); + for (let i = 0; i < result.length; i++) { + if (i !== index) { + const iWidth = result[i].width ?? TABLE_CONST.DEFAULT_TABLE_WIDTH; + const iHeight = calculateTableHeight(result[i].fields); + + const isOverlapping = !( + table.x >= result[i].x + iWidth || + table.x + tableWidth <= result[i].x || + table.y >= result[i].y + iHeight || + table.y + tableHeight <= result[i].y + ); + + const hasBadPosition = (isOverlapping) && + (table.x <= TABLE_CONST.TABLE_SHIFT_DISTANCE) && + (tableWidth > TABLE_CONST.DEFAULT_TABLE_WIDTH); + + expect(hasBadPosition).toBe(false); + } + } + }); + }); }); }); @@ -1970,6 +2087,27 @@ describe('getPropertyJsonSchema', () => { //Assert expect(result).toBe('"fieldName": { bsonType: "string" }'); }); +}); + + + +describe('getPropertyJsonSchema', () => { + it('should generate json schema for non-array field', () => { + //Arrange + const field: FieldVm = { + id: '1', + PK: false, + name: 'fieldName', + type: 'string', + }; + + //Act + const result = getPropertyJsonSchema(field); + + //Assert + expect(result).toBe('"fieldName": { bsonType: "string" }'); + }); + it('should generate json schema for array field', () => { //Arrange diff --git a/src/pods/toolbar/components/export-button/export-button.business.ts b/src/pods/toolbar/components/export-button/export-button.business.ts index 8f7fd991..0e151b1f 100644 --- a/src/pods/toolbar/components/export-button/export-button.business.ts +++ b/src/pods/toolbar/components/export-button/export-button.business.ts @@ -113,8 +113,8 @@ export const placeTableWithoutOverlap = ( attempts++; } - // If relocated table still overlaps, restore original posotion. - if ((newTable.width) && (newTable.width > TABLE_CONST.TABLE_SHIFT_DISTANCE) && doesTableOverlap(newTable, tables)) { + // If relocated table still overlaps, restore original position. + if ((newTable.width) && (newTable.width > TABLE_CONST.DEFAULT_TABLE_WIDTH) && doesTableOverlap(newTable, tables)) { newTable.x = table.x; newTable.y = table.y; }