From 3d8bb67f02daebc0962077eb771f30fc780ad934 Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Thu, 26 Sep 2024 12:32:42 +0100 Subject: [PATCH 1/7] wip --- .../transform-grid-options.ts | 20 +++++++++- .../angular/warnings/output.component.ts | 2 +- .../angular/warnings/output.warnings.cjs | 1 - .../js/cell-selection-expressions/output.js | 17 +++++---- .../js/cell-selection-fill-handle/output.js | 15 ++++---- .../scenarios/js/cell-selection/output.js | 17 ++++----- .../scenarios/js/columnDefs/output.js | 2 +- .../js/multi-row-selection/output.js | 4 +- .../js/single-row-selection/output.js | 2 +- .../jsx/cell-selection-fill-handle/output.jsx | 5 +-- .../scenarios/jsx/cell-selection/output.jsx | 10 ++--- .../jsx/multi-row-selection/output.jsx | 2 +- .../output.jsx | 3 +- .../jsx/single-row-selection/output.jsx | 2 +- .../replacements.ts | 37 +++++++++---------- 15 files changed, 75 insertions(+), 64 deletions(-) diff --git a/packages/cli/src/codemods/plugins/transform-grid-options/transform-grid-options.ts b/packages/cli/src/codemods/plugins/transform-grid-options/transform-grid-options.ts index 53a5c69..064158f 100644 --- a/packages/cli/src/codemods/plugins/transform-grid-options/transform-grid-options.ts +++ b/packages/cli/src/codemods/plugins/transform-grid-options/transform-grid-options.ts @@ -777,7 +777,15 @@ export function migrateDeepProperty initializer = createSiblingPropertyInitializer(rootNode, rootAccessor); } if (!initializer) return; - const newObj = initializer.get('value'); + let newObj = initializer.get('value'); + if (!newObj.isObjectExpression()) { + // overwrite value with a new object expression + const [transformed] = initializer.replaceWith( + t.objectProperty(initializer.node.key, t.objectExpression([])), + ); + initializer = transformed; + newObj = initializer.get('value') as NodePath; + } if (!newObj.isObjectExpression()) return; rootNode = newObj; @@ -876,7 +884,15 @@ export function migrateDeepProperty initializer = createSiblingPropertyInitializer(rootNode, accessor); } if (!initializer) return; - const newObj = initializer.get('value'); + let newObj = initializer.get('value'); + if (!newObj.isObjectExpression()) { + // overwrite value with a new object expression + const [transformed] = initializer.replaceWith( + t.objectProperty(initializer.node.key, t.objectExpression([])), + ); + initializer = transformed; + newObj = initializer.get('value') as NodePath; + } if (!newObj.isObjectExpression()) return; rootNode = newObj; diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/output.component.ts b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/output.component.ts index b7ce35b..bb436a3 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/output.component.ts +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/output.component.ts @@ -18,7 +18,7 @@ import { IOlympicData } from './interfaces'; [rowMultiSelectWithClick]="true" [groupSelectsChildren]="true" [groupSelectsFiltered]="true" - [enableRangeSelection]="true" + [cellSelection]="true" [suppressMultiRangeSelection]="true" [suppressClearOnFillReduction]="true" [enableRangeHandle]="true" diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/output.warnings.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/output.warnings.cjs index a8e8c42..7d1c51d 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/output.warnings.cjs +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/output.warnings.cjs @@ -6,7 +6,6 @@ module.exports = [ new SyntaxError('The grid option "rowMultiSelectWithClick" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/'), new SyntaxError('The grid option "groupSelectsChildren" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/'), new SyntaxError('The grid option "groupSelectsFiltered" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/'), - new SyntaxError('The grid option "enableRangeSelection" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/'), new SyntaxError('The grid option "suppressMultiRangeSelection" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/'), new SyntaxError('The grid option "suppressClearOnFillReduction" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/'), new SyntaxError('The grid option "enableRangeHandle" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/'), diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/output.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/output.js index 8926b3c..e49ed16 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/output.js +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/output.js @@ -17,13 +17,16 @@ const gridApi = createGrid(document.body, { onCellSelectionChanged: onRangeSelectionChanged, onCellSelectionDeleteStart: foo, onCellSelectionDeleteEnd: () => {}, - enableRangeSelection: cellSelection, - enableRangeHandle: isEnableRangeHandle(), - suppressCopyRowsToClipboard: true, - suppressCopySingleCellRanges: true, - selection: { + cellSelection: { suppressMultiRanges: suppressMultiRangeSelection, - suppressClearOnFillReduction: suppressClearOnFillReduction - } + + handle: { + suppressClearOnFillReduction: suppressClearOnFillReduction + } + }, + + enableRangeHandle: isEnableRangeHandle(), + suppressCopyRowsToClipboard: true, + suppressCopySingleCellRanges: true }); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/output.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/output.js index 3ae66f6..886a27e 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/output.js +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/output.js @@ -15,19 +15,18 @@ const gridApi = createGrid(document.body, { onCellSelectionChanged: onRangeSelectionChanged, onCellSelectionDeleteStart: foo, onCellSelectionDeleteEnd: () => {}, - suppressCopyRowsToClipboard: true, - suppressCopySingleCellRanges: true, - - selection: { - mode: "cell", + cellSelection: { handle: { mode: "fill", + suppressClearOnFillReduction: suppressClearOnFillReduction, direction: getFillDirection(), setFillValue: () => {console.log('filling')} }, - suppressMultiRanges: suppressMultiRangeSelection, - suppressClearOnFillReduction: suppressClearOnFillReduction - } + suppressMultiRanges: suppressMultiRangeSelection + }, + + suppressCopyRowsToClipboard: true, + suppressCopySingleCellRanges: true }); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/output.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/output.js index fd39c90..c992bad 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/output.js +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/output.js @@ -13,17 +13,16 @@ const gridApi = createGrid(document.body, { onCellSelectionChanged: onRangeSelectionChanged, onCellSelectionDeleteStart: foo, onCellSelectionDeleteEnd: () => {}, - suppressCopyRowsToClipboard: true, - suppressCopySingleCellRanges: true, - - selection: { - mode: "cell", + cellSelection: { handle: { - mode: "range" + mode: "range", + suppressClearOnFillReduction: suppressClearOnFillReduction }, - suppressMultiRanges: suppressMultiRangeSelection, - suppressClearOnFillReduction: suppressClearOnFillReduction - } + suppressMultiRanges: suppressMultiRangeSelection + }, + + suppressCopyRowsToClipboard: true, + suppressCopySingleCellRanges: true }); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/output.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/output.js index 4d2105d..50add99 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/output.js +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/output.js @@ -16,7 +16,7 @@ const gridApi = createGrid(document.body, { rowData: [], - selection: { + rowSelection: { mode: "multiRow" } }); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/output.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/output.js index 703504b..991f053 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/output.js +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/output.js @@ -13,9 +13,9 @@ const gridApi = createGrid(document.body, { suppressCopyRowsToClipboard: true, suppressCopySingleCellRanges: true, - selection: { + rowSelection: { mode: "multiRow", isRowSelectable: (params) => params.data.year < 2007, - enableMultiSelectWithClick: true + enableSelectionWithoutKeys: true } }); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.js index d5a98f5..6f37f55 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.js +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.js @@ -11,7 +11,7 @@ const gridApi = createGrid(document.body, { suppressCopyRowsToClipboard: true, suppressCopySingleCellRanges: true, - selection: { + rowSelection: { mode: "singleRow", isRowSelectable: (params) => params.data.year < 2007 } diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/output.jsx b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/output.jsx index 1b67831..3090e63 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/output.jsx +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/output.jsx @@ -17,12 +17,11 @@ function MyComponent(props) { onCellSelectionDeleteEnd={() => {}} suppressCopyRowsToClipboard={true} suppressCopySingleCellRanges={true} - selection={{ - mode: "cell", + cellSelection={{ suppressMultiRanges: suppressMultiRangeSelection, - suppressClearOnFillReduction: suppressClearOnFillReduction, handle: { + suppressClearOnFillReduction: suppressClearOnFillReduction, mode: "fill", direction: 'x', setFillValue: () => {console.log('filling')} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/output.jsx b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/output.jsx index 4618f5f..94a446e 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/output.jsx +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/output.jsx @@ -17,15 +17,13 @@ function MyComponent (props) { onCellSelectionDeleteEnd={() => {}} suppressCopyRowsToClipboard={true} suppressCopySingleCellRanges={true} - selection={{ - mode: "cell", - + cellSelection={{ handle: { - mode: "range" + mode: "range", + suppressClearOnFillReduction: suppressClearOnFillReduction }, - suppressMultiRanges: suppressMultiRangeSelection, - suppressClearOnFillReduction: suppressClearOnFillReduction + suppressMultiRanges: suppressMultiRangeSelection }} />) ); } diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/output.jsx b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/output.jsx index 4ee70ec..d416fc9 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/output.jsx +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/output.jsx @@ -14,7 +14,7 @@ function MyComponent(props) { groupSelectsFiltered suppressCopyRowsToClipboard suppressCopySingleCellRanges - selection={{ + rowSelection={{ mode: "multiRow", isRowSelectable: (params) => params.data.year < 2007, enableMultiSelectWithClick: true diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/output.jsx b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/output.jsx index 0a64b86..9c59e0e 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/output.jsx +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/output.jsx @@ -7,7 +7,6 @@ function MyComponent(props) { ( {}} onCellSelectionDeleteStart={() => {}} onCellSelectionDeleteEnd={() => {}} @@ -15,7 +14,7 @@ function MyComponent(props) { suppressRowDeselection suppressCopyRowsToClipboard suppressCopySingleCellRanges - selection={{ + rowSelection={{ isRowSelectable: (params) => params.data.year < 2007 }} />) ); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/output.jsx b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/output.jsx index f7bfc19..7c098e3 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/output.jsx +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/output.jsx @@ -12,7 +12,7 @@ function MyComponent(props) { suppressRowDeselection suppressCopyRowsToClipboard suppressCopySingleCellRanges - selection={{ + rowSelection={{ mode: "singleRow", isRowSelectable: (params) => params.data.year < 2007 }} />) diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/replacements.ts b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/replacements.ts index 6f2980c..0320419 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/replacements.ts +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/replacements.ts @@ -47,7 +47,7 @@ export const replacements: Array = transformOb onRangeDeleteEnd: migrateProperty('onCellSelectionDeleteEnd', migrateOptionalValue()), rowSelection: migrateDeepProperty( - ['selection', 'mode'], + ['rowSelection', 'mode'], transformOptionalValue(apply(transformRowSelection)), getManualInterventionMessage('rowSelection', MIGRATION_URL), ), @@ -58,12 +58,12 @@ export const replacements: Array = transformOb getManualInterventionMessage('suppressRowDeselection', MIGRATION_URL), ), isRowSelectable: migrateDeepProperty( - ['selection', 'isRowSelectable'], + ['rowSelection', 'isRowSelectable'], migrateOptionalValue(), getManualInterventionMessage('isRowSelectable', MIGRATION_URL), ), rowMultiSelectWithClick: migrateDeepProperty( - ['selection', 'enableMultiSelectWithClick'], + ['rowSelection', 'enableSelectionWithoutKeys'], migrateOptionalValue(), getManualInterventionMessage('rowMultiSelectWithClick', MIGRATION_URL), ), @@ -75,38 +75,37 @@ export const replacements: Array = transformOb getManualInterventionMessage('groupSelectsFiltered', MIGRATION_URL), ), - enableRangeSelection: migrateDeepProperty( - ['selection', 'mode'], - transformOptionalValue(apply(transformCellSelection)), - getManualInterventionMessage('enableRangeSelection', MIGRATION_URL), - ), + // Migration of this must come before all other cell selection properties. + // If no other cell selection properties are specified, + enableRangeSelection: migrateProperty('cellSelection', migrateOptionalValue()), + suppressMultiRangeSelection: migrateDeepProperty( - ['selection', 'suppressMultiRanges'], + ['cellSelection', 'suppressMultiRanges'], migrateOptionalValue(), getManualInterventionMessage('suppressMultiRangeSelection', MIGRATION_URL), ), suppressClearOnFillReduction: migrateDeepProperty( - ['selection', 'suppressClearOnFillReduction'], + ['cellSelection', 'handle', 'suppressClearOnFillReduction'], migrateOptionalValue(), getManualInterventionMessage('suppressClearOnFillReduction', MIGRATION_URL), ), enableRangeHandle: migrateDeepProperty( - ['selection', 'handle', 'mode'], + ['cellSelection', 'handle', 'mode'], transformOptionalValue(apply(transformRangeHandle)), getManualInterventionMessage('enableRangeHandle', MIGRATION_URL), ), enableFillHandle: migrateDeepProperty( - ['selection', 'handle', 'mode'], + ['cellSelection', 'handle', 'mode'], transformOptionalValue(apply(transformFillHandle)), getManualInterventionMessage('enableFillHandle', MIGRATION_URL), ), fillHandleDirection: migrateDeepProperty( - ['selection', 'handle', 'direction'], + ['cellSelection', 'handle', 'direction'], migrateOptionalValue(), getManualInterventionMessage('fillHandleDirection', MIGRATION_URL), ), fillOperation: migrateDeepProperty( - ['selection', 'handle', 'setFillValue'], + ['cellSelection', 'handle', 'setFillValue'], migrateOptionalValue(), getManualInterventionMessage('fillOperation', MIGRATION_URL), ), @@ -154,11 +153,11 @@ function transformRowSelection(value: ObjectPropertyValue): t.Expression | null } function transformCellSelection(value: ObjectPropertyValue): t.Expression | null { - if (value.isBooleanLiteral()) { - if (value.node.value) { - return ast.expression`'cell'`; - } - } + // if (value.isBooleanLiteral()) { + // if (value.node.value) { + // return ast.expression`'cell'`; + // } + // } return null; } From 7bfb465ef794960e1b98f600b9756f3266305726 Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Thu, 26 Sep 2024 16:51:02 +0100 Subject: [PATCH 2/7] wip --- .../transform-grid-options.ts | 4 ++++ .../scenarios/js/columnDefs/output.js | 2 -- .../scenarios/js/multi-row-selection/output.js | 15 ++++++++------- .../scenarios/js/single-row-selection/output.js | 11 ++++++----- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/cli/src/codemods/plugins/transform-grid-options/transform-grid-options.ts b/packages/cli/src/codemods/plugins/transform-grid-options/transform-grid-options.ts index 064158f..0438c34 100644 --- a/packages/cli/src/codemods/plugins/transform-grid-options/transform-grid-options.ts +++ b/packages/cli/src/codemods/plugins/transform-grid-options/transform-grid-options.ts @@ -795,6 +795,10 @@ export function migrateDeepProperty } } + const key = node.get('key'); + if (key.isIdentifier() && key.node.name === path[0]) { + return; + } node.remove(); }, diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/output.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/output.js index 50add99..df83656 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/output.js +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/output.js @@ -13,9 +13,7 @@ const gridApi = createGrid(document.body, { headerCheckboxSelection: true, headerCheckboxSelectionCurrentPageOnly: true, }], - rowData: [], - rowSelection: { mode: "multiRow" } diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/output.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/output.js index 991f053..d16d676 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/output.js +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/output.js @@ -6,16 +6,17 @@ const gridApi = createGrid(document.body, { onCellSelectionChanged: () => {}, onCellSelectionDeleteStart: () => {}, onCellSelectionDeleteEnd: () => {}, - suppressRowClickSelection: true, - suppressRowDeselection: true, - groupSelectsChildren: true, - groupSelectsFiltered: true, - suppressCopyRowsToClipboard: true, - suppressCopySingleCellRanges: true, rowSelection: { mode: "multiRow", isRowSelectable: (params) => params.data.year < 2007, enableSelectionWithoutKeys: true - } + }, + + suppressRowClickSelection: true, + suppressRowDeselection: true, + groupSelectsChildren: true, + groupSelectsFiltered: true, + suppressCopyRowsToClipboard: true, + suppressCopySingleCellRanges: true }); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.js index 6f37f55..cbaa1b1 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.js +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.js @@ -6,13 +6,14 @@ const gridApi = createGrid(document.body, { onCellSelectionChanged: () => {}, onCellSelectionDeleteStart: () => {}, onCellSelectionDeleteEnd: () => {}, - suppressRowClickSelection: true, - suppressRowDeselection: true, - suppressCopyRowsToClipboard: true, - suppressCopySingleCellRanges: true, rowSelection: { mode: "singleRow", isRowSelectable: (params) => params.data.year < 2007 - } + }, + + suppressRowClickSelection: true, + suppressRowDeselection: true, + suppressCopyRowsToClipboard: true, + suppressCopySingleCellRanges: true }); From 4de10757b9933e9a4b48cf59affdcd172404349a Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Thu, 26 Sep 2024 17:01:46 +0100 Subject: [PATCH 3/7] migrate enableRangeSelection, not other nested cell selection properties --- .../js/cell-selection-expressions/output.js | 14 +++---- .../output.warnings.cjs | 12 ++++-- .../replacements.ts | 41 ++++++------------- 3 files changed, 25 insertions(+), 42 deletions(-) diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/output.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/output.js index e49ed16..2eb003c 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/output.js +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/output.js @@ -18,15 +18,11 @@ const gridApi = createGrid(document.body, { onCellSelectionDeleteStart: foo, onCellSelectionDeleteEnd: () => {}, - cellSelection: { - suppressMultiRanges: suppressMultiRangeSelection, - - handle: { - suppressClearOnFillReduction: suppressClearOnFillReduction - } - }, - + cellSelection: cellSelection, enableRangeHandle: isEnableRangeHandle(), + suppressMultiRangeSelection: suppressMultiRangeSelection, + suppressClearOnFillReduction, + suppressCopyRowsToClipboard: true, - suppressCopySingleCellRanges: true + suppressCopySingleCellRanges: true, }); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/output.warnings.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/output.warnings.cjs index 1134562..23865a8 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/output.warnings.cjs +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/output.warnings.cjs @@ -1,12 +1,16 @@ module.exports = [ - new SyntaxError(`The grid option "enableRangeSelection" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ - -> | enableRangeSelection: cellSelection, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), new SyntaxError(`The grid option "enableRangeHandle" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ > | enableRangeHandle: isEnableRangeHandle(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressMultiRangeSelection" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ + +> | suppressMultiRangeSelection: suppressMultiRangeSelection, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressClearOnFillReduction" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ + +> | suppressClearOnFillReduction, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), new SyntaxError(`The grid option "suppressCopyRowsToClipboard" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ > | suppressCopyRowsToClipboard: true, diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/replacements.ts b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/replacements.ts index 0320419..7320b22 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/replacements.ts +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/replacements.ts @@ -1,4 +1,5 @@ import { + frameworkWarning, getManualInterventionMessage, isNonNullJsxPropertyValue, migrateDeepProperty, @@ -75,40 +76,22 @@ export const replacements: Array = transformOb getManualInterventionMessage('groupSelectsFiltered', MIGRATION_URL), ), - // Migration of this must come before all other cell selection properties. - // If no other cell selection properties are specified, enableRangeSelection: migrateProperty('cellSelection', migrateOptionalValue()), - suppressMultiRangeSelection: migrateDeepProperty( - ['cellSelection', 'suppressMultiRanges'], - migrateOptionalValue(), + suppressMultiRangeSelection: removeProperty( getManualInterventionMessage('suppressMultiRangeSelection', MIGRATION_URL), ), - suppressClearOnFillReduction: migrateDeepProperty( - ['cellSelection', 'handle', 'suppressClearOnFillReduction'], - migrateOptionalValue(), + suppressClearOnFillReduction: removeProperty( getManualInterventionMessage('suppressClearOnFillReduction', MIGRATION_URL), ), - enableRangeHandle: migrateDeepProperty( - ['cellSelection', 'handle', 'mode'], - transformOptionalValue(apply(transformRangeHandle)), + enableRangeHandle: removeProperty( getManualInterventionMessage('enableRangeHandle', MIGRATION_URL), ), - enableFillHandle: migrateDeepProperty( - ['cellSelection', 'handle', 'mode'], - transformOptionalValue(apply(transformFillHandle)), - getManualInterventionMessage('enableFillHandle', MIGRATION_URL), - ), - fillHandleDirection: migrateDeepProperty( - ['cellSelection', 'handle', 'direction'], - migrateOptionalValue(), + enableFillHandle: removeProperty(getManualInterventionMessage('enableFillHandle', MIGRATION_URL)), + fillHandleDirection: removeProperty( getManualInterventionMessage('fillHandleDirection', MIGRATION_URL), ), - fillOperation: migrateDeepProperty( - ['cellSelection', 'handle', 'setFillValue'], - migrateOptionalValue(), - getManualInterventionMessage('fillOperation', MIGRATION_URL), - ), + fillOperation: removeProperty(getManualInterventionMessage('fillOperation', MIGRATION_URL)), suppressCopyRowsToClipboard: removeProperty( getManualInterventionMessage('suppressCopyRowsToClipboard', MIGRATION_URL), @@ -153,11 +136,11 @@ function transformRowSelection(value: ObjectPropertyValue): t.Expression | null } function transformCellSelection(value: ObjectPropertyValue): t.Expression | null { - // if (value.isBooleanLiteral()) { - // if (value.node.value) { - // return ast.expression`'cell'`; - // } - // } + if (value.isBooleanLiteral()) { + if (value.node.value) { + return ast.expression`'cell'`; + } + } return null; } From 339a0c65f491445b240a28258792e73ae1923d9a Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Thu, 26 Sep 2024 20:06:05 +0100 Subject: [PATCH 4/7] wip --- .../scenarios/js/cell-selection/output.js | 14 +++++--------- .../js/cell-selection/output.warnings.cjs | 12 ++++++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/output.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/output.js index c992bad..0f61a4d 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/output.js +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/output.js @@ -14,15 +14,11 @@ const gridApi = createGrid(document.body, { onCellSelectionDeleteStart: foo, onCellSelectionDeleteEnd: () => {}, - cellSelection: { - handle: { - mode: "range", - suppressClearOnFillReduction: suppressClearOnFillReduction - }, - - suppressMultiRanges: suppressMultiRangeSelection - }, + cellSelection: true, + enableRangeHandle: true, + suppressMultiRangeSelection: suppressMultiRangeSelection, + suppressClearOnFillReduction, suppressCopyRowsToClipboard: true, - suppressCopySingleCellRanges: true + suppressCopySingleCellRanges: true, }); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/output.warnings.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/output.warnings.cjs index bf8e625..09336db 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/output.warnings.cjs +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/output.warnings.cjs @@ -1,4 +1,16 @@ module.exports = [ + new SyntaxError(`The grid option "enableRangeHandle" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ + +> | enableRangeHandle: true, + | ^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressMultiRangeSelection" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ + +> | suppressMultiRangeSelection: suppressMultiRangeSelection, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressClearOnFillReduction" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ + +> | suppressClearOnFillReduction, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), new SyntaxError(`The grid option "suppressCopyRowsToClipboard" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ > | suppressCopyRowsToClipboard: true, From ff33ceb58bff639e17c8d1c397172c2010a9cc26 Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Thu, 26 Sep 2024 21:15:36 +0100 Subject: [PATCH 5/7] wip --- .../js/cell-selection-fill-handle/output.js | 18 +++++++---------- .../output.warnings.cjs | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/output.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/output.js index 886a27e..0c02eb5 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/output.js +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/output.js @@ -16,17 +16,13 @@ const gridApi = createGrid(document.body, { onCellSelectionDeleteStart: foo, onCellSelectionDeleteEnd: () => {}, - cellSelection: { - handle: { - mode: "fill", - suppressClearOnFillReduction: suppressClearOnFillReduction, - direction: getFillDirection(), - setFillValue: () => {console.log('filling')} - }, - - suppressMultiRanges: suppressMultiRangeSelection - }, + cellSelection: true, + enableFillHandle: true, + suppressMultiRangeSelection: suppressMultiRangeSelection, + suppressClearOnFillReduction, + fillHandleDirection: getFillDirection(), + fillOperation: () => {console.log('filling')}, suppressCopyRowsToClipboard: true, - suppressCopySingleCellRanges: true + suppressCopySingleCellRanges: true, }); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/output.warnings.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/output.warnings.cjs index bf8e625..5159c5b 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/output.warnings.cjs +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/output.warnings.cjs @@ -1,4 +1,24 @@ module.exports = [ +new SyntaxError(`The grid option "enableFillHandle" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ + +> | enableFillHandle: true, + | ^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressMultiRangeSelection" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ + +> | suppressMultiRangeSelection: suppressMultiRangeSelection, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressClearOnFillReduction" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ + +> | suppressClearOnFillReduction, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "fillHandleDirection" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ + +> | fillHandleDirection: getFillDirection(), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "fillOperation" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ + +> | fillOperation: () => {console.log('filling')}, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), new SyntaxError(`The grid option "suppressCopyRowsToClipboard" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ > | suppressCopyRowsToClipboard: true, From abc4041c723ed8d49e30358692c4a23097fd7343 Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Thu, 26 Sep 2024 22:12:50 +0100 Subject: [PATCH 6/7] wip --- .../transform-grid-options.ts | 11 ++++++- .../jsx/cell-selection-fill-handle/output.jsx | 31 +++++++++---------- .../output.warnings.cjs | 19 ++++++++++++ .../scenarios/jsx/cell-selection/input.jsx | 2 +- .../scenarios/jsx/cell-selection/output.jsx | 15 +++++---- .../jsx/cell-selection/output.warnings.cjs | 12 +++++++ .../jsx/multi-row-selection/output.jsx | 12 +++---- 7 files changed, 69 insertions(+), 33 deletions(-) diff --git a/packages/cli/src/codemods/plugins/transform-grid-options/transform-grid-options.ts b/packages/cli/src/codemods/plugins/transform-grid-options/transform-grid-options.ts index 0438c34..175bd4b 100644 --- a/packages/cli/src/codemods/plugins/transform-grid-options/transform-grid-options.ts +++ b/packages/cli/src/codemods/plugins/transform-grid-options/transform-grid-options.ts @@ -873,7 +873,12 @@ export function migrateDeepProperty // Fish out the reference to the object expression const jsxExpressionContainer = rootSibling?.get('value'); if (!jsxExpressionContainer?.isJSXExpressionContainer()) return; - const objExp = jsxExpressionContainer.get('expression'); + let objExp = jsxExpressionContainer.get('expression'); + if (!objExp.isObjectExpression()) { + // overwrite value with a new object expression + const [transformed] = objExp.replaceWith(t.objectExpression([])); + objExp = transformed; + } if (!objExp.isObjectExpression()) return; // This loop is doing largely the same thing as the loop in the `.init` transformer: @@ -906,6 +911,10 @@ export function migrateDeepProperty } } + const key = node.get('name'); + if (key.isJSXIdentifier() && key.node.name === path[0]) { + return; + } node.remove(); }, diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/output.jsx b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/output.jsx index 3090e63..f81e18e 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/output.jsx +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/output.jsx @@ -10,22 +10,19 @@ function foo() {} function MyComponent(props) { return ( ( {}} - suppressCopyRowsToClipboard={true} - suppressCopySingleCellRanges={true} - cellSelection={{ - suppressMultiRanges: suppressMultiRangeSelection, - - handle: { - suppressClearOnFillReduction: suppressClearOnFillReduction, - mode: "fill", - direction: 'x', - setFillValue: () => {console.log('filling')} - } - }} />) + columnDefs={[]} + rowData={[]} + onCellSelectionChanged={onRangeSelectionChanged} + onCellSelectionDeleteStart={foo} + onCellSelectionDeleteEnd={() => {}} + cellSelection={true} + suppressMultiRangeSelection={suppressMultiRangeSelection} + suppressClearOnFillReduction={suppressClearOnFillReduction} + enableFillHandle={true} + fillHandleDirection={'x'} + fillOperation={() => {console.log('filling')}} + suppressCopyRowsToClipboard={true} + suppressCopySingleCellRanges={true} + />) ); } diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/output.warnings.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/output.warnings.cjs index 14a99b6..0ee682c 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/output.warnings.cjs +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/output.warnings.cjs @@ -1,4 +1,23 @@ module.exports = [ + new SyntaxError(`The grid option "suppressMultiRangeSelection" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ + +> | suppressMultiRangeSelection={suppressMultiRangeSelection} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressClearOnFillReduction" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ + +> | suppressClearOnFillReduction={suppressClearOnFillReduction} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "enableFillHandle" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ + +> | enableFillHandle={true} + | ^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "fillHandleDirection" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ + +> | fillHandleDirection={'x'} + | ^^^^^^^^^^^^^^^^^^^^^^^^^`),new SyntaxError(`The grid option "fillOperation" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ + +> | fillOperation={() => {console.log('filling')}} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), new SyntaxError(`The grid option "suppressCopyRowsToClipboard" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ > | suppressCopyRowsToClipboard={true} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/input.jsx b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/input.jsx index 4b264ef..b2338d4 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/input.jsx +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/input.jsx @@ -9,7 +9,7 @@ function foo() {} function MyComponent (props) { return ( - {}} + + cellSelection={true} + enableRangeHandle={true} + suppressMultiRangeSelection={suppressMultiRangeSelection} + suppressClearOnFillReduction={suppressClearOnFillReduction} + suppressCopyRowsToClipboard={true} suppressCopySingleCellRanges={true} - cellSelection={{ - handle: { - mode: "range", - suppressClearOnFillReduction: suppressClearOnFillReduction - }, - - suppressMultiRanges: suppressMultiRangeSelection - }} />) + />) ); } diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/output.warnings.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/output.warnings.cjs index 14a99b6..4f3ad18 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/output.warnings.cjs +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/output.warnings.cjs @@ -1,4 +1,16 @@ module.exports = [ + new SyntaxError(`The grid option "enableRangeHandle" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ + +> | enableRangeHandle={true} + | ^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressMultiRangeSelection" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ + +> | suppressMultiRangeSelection={suppressMultiRangeSelection} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressClearOnFillReduction" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ + +> | suppressClearOnFillReduction={suppressClearOnFillReduction} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), new SyntaxError(`The grid option "suppressCopyRowsToClipboard" cannot be automatically migrated. Please refer to the migration guide for more details: https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/ > | suppressCopyRowsToClipboard={true} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/output.jsx b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/output.jsx index d416fc9..6efcbc8 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/output.jsx +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/output.jsx @@ -5,6 +5,11 @@ function MyComponent(props) { ( params.data.year < 2007, + enableSelectionWithoutKeys: true + }} onCellSelectionChanged={() => {}} onCellSelectionDeleteStart={() => {}} onCellSelectionDeleteEnd={() => {}} @@ -13,11 +18,6 @@ function MyComponent(props) { groupSelectsChildren groupSelectsFiltered suppressCopyRowsToClipboard - suppressCopySingleCellRanges - rowSelection={{ - mode: "multiRow", - isRowSelectable: (params) => params.data.year < 2007, - enableMultiSelectWithClick: true - }} />) + suppressCopySingleCellRanges />) ); } From ec596cbec6ac8f636708fbed0bc1ebfda44ad846 Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Thu, 26 Sep 2024 22:44:41 +0100 Subject: [PATCH 7/7] wip --- .../transform-grid-options.ts | 22 ++++++++++++++----- .../output.jsx | 8 +++---- .../jsx/single-row-selection/output.jsx | 10 ++++----- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/packages/cli/src/codemods/plugins/transform-grid-options/transform-grid-options.ts b/packages/cli/src/codemods/plugins/transform-grid-options/transform-grid-options.ts index 175bd4b..058699b 100644 --- a/packages/cli/src/codemods/plugins/transform-grid-options/transform-grid-options.ts +++ b/packages/cli/src/codemods/plugins/transform-grid-options/transform-grid-options.ts @@ -871,13 +871,23 @@ export function migrateDeepProperty if (!rootSibling) return; // Fish out the reference to the object expression - const jsxExpressionContainer = rootSibling?.get('value'); - if (!jsxExpressionContainer?.isJSXExpressionContainer()) return; - let objExp = jsxExpressionContainer.get('expression'); - if (!objExp.isObjectExpression()) { + const jsxAttributeValue = rootSibling?.get('value'); + let objExp: NodePath; + if (jsxAttributeValue?.isJSXExpressionContainer()) { + objExp = jsxAttributeValue.get('expression'); + if (!objExp.isObjectExpression()) { + // overwrite value with a new object expression + const [transformed] = objExp.replaceWith(t.objectExpression([])); + objExp = transformed; + } + } else if (jsxAttributeValue?.isStringLiteral()) { // overwrite value with a new object expression - const [transformed] = objExp.replaceWith(t.objectExpression([])); - objExp = transformed; + const [transformed] = jsxAttributeValue.replaceWith( + t.jsxExpressionContainer(t.objectExpression([])), + ); + objExp = transformed.get('expression'); + } else { + return; } if (!objExp.isObjectExpression()) return; diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/output.jsx b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/output.jsx index 9c59e0e..6960bdd 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/output.jsx +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/output.jsx @@ -7,15 +7,15 @@ function MyComponent(props) { ( params.data.year < 2007 + }} onCellSelectionChanged={() => {}} onCellSelectionDeleteStart={() => {}} onCellSelectionDeleteEnd={() => {}} suppressRowClickSelection suppressRowDeselection suppressCopyRowsToClipboard - suppressCopySingleCellRanges - rowSelection={{ - isRowSelectable: (params) => params.data.year < 2007 - }} />) + suppressCopySingleCellRanges />) ); } diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/output.jsx b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/output.jsx index 7c098e3..a3e7c1c 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/output.jsx +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/output.jsx @@ -5,16 +5,16 @@ function MyComponent(props) { ( params.data.year < 2007 + }} onCellSelectionChanged={() => {}} onCellSelectionDeleteStart={() => {}} onCellSelectionDeleteEnd={() => {}} suppressRowClickSelection suppressRowDeselection suppressCopyRowsToClipboard - suppressCopySingleCellRanges - rowSelection={{ - mode: "singleRow", - isRowSelectable: (params) => params.data.year < 2007 - }} />) + suppressCopySingleCellRanges />) ); }