-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Enhance error handling in ComputeTablePropertyControlV2 binding …
…methods (#38205)
- Loading branch information
1 parent
da449ee
commit 08cd433
Showing
9 changed files
with
163 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...t/packages/dsl/src/migrate/migrations/090-migrate-table-widget-v2-validation-try-catch.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { ColumnProperties, DSLWidget, WidgetProps } from "../types"; | ||
import { isDynamicValue, traverseDSLAndMigrate } from "../utils"; | ||
|
||
const oldBindingPrefix = (tableName: string) => { | ||
return `{{${tableName}.processedTableData.map((currentRow, currentIndex) => (`; | ||
}; | ||
|
||
const newBindingPrefix = (tableName: string) => { | ||
return `{{${tableName}.processedTableData.map((currentRow, currentIndex) => { try { return (`; | ||
}; | ||
|
||
const oldBindingSuffix = `))}}`; | ||
const newBindingSuffix = `); } catch (e) { return null; }})}}`; | ||
|
||
export const migrateTableWidgetV2ValidationTryCatch = ( | ||
currentDSL: DSLWidget, | ||
) => { | ||
return traverseDSLAndMigrate(currentDSL, (widget: WidgetProps) => { | ||
if (widget.type !== "TABLE_WIDGET_V2") return; | ||
|
||
const primaryColumns: Record<string, ColumnProperties> = | ||
widget.primaryColumns as Record<string, ColumnProperties>; | ||
|
||
Object.values(primaryColumns).forEach((colProperties) => { | ||
if (!colProperties.computedValue) return; | ||
|
||
const value = colProperties.computedValue; | ||
|
||
if (!isDynamicValue(value)) return; | ||
|
||
const tableName = widget.widgetName; | ||
const oldPrefix = oldBindingPrefix(tableName); | ||
|
||
// Only update if it matches the old format | ||
if (!value.startsWith(oldPrefix)) return; | ||
|
||
// Replace old prefix/suffix with new ones | ||
const computation = value | ||
.replace(oldPrefix, "") | ||
.replace(oldBindingSuffix, ""); | ||
|
||
// Add the new prefix and suffix with try-catch | ||
colProperties.computedValue = `${newBindingPrefix(tableName)}${computation}${newBindingSuffix}`; | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
app/client/packages/dsl/src/migrate/tests/TableWidgetV2/DSLs/ValidationTryCatchDSLs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { DSLWidget } from "../../../types"; | ||
|
||
const oldBindingPrefix = (tableName: string) => { | ||
return `{{${tableName}.processedTableData.map((currentRow, currentIndex) => (`; | ||
}; | ||
|
||
const newBindingPrefix = (tableName: string) => { | ||
return `{{${tableName}.processedTableData.map((currentRow, currentIndex) => { try { return (`; | ||
}; | ||
|
||
const oldBindingSuffix = `))}}`; | ||
const newBindingSuffix = `); } catch (e) { return null; }})}}`; | ||
|
||
const computation = "currentRow.id + '_' + currentIndex"; | ||
|
||
export const validationTryCatchInput = { | ||
children: [ | ||
{ | ||
widgetName: "Table1", | ||
type: "TABLE_WIDGET_V2", | ||
primaryColumns: { | ||
customColumn1: { | ||
computedValue: `${oldBindingPrefix("Table1")}${computation}${oldBindingSuffix}`, | ||
}, | ||
customColumn2: { | ||
computedValue: "static value", // Should not be modified | ||
}, | ||
}, | ||
}, | ||
], | ||
} as any as DSLWidget; | ||
|
||
export const validationTryCatchOutput = { | ||
children: [ | ||
{ | ||
widgetName: "Table1", | ||
type: "TABLE_WIDGET_V2", | ||
primaryColumns: { | ||
customColumn1: { | ||
computedValue: `${newBindingPrefix("Table1")}${computation}${newBindingSuffix}`, | ||
}, | ||
customColumn2: { | ||
computedValue: "static value", // Not modified | ||
}, | ||
}, | ||
}, | ||
], | ||
} as any as DSLWidget; |
15 changes: 15 additions & 0 deletions
15
app/client/packages/dsl/src/migrate/tests/TableWidgetV2/ValidationTryCatch.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { migrateTableWidgetV2ValidationTryCatch } from "../../migrations/090-migrate-table-widget-v2-validation-try-catch"; | ||
import { | ||
validationTryCatchInput, | ||
validationTryCatchOutput, | ||
} from "./DSLs/ValidationTryCatchDSLs"; | ||
|
||
describe("migrateTableWidgetV2ValidationTryCatch", () => { | ||
it("should add try-catch blocks to table compute value bindings", () => { | ||
const migratedDSL = migrateTableWidgetV2ValidationTryCatch( | ||
validationTryCatchInput, | ||
); | ||
|
||
expect(migratedDSL).toEqual(validationTryCatchOutput); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters