diff --git a/packages/cli/package.json b/packages/cli/package.json index af31e6db..c926762e 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@ag-grid-devtools/cli", - "version": "32.0.7", + "version": "32.2.0", "license": "MIT", "description": "AG Grid developer toolkit", "author": "AG Grid ", diff --git a/packages/cli/src/codemods/lib.test.ts b/packages/cli/src/codemods/lib.test.ts index 50bd1a7d..898ee48f 100644 --- a/packages/cli/src/codemods/lib.test.ts +++ b/packages/cli/src/codemods/lib.test.ts @@ -2,7 +2,7 @@ import { expect, test } from 'vitest'; import * as lib from './lib'; -const versions: Array = ['31.0.0', '31.1.0', '31.2.0', '31.3.0', '32.0.0']; +const versions: Array = ['31.0.0', '31.1.0', '31.2.0', '31.3.0', '32.0.0', '32.2.0']; test('module exports', () => { expect({ ...lib }).toEqual({ diff --git a/packages/cli/src/codemods/plugins/transform-grid-api-methods/plugin.json b/packages/cli/src/codemods/plugins/transform-grid-api-methods/plugin.json index 422bef93..257805ac 100644 --- a/packages/cli/src/codemods/plugins/transform-grid-api-methods/plugin.json +++ b/packages/cli/src/codemods/plugins/transform-grid-api-methods/plugin.json @@ -1,5 +1,4 @@ { "name": "Transform Grid API methods", - "description": "Transform deprecated Grid API method invocations", - "template": "../../../templates/plugin-transform-grid-api-methods" + "description": "Transform deprecated Grid API method invocations" } diff --git a/packages/cli/src/codemods/plugins/transform-grid-options/plugin.json b/packages/cli/src/codemods/plugins/transform-grid-options/plugin.json index 0d68a64b..306bd4d6 100644 --- a/packages/cli/src/codemods/plugins/transform-grid-options/plugin.json +++ b/packages/cli/src/codemods/plugins/transform-grid-options/plugin.json @@ -1,5 +1,4 @@ { "name": "Transform Grid options", - "description": "Transform deprecated Grid options", - "template": "../../../templates/plugin-transform-grid-options" + "description": "Transform deprecated Grid options" } 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 8550925c..53a5c69d 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 @@ -60,7 +60,6 @@ type JSXIdentifier = Types.JSXIdentifier; type JSXNamespacedName = Types.JSXNamespacedName; type Literal = Types.Literal; type MemberExpression = Types.MemberExpression; -type OptionalMemberExpression = Types.OptionalMemberExpression; type ObjectExpression = Types.ObjectExpression; type ObjectMethod = Types.ObjectMethod; type ObjectProperty = Types.ObjectProperty; @@ -727,6 +726,229 @@ export function migrateProperty>( return transformer; } +/** + * Migrate a property into a nested object. For example `gridOptions.rowSelection` -> `gridOptions.selection.mode`. + * + * If the target object doesn't exist, it will be created. + * + * Note that a lot of the early returns in the transformers are to do with type narrowing; we don't expect those code paths + * to be triggered normally. + * + * @param path Ordered field names specifying the path in the target object + * @param transform Transformation to apply to the original value + * @param deprecationWarning Deprecation warning to print for unsupported transformations (e.g. Angular) + * @returns Object property transformer + */ +export function migrateDeepProperty>( + path: string[], + transform: ObjectPropertyValueTransformer, + deprecationWarning?: string, +): ObjectPropertyTransformer { + if (path.length === 1) { + return migrateProperty(path[0], transform); + } + + const transformer: ObjectPropertyTransformer = { + init(node, context) { + if (node.shouldSkip) return; + node.skip(); + + if (!node.parentPath.isObjectExpression()) return; + + // Start off at the root node, where the target object should be defined + let rootNode = node.parentPath; + + const value = node.get('value'); + if (Array.isArray(value) || !value.isExpression()) return; + const accessor = createStaticPropertyKey(t.identifier(path[path.length - 1]), false); + const updatedValue = transform.property(value, accessor, context); + if (updatedValue == null) { + deprecationWarning && context.opts.warn(node, deprecationWarning); + return; + } + + // Step through the target path, either finding an existing field by that name, + // or creating an object property if one doesn't exist + for (let i = 0; i < path.length; i++) { + const part = path[i]; + const rootAccessor = { key: t.identifier(part), computed: false }; + let initializer = findSiblingPropertyInitializer(rootNode, rootAccessor); + if (!initializer) { + initializer = createSiblingPropertyInitializer(rootNode, rootAccessor); + } + if (!initializer) return; + const newObj = initializer.get('value'); + if (!newObj.isObjectExpression()) return; + rootNode = newObj; + + // On the final path part, apply the transformation and set the value + if (i === path.length - 1) { + rewriteObjectPropertyInitializer(initializer, rootAccessor, updatedValue); + } + } + + node.remove(); + }, + + get(node, context) { + if (node.shouldSkip) return; + node.skip(); + + deprecationWarning && context.opts.warn(node, deprecationWarning); + }, + + set(node, context) { + if (node.shouldSkip) return; + node.skip(); + + deprecationWarning && context.opts.warn(node, deprecationWarning); + }, + + angularAttribute(attributeNode, component, element, context) { + deprecationWarning && context.opts.warn(null, deprecationWarning); + }, + + jsxAttribute(node, element, context) { + if (node.shouldSkip) return; + node.skip(); + + // Parent should be the JSX element + if (!node.parentPath.isJSXOpeningElement()) return; + const root = node.parentPath; + + // Compute the transformed value of the property ahead of time + let value: NodePath = + node.get('value'); + // A null value for the JSXAttribute is an implicit truthy value + // (e.g. ) + if (isNullNodePath(value)) { + const [transformed] = value.replaceWith(t.jsxExpressionContainer(t.booleanLiteral(true))); + value = transformed; + } + // When getting the value to set at the inner-most level of the object, + // we'll need to extract it from the expression container + if (value.isJSXExpressionContainer()) { + const innerExpression = value.get('expression'); + // Shouldn't be possible to encounter an empty expression here + if (innerExpression.isJSXEmptyExpression()) return; + value = innerExpression as NodePath; + } + // At this point, after the above clauses, we know `value` can only be `NodePath` + let updatedValue = transform.jsxAttribute( + value as NodePath, + element, + node, + context, + ); + if (!updatedValue || updatedValue === true || t.isJSXEmptyExpression(updatedValue)) { + deprecationWarning && context.opts.warn(node, deprecationWarning); + return; + } + + // Find or create the root attribute of the target object, injecting + // an empty object expression into the expression container + let rootSibling = root + .get('attributes') + .find( + (att): att is NodePath => + att.isJSXAttribute() && att.get('name').node.name === path[0], + ); + if (!rootSibling) { + rootSibling = createJSXSiblingAttribute(root, path[0]); + } + if (!rootSibling) return; + + // Fish out the reference to the object expression + const jsxExpressionContainer = rootSibling?.get('value'); + if (!jsxExpressionContainer?.isJSXExpressionContainer()) return; + const objExp = jsxExpressionContainer.get('expression'); + if (!objExp.isObjectExpression()) return; + + // This loop is doing largely the same thing as the loop in the `.init` transformer: + // stepping through the path, either finding or creating the target field and setting the + // transformed value on the final step + let rootNode = objExp; + for (let i = 1; i < path.length; i++) { + const part = path[i]; + const accessor = { key: t.identifier(part), computed: false }; + let initializer = findSiblingPropertyInitializer(rootNode, accessor); + if (!initializer) { + initializer = createSiblingPropertyInitializer(rootNode, accessor); + } + if (!initializer) return; + const newObj = initializer.get('value'); + if (!newObj.isObjectExpression()) return; + rootNode = newObj; + + // On the final path part, apply the transformation and set the value + if (i === path.length - 1) { + rewriteObjectPropertyInitializer(initializer, accessor, updatedValue); + } + } + + node.remove(); + }, + + vueAttribute(templateNode, component, element, context) { + deprecationWarning && context.opts.warn(null, deprecationWarning); + }, + }; + + return transformer; +} + +function isNullNodePath(x: NodePath): x is NodePath { + return x.node == null; +} + +function createJSXSiblingAttribute( + root: NodePath, + name: string, +): NodePath | undefined { + const newAttribute = t.jsxAttribute( + t.jsxIdentifier(name), + t.jsxExpressionContainer(t.objectExpression([])), + ); + const [transformed] = root.replaceWith( + t.jSXOpeningElement(root.get('name').node, root.node.attributes.concat(newAttribute), true), + ); + + const wrappedNewAttribute = transformed + .get('attributes') + .find( + (attr): attr is NodePath => + attr.isJSXAttribute() && attr.get('name').node.name === name, + ); + + return wrappedNewAttribute; +} + +function createSiblingPropertyInitializer( + objExp: NodePath, + accessor: PropertyAccessor, +) { + const prop = t.objectProperty(accessor.key, t.objectExpression([])); + const [newPath] = objExp.replaceWith(t.objectExpression(objExp.node.properties.concat(prop))); + return newPath + .get('properties') + .find( + (p): p is NodePath => p.isObjectProperty() && p.node.key === accessor.key, + ); +} + +function findSiblingPropertyInitializer( + objExp: NodePath, + accessor: PropertyAccessor, +): NodePath | undefined { + return objExp + .get('properties') + .filter((p): p is NodePath => t.isObjectProperty(p.node)) + .find((p) => { + const existingAccessor = parseObjectPropertyInitializerAccessor(p); + return existingAccessor ? arePropertyAccessorsEqual(accessor, existingAccessor) : false; + }); +} + export function removeProperty( deprecationWarning: string, ): ObjectPropertyTransformer> { @@ -981,8 +1203,7 @@ function getPropertyInitializerValue( ): NodePath | null { if (property.isObjectProperty()) { const value = property.get('value'); - if (value.isExpression()) return value; - return null; + return value.isExpression() ? value : null; } else if (property.isObjectMethod()) { return property; } else { @@ -994,13 +1215,10 @@ function renameObjectProperty( property: NodePath, targetAccessor: PropertyAccessor, ): NodePath { - if ( - property.node.key === targetAccessor.key && - property.node.computed === targetAccessor.computed - ) { + const { node } = property; + if (node.key === targetAccessor.key && node.computed === targetAccessor.computed) { return property; } - const { node } = property; const value = t.isObjectMethod(node) ? node : t.isExpression(node.value) ? node.value : null; if (!value) return property; return rewriteObjectPropertyInitializer(property, targetAccessor, value); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v31-2/replacements.ts b/packages/cli/src/codemods/transforms/transform-grid-options-v31-2/replacements.ts index 93d00533..20957a17 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v31-2/replacements.ts +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v31-2/replacements.ts @@ -8,7 +8,6 @@ import { transformOptionalValue, transformPropertyValue, type CodemodObjectPropertyReplacement, - getDeprecationMessage, } from '../../plugins/transform-grid-options/transform-grid-options'; const MIGRATION_URL = 'https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-31-2/'; diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/README.md b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/README.md new file mode 100644 index 00000000..5215c144 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/README.md @@ -0,0 +1,27 @@ +# `transform-grid-options-v32-2` + +> _Transform deprecated Grid options_ + +See the [`transform-grid-options`](../../plugins/transform-grid-options/) plugin for usage instructions. + +## Common tasks + +### Add a test case + +Create a new unit test scenario for this transform: + +``` +pnpm run task:create-test --type transform --target transform-grid-options-v32-2 +``` + +### Add a new rule + +Replacement rules are specified in [`replacements.ts`](./replacements.ts) + +### Add to a codemod release + +Add this source code transformation to a codemod release: + +``` +pnpm run task:include-transform --transform transform-grid-options-v32-2 +``` diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/input.component.ts b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/input.component.ts new file mode 100644 index 00000000..b7ce35b9 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/input.component.ts @@ -0,0 +1,50 @@ +// @ts-nocheck +import { AdvancedFilterModel, ColDef, ColGroupDef, GridReadyEvent } from '@ag-grid-community/core'; +import { AgGridAngular } from '@ag-grid-community/angular'; +import { HttpClient } from '@angular/common/http'; +import { Component, ViewChild } from '@angular/core'; +import { IOlympicData } from './interfaces'; + +@Component({ + selector: 'my-app', + template: `
+ +
`, +}) +export class AppComponent { + @ViewChild(AgGridAngular) private grid!: AgGridAngular; + public columnDefs: (ColDef | ColGroupDef)[] = []; + public rowData!: IOlympicData[]; + + constructor(private http: HttpClient) { + } + + onGridReady(params: GridReadyEvent) { + this.http + .get('https://www.ag-grid.com/example-assets/olympic-winners.json') + .subscribe((data) => { + this.rowData = data; + console.log("Hello, world!"); + }); + } +} 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 new file mode 100644 index 00000000..b7ce35b9 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/output.component.ts @@ -0,0 +1,50 @@ +// @ts-nocheck +import { AdvancedFilterModel, ColDef, ColGroupDef, GridReadyEvent } from '@ag-grid-community/core'; +import { AgGridAngular } from '@ag-grid-community/angular'; +import { HttpClient } from '@angular/common/http'; +import { Component, ViewChild } from '@angular/core'; +import { IOlympicData } from './interfaces'; + +@Component({ + selector: 'my-app', + template: `
+ +
`, +}) +export class AppComponent { + @ViewChild(AgGridAngular) private grid!: AgGridAngular; + public columnDefs: (ColDef | ColGroupDef)[] = []; + public rowData!: IOlympicData[]; + + constructor(private http: HttpClient) { + } + + onGridReady(params: GridReadyEvent) { + this.http + .get('https://www.ag-grid.com/example-assets/olympic-winners.json') + .subscribe((data) => { + this.rowData = data; + console.log("Hello, world!"); + }); + } +} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/output.errors.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/output.errors.cjs new file mode 100644 index 00000000..e0a30c5d --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/output.errors.cjs @@ -0,0 +1 @@ +module.exports = []; 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 new file mode 100644 index 00000000..a8e8c426 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/output.warnings.cjs @@ -0,0 +1,18 @@ +module.exports = [ + new SyntaxError('The grid option "rowSelection" 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 "suppressRowClickSelection" 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 "suppressRowDeselection" 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 "isRowSelectable" 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 "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/'), + 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/'), + 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/'), + 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/'), + 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/'), + new SyntaxError('The grid option "suppressCopySingleCellRanges" 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/angular/warnings/scenario.json b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/scenario.json new file mode 100644 index 00000000..c31eff9c --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/scenario.json @@ -0,0 +1,8 @@ +{ + "scenario": { + "input": "input.component.ts", + "output": "output.component.ts", + "errors": "output.errors.cjs", + "warnings": "output.warnings.cjs" + } +} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/input.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/input.js new file mode 100644 index 00000000..addf57dd --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/input.js @@ -0,0 +1,28 @@ +import { createGrid } from '@ag-grid-community/core'; + +const suppressMultiRangeSelection = true; +const suppressClearOnFillReduction = true; + +function onRangeSelectionChanged() {} + +function foo() {} + +const cellSelection = false; + +function isEnableRangeHandle() {} + +const gridApi = createGrid(document.body, { + columnDefs: [], + rowData: [], + onRangeSelectionChanged, + onRangeDeleteStart: foo, + onRangeDeleteEnd: () => {}, + + enableRangeSelection: cellSelection, + enableRangeHandle: isEnableRangeHandle(), + suppressMultiRangeSelection: suppressMultiRangeSelection, + suppressClearOnFillReduction, + + suppressCopyRowsToClipboard: true, + suppressCopySingleCellRanges: true, +}); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/output.errors.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/output.errors.cjs new file mode 100644 index 00000000..e0a30c5d --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/output.errors.cjs @@ -0,0 +1 @@ +module.exports = []; 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 new file mode 100644 index 00000000..8926b3c1 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/output.js @@ -0,0 +1,29 @@ +import { createGrid } from '@ag-grid-community/core'; + +const suppressMultiRangeSelection = true; +const suppressClearOnFillReduction = true; + +function onRangeSelectionChanged() {} + +function foo() {} + +const cellSelection = false; + +function isEnableRangeHandle() {} + +const gridApi = createGrid(document.body, { + columnDefs: [], + rowData: [], + onCellSelectionChanged: onRangeSelectionChanged, + onCellSelectionDeleteStart: foo, + onCellSelectionDeleteEnd: () => {}, + enableRangeSelection: cellSelection, + enableRangeHandle: isEnableRangeHandle(), + suppressCopyRowsToClipboard: true, + suppressCopySingleCellRanges: true, + + selection: { + suppressMultiRanges: suppressMultiRangeSelection, + suppressClearOnFillReduction: suppressClearOnFillReduction + } +}); 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 new file mode 100644 index 00000000..11345620 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/output.warnings.cjs @@ -0,0 +1,18 @@ +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 "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, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressCopySingleCellRanges" 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/ + +> | suppressCopySingleCellRanges: true, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), +]; diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/scenario.json b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/scenario.json new file mode 100644 index 00000000..346c1107 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/scenario.json @@ -0,0 +1,8 @@ +{ + "scenario": { + "input": "input.js", + "output": "output.js", + "errors": "output.errors.cjs", + "warnings": "output.warnings.cjs" + } +} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/input.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/input.js new file mode 100644 index 00000000..fa1980b8 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/input.js @@ -0,0 +1,28 @@ +import { createGrid } from '@ag-grid-community/core'; + +const suppressMultiRangeSelection = true; +const suppressClearOnFillReduction = true; + +function onRangeSelectionChanged() {} + +function foo() {} + +function getFillDirection() {} + +const gridApi = createGrid(document.body, { + columnDefs: [], + rowData: [], + onRangeSelectionChanged, + onRangeDeleteStart: foo, + onRangeDeleteEnd: () => {}, + + enableRangeSelection: true, + enableFillHandle: true, + suppressMultiRangeSelection: suppressMultiRangeSelection, + suppressClearOnFillReduction, + fillHandleDirection: getFillDirection(), + fillOperation: () => {console.log('filling')}, + + 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.errors.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/output.errors.cjs new file mode 100644 index 00000000..e0a30c5d --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/output.errors.cjs @@ -0,0 +1 @@ +module.exports = []; 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 new file mode 100644 index 00000000..3ae66f64 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/output.js @@ -0,0 +1,33 @@ +import { createGrid } from '@ag-grid-community/core'; + +const suppressMultiRangeSelection = true; +const suppressClearOnFillReduction = true; + +function onRangeSelectionChanged() {} + +function foo() {} + +function getFillDirection() {} + +const gridApi = createGrid(document.body, { + columnDefs: [], + rowData: [], + onCellSelectionChanged: onRangeSelectionChanged, + onCellSelectionDeleteStart: foo, + onCellSelectionDeleteEnd: () => {}, + suppressCopyRowsToClipboard: true, + suppressCopySingleCellRanges: true, + + selection: { + mode: "cell", + + handle: { + mode: "fill", + direction: getFillDirection(), + setFillValue: () => {console.log('filling')} + }, + + suppressMultiRanges: suppressMultiRangeSelection, + suppressClearOnFillReduction: suppressClearOnFillReduction + } +}); 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 new file mode 100644 index 00000000..bf8e625c --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/output.warnings.cjs @@ -0,0 +1,10 @@ +module.exports = [ + 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, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressCopySingleCellRanges" 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/ + +> | suppressCopySingleCellRanges: true, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), +]; diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/scenario.json b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/scenario.json new file mode 100644 index 00000000..346c1107 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/scenario.json @@ -0,0 +1,8 @@ +{ + "scenario": { + "input": "input.js", + "output": "output.js", + "errors": "output.errors.cjs", + "warnings": "output.warnings.cjs" + } +} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/input.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/input.js new file mode 100644 index 00000000..5c75bb4b --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/input.js @@ -0,0 +1,24 @@ +import { createGrid } from '@ag-grid-community/core'; + +const suppressMultiRangeSelection = true; +const suppressClearOnFillReduction = true; + +function onRangeSelectionChanged() {} + +function foo() {} + +const gridApi = createGrid(document.body, { + columnDefs: [], + rowData: [], + onRangeSelectionChanged, + onRangeDeleteStart: foo, + onRangeDeleteEnd: () => {}, + + enableRangeSelection: true, + enableRangeHandle: true, + suppressMultiRangeSelection: suppressMultiRangeSelection, + suppressClearOnFillReduction, + + suppressCopyRowsToClipboard: true, + suppressCopySingleCellRanges: true, +}); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/output.errors.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/output.errors.cjs new file mode 100644 index 00000000..e0a30c5d --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/output.errors.cjs @@ -0,0 +1 @@ +module.exports = []; 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 new file mode 100644 index 00000000..fd39c90f --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/output.js @@ -0,0 +1,29 @@ +import { createGrid } from '@ag-grid-community/core'; + +const suppressMultiRangeSelection = true; +const suppressClearOnFillReduction = true; + +function onRangeSelectionChanged() {} + +function foo() {} + +const gridApi = createGrid(document.body, { + columnDefs: [], + rowData: [], + onCellSelectionChanged: onRangeSelectionChanged, + onCellSelectionDeleteStart: foo, + onCellSelectionDeleteEnd: () => {}, + suppressCopyRowsToClipboard: true, + suppressCopySingleCellRanges: true, + + selection: { + mode: "cell", + + handle: { + mode: "range" + }, + + suppressMultiRanges: suppressMultiRangeSelection, + suppressClearOnFillReduction: suppressClearOnFillReduction + } +}); 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 new file mode 100644 index 00000000..bf8e625c --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/output.warnings.cjs @@ -0,0 +1,10 @@ +module.exports = [ + 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, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressCopySingleCellRanges" 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/ + +> | suppressCopySingleCellRanges: true, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), +]; diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/scenario.json b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/scenario.json new file mode 100644 index 00000000..346c1107 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/scenario.json @@ -0,0 +1,8 @@ +{ + "scenario": { + "input": "input.js", + "output": "output.js", + "errors": "output.errors.cjs", + "warnings": "output.warnings.cjs" + } +} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/input.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/input.js new file mode 100644 index 00000000..f925d227 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/input.js @@ -0,0 +1,18 @@ +import { createGrid } from '@ag-grid-community/core'; + +const gridApi = createGrid(document.body, { + columnDefs: [{ + field: 'sport', + checkboxSelection: true, + headerCheckboxSelection: true, + headerCheckboxSelectionFilteredOnly: true, + }, + { + field: 'year', + checkboxSelection: () => false, + headerCheckboxSelection: true, + headerCheckboxSelectionCurrentPageOnly: true, + }], + rowData: [], + rowSelection: 'multiple' +}); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/output.errors.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/output.errors.cjs new file mode 100644 index 00000000..e0a30c5d --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/output.errors.cjs @@ -0,0 +1 @@ +module.exports = []; 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 new file mode 100644 index 00000000..4d2105d3 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/output.js @@ -0,0 +1,22 @@ +import { createGrid } from '@ag-grid-community/core'; + +const gridApi = createGrid(document.body, { + columnDefs: [{ + field: 'sport', + checkboxSelection: true, + headerCheckboxSelection: true, + headerCheckboxSelectionFilteredOnly: true, + }, + { + field: 'year', + checkboxSelection: () => false, + headerCheckboxSelection: true, + headerCheckboxSelectionCurrentPageOnly: true, + }], + + rowData: [], + + selection: { + mode: "multiRow" + } +}); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/output.warnings.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/output.warnings.cjs new file mode 100644 index 00000000..2ad31f42 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/output.warnings.cjs @@ -0,0 +1,26 @@ +module.exports = [ + new SyntaxError(`The grid option "checkboxSelection" 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/ + +> | checkboxSelection: true, + | ^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "headerCheckboxSelection" 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/ + +> | headerCheckboxSelection: true, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "headerCheckboxSelectionFilteredOnly" 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/ + +> | headerCheckboxSelectionFilteredOnly: true, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "checkboxSelection" 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/ + +> | checkboxSelection: () => false, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "headerCheckboxSelection" 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/ + +> | headerCheckboxSelection: true, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "headerCheckboxSelectionCurrentPageOnly" 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/ + +> | headerCheckboxSelectionCurrentPageOnly: true, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), +]; diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/scenario.json b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/scenario.json new file mode 100644 index 00000000..346c1107 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/scenario.json @@ -0,0 +1,8 @@ +{ + "scenario": { + "input": "input.js", + "output": "output.js", + "errors": "output.errors.cjs", + "warnings": "output.warnings.cjs" + } +} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/input.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/input.js new file mode 100644 index 00000000..5cae2a02 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/input.js @@ -0,0 +1,20 @@ +import { createGrid } from '@ag-grid-community/core'; + +const gridApi = createGrid(document.body, { + columnDefs: [], + rowData: [], + onRangeSelectionChanged: () => {}, + onRangeDeleteStart: () => {}, + onRangeDeleteEnd: () => {}, + + rowSelection: 'multiple', + suppressRowClickSelection: true, + suppressRowDeselection: true, + isRowSelectable: (params) => params.data.year < 2007, + rowMultiSelectWithClick: 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/multi-row-selection/output.errors.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/output.errors.cjs new file mode 100644 index 00000000..e0a30c5d --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/output.errors.cjs @@ -0,0 +1 @@ +module.exports = []; 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 new file mode 100644 index 00000000..703504b0 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/output.js @@ -0,0 +1,21 @@ +import { createGrid } from '@ag-grid-community/core'; + +const gridApi = createGrid(document.body, { + columnDefs: [], + rowData: [], + onCellSelectionChanged: () => {}, + onCellSelectionDeleteStart: () => {}, + onCellSelectionDeleteEnd: () => {}, + suppressRowClickSelection: true, + suppressRowDeselection: true, + groupSelectsChildren: true, + groupSelectsFiltered: true, + suppressCopyRowsToClipboard: true, + suppressCopySingleCellRanges: true, + + selection: { + 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/js/multi-row-selection/output.warnings.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/output.warnings.cjs new file mode 100644 index 00000000..fd363eeb --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/output.warnings.cjs @@ -0,0 +1,26 @@ +module.exports = [ + new SyntaxError(`The grid option "suppressRowClickSelection" 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/ + +> | suppressRowClickSelection: true, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressRowDeselection" 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/ + +> | suppressRowDeselection: true, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + 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/ + +> | groupSelectsChildren: true, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^`), + 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/ + +> | groupSelectsFiltered: true, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^`), + 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, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressCopySingleCellRanges" 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/ + +> | suppressCopySingleCellRanges: true, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), +]; diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/scenario.json b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/scenario.json new file mode 100644 index 00000000..346c1107 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/scenario.json @@ -0,0 +1,8 @@ +{ + "scenario": { + "input": "input.js", + "output": "output.js", + "errors": "output.errors.cjs", + "warnings": "output.warnings.cjs" + } +} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/input.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/input.js new file mode 100644 index 00000000..7b9dfba8 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/input.js @@ -0,0 +1,17 @@ +import { createGrid } from '@ag-grid-community/core'; + +const gridApi = createGrid(document.body, { + columnDefs: [], + rowData: [], + onRangeSelectionChanged: () => {}, + onRangeDeleteStart: () => {}, + onRangeDeleteEnd: () => {}, + + rowSelection: 'single', + suppressRowClickSelection: true, + suppressRowDeselection: true, + isRowSelectable: (params) => params.data.year < 2007, + + suppressCopyRowsToClipboard: true, + suppressCopySingleCellRanges: true, +}); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.errors.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.errors.cjs new file mode 100644 index 00000000..e0a30c5d --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.errors.cjs @@ -0,0 +1 @@ +module.exports = []; 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 new file mode 100644 index 00000000..d5a98f59 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.js @@ -0,0 +1,18 @@ +import { createGrid } from '@ag-grid-community/core'; + +const gridApi = createGrid(document.body, { + columnDefs: [], + rowData: [], + onCellSelectionChanged: () => {}, + onCellSelectionDeleteStart: () => {}, + onCellSelectionDeleteEnd: () => {}, + suppressRowClickSelection: true, + suppressRowDeselection: true, + suppressCopyRowsToClipboard: true, + suppressCopySingleCellRanges: true, + + selection: { + mode: "singleRow", + isRowSelectable: (params) => params.data.year < 2007 + } +}); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.warnings.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.warnings.cjs new file mode 100644 index 00000000..ce6f30f1 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.warnings.cjs @@ -0,0 +1,18 @@ +module.exports = [ + new SyntaxError(`The grid option "suppressRowClickSelection" 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/ + +> | suppressRowClickSelection: true, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressRowDeselection" 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/ + +> | suppressRowDeselection: true, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + 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, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressCopySingleCellRanges" 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/ + +> | suppressCopySingleCellRanges: true, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), +]; diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/scenario.json b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/scenario.json new file mode 100644 index 00000000..346c1107 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/scenario.json @@ -0,0 +1,8 @@ +{ + "scenario": { + "input": "input.js", + "output": "output.js", + "errors": "output.errors.cjs", + "warnings": "output.warnings.cjs" + } +} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/input.jsx b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/input.jsx new file mode 100644 index 00000000..0c09a642 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/input.jsx @@ -0,0 +1,28 @@ +import { AgGridReact } from '@ag-grid-community/react'; + +const suppressMultiRangeSelection = true; +const suppressClearOnFillReduction = true; + +function onRangeSelectionChanged() {} + +function foo() {} + +function MyComponent(props) { + return ( + ( {}} + enableRangeSelection={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.errors.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/output.errors.cjs new file mode 100644 index 00000000..e0a30c5d --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/output.errors.cjs @@ -0,0 +1 @@ +module.exports = []; 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 new file mode 100644 index 00000000..1b67831d --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/output.jsx @@ -0,0 +1,32 @@ +import { AgGridReact } from '@ag-grid-community/react'; + +const suppressMultiRangeSelection = true; +const suppressClearOnFillReduction = true; + +function onRangeSelectionChanged() {} + +function foo() {} + +function MyComponent(props) { + return ( + ( {}} + suppressCopyRowsToClipboard={true} + suppressCopySingleCellRanges={true} + selection={{ + mode: "cell", + suppressMultiRanges: suppressMultiRangeSelection, + suppressClearOnFillReduction: suppressClearOnFillReduction, + + handle: { + 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-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 new file mode 100644 index 00000000..14a99b61 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/output.warnings.cjs @@ -0,0 +1,10 @@ +module.exports = [ + 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} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressCopySingleCellRanges" 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/ + +> | suppressCopySingleCellRanges={true} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), +]; diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/scenario.json b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/scenario.json new file mode 100644 index 00000000..28038495 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/scenario.json @@ -0,0 +1,8 @@ +{ + "scenario": { + "input": "input.jsx", + "output": "output.jsx", + "errors": "output.errors.cjs", + "warnings": "output.warnings.cjs" + } +} 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 new file mode 100644 index 00000000..4b264ef2 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/input.jsx @@ -0,0 +1,28 @@ +import { AgGridReact } from '@ag-grid-community/react'; + +const suppressMultiRangeSelection = true; +const suppressClearOnFillReduction = true; + +function onRangeSelectionChanged() {} + +function foo() {} + +function MyComponent (props) { + return ( + {}} + + enableRangeSelection={true} + enableRangeHandle={true} + suppressMultiRangeSelection={suppressMultiRangeSelection} + suppressClearOnFillReduction={suppressClearOnFillReduction} + + suppressCopyRowsToClipboard={true} + suppressCopySingleCellRanges={true} + /> + ) +} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/output.errors.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/output.errors.cjs new file mode 100644 index 00000000..e0a30c5d --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/output.errors.cjs @@ -0,0 +1 @@ +module.exports = []; 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 new file mode 100644 index 00000000..4618f5f0 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/output.jsx @@ -0,0 +1,31 @@ +import { AgGridReact } from '@ag-grid-community/react'; + +const suppressMultiRangeSelection = true; +const suppressClearOnFillReduction = true; + +function onRangeSelectionChanged() {} + +function foo() {} + +function MyComponent (props) { + return ( + ( {}} + suppressCopyRowsToClipboard={true} + suppressCopySingleCellRanges={true} + selection={{ + mode: "cell", + + handle: { + mode: "range" + }, + + suppressMultiRanges: suppressMultiRangeSelection, + suppressClearOnFillReduction: suppressClearOnFillReduction + }} />) + ); +} 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 new file mode 100644 index 00000000..14a99b61 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/output.warnings.cjs @@ -0,0 +1,10 @@ +module.exports = [ + 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} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressCopySingleCellRanges" 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/ + +> | suppressCopySingleCellRanges={true} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), +]; diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/scenario.json b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/scenario.json new file mode 100644 index 00000000..28038495 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/scenario.json @@ -0,0 +1,8 @@ +{ + "scenario": { + "input": "input.jsx", + "output": "output.jsx", + "errors": "output.errors.cjs", + "warnings": "output.warnings.cjs" + } +} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/input.jsx b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/input.jsx new file mode 100644 index 00000000..effd6ee3 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/input.jsx @@ -0,0 +1,26 @@ +import { AgGridReact } from '@ag-grid-community/react'; + +function MyComponent(props) { + return ( + {}} + onRangeDeleteStart={() => {}} + onRangeDeleteEnd={() => {}} + + suppressRowClickSelection + suppressRowDeselection + isRowSelectable={(params) => params.data.year < 2007} + rowMultiSelectWithClick + groupSelectsChildren + groupSelectsFiltered + + suppressCopyRowsToClipboard + suppressCopySingleCellRanges + /> + ); +} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/output.errors.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/output.errors.cjs new file mode 100644 index 00000000..e0a30c5d --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/output.errors.cjs @@ -0,0 +1 @@ +module.exports = []; 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 new file mode 100644 index 00000000..4ee70ece --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/output.jsx @@ -0,0 +1,23 @@ +import { AgGridReact } from '@ag-grid-community/react'; + +function MyComponent(props) { + return ( + ( {}} + onCellSelectionDeleteStart={() => {}} + onCellSelectionDeleteEnd={() => {}} + suppressRowClickSelection + suppressRowDeselection + groupSelectsChildren + groupSelectsFiltered + suppressCopyRowsToClipboard + suppressCopySingleCellRanges + selection={{ + 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/multi-row-selection/output.warnings.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/output.warnings.cjs new file mode 100644 index 00000000..2e44844d --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/output.warnings.cjs @@ -0,0 +1,26 @@ +module.exports = [ + new SyntaxError(`The grid option "suppressRowClickSelection" 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/ + +> | suppressRowClickSelection + | ^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressRowDeselection" 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/ + +> | suppressRowDeselection + | ^^^^^^^^^^^^^^^^^^^^^^`), + 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/ + +> | groupSelectsChildren + | ^^^^^^^^^^^^^^^^^^^^`), + 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/ + +> | groupSelectsFiltered + | ^^^^^^^^^^^^^^^^^^^^`), + 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 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressCopySingleCellRanges" 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/ + +> | suppressCopySingleCellRanges + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), +]; diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/scenario.json b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/scenario.json new file mode 100644 index 00000000..28038495 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/scenario.json @@ -0,0 +1,8 @@ +{ + "scenario": { + "input": "input.jsx", + "output": "output.jsx", + "errors": "output.errors.cjs", + "warnings": "output.warnings.cjs" + } +} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/input.jsx b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/input.jsx new file mode 100644 index 00000000..1bd07b31 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/input.jsx @@ -0,0 +1,25 @@ +import { AgGridReact } from '@ag-grid-community/react'; + +function MyComponent(props) { + const [selectionState, setSelectionState] = useState("single"); + + return ( + {}} + onRangeDeleteStart={() => {}} + onRangeDeleteEnd={() => {}} + + suppressRowClickSelection + suppressRowDeselection + isRowSelectable={(params) => params.data.year < 2007} + + suppressCopyRowsToClipboard + suppressCopySingleCellRanges + /> + ); +} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/output.errors.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/output.errors.cjs new file mode 100644 index 00000000..e0a30c5d --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/output.errors.cjs @@ -0,0 +1 @@ +module.exports = []; 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 new file mode 100644 index 00000000..0a64b86c --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/output.jsx @@ -0,0 +1,22 @@ +import { AgGridReact } from '@ag-grid-community/react'; + +function MyComponent(props) { + const [selectionState, setSelectionState] = useState("single"); + + return ( + ( {}} + onCellSelectionDeleteStart={() => {}} + onCellSelectionDeleteEnd={() => {}} + suppressRowClickSelection + suppressRowDeselection + suppressCopyRowsToClipboard + suppressCopySingleCellRanges + selection={{ + 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-expressions/output.warnings.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/output.warnings.cjs new file mode 100644 index 00000000..a699d352 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/output.warnings.cjs @@ -0,0 +1,22 @@ +module.exports = [ + new SyntaxError(`The grid option "rowSelection" 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/ + +> | rowSelection={selectionState} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressRowClickSelection" 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/ + +> | suppressRowClickSelection + | ^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressRowDeselection" 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/ + +> | suppressRowDeselection + | ^^^^^^^^^^^^^^^^^^^^^^`), + 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 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressCopySingleCellRanges" 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/ + +> | suppressCopySingleCellRanges + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), +]; diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/scenario.json b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/scenario.json new file mode 100644 index 00000000..28038495 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/scenario.json @@ -0,0 +1,8 @@ +{ + "scenario": { + "input": "input.jsx", + "output": "output.jsx", + "errors": "output.errors.cjs", + "warnings": "output.warnings.cjs" + } +} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/input.jsx b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/input.jsx new file mode 100644 index 00000000..e4081a26 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/input.jsx @@ -0,0 +1,23 @@ +import { AgGridReact } from '@ag-grid-community/react'; + +function MyComponent(props) { + return ( + {}} + onRangeDeleteStart={() => {}} + onRangeDeleteEnd={() => {}} + + suppressRowClickSelection + suppressRowDeselection + isRowSelectable={(params) => params.data.year < 2007} + + suppressCopyRowsToClipboard + suppressCopySingleCellRanges + /> + ); +} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/output.errors.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/output.errors.cjs new file mode 100644 index 00000000..e0a30c5d --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/output.errors.cjs @@ -0,0 +1 @@ +module.exports = []; 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 new file mode 100644 index 00000000..f7bfc198 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/output.jsx @@ -0,0 +1,20 @@ +import { AgGridReact } from '@ag-grid-community/react'; + +function MyComponent(props) { + return ( + ( {}} + onCellSelectionDeleteStart={() => {}} + onCellSelectionDeleteEnd={() => {}} + suppressRowClickSelection + suppressRowDeselection + suppressCopyRowsToClipboard + suppressCopySingleCellRanges + selection={{ + mode: "singleRow", + 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.warnings.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/output.warnings.cjs new file mode 100644 index 00000000..c3ac9d42 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/output.warnings.cjs @@ -0,0 +1,18 @@ +module.exports = [ + new SyntaxError(`The grid option "suppressRowClickSelection" 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/ + +> | suppressRowClickSelection + | ^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressRowDeselection" 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/ + +> | suppressRowDeselection + | ^^^^^^^^^^^^^^^^^^^^^^`), + 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 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^`), + new SyntaxError(`The grid option "suppressCopySingleCellRanges" 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/ + +> | suppressCopySingleCellRanges + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^`), +]; diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/scenario.json b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/scenario.json new file mode 100644 index 00000000..28038495 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/scenario.json @@ -0,0 +1,8 @@ +{ + "scenario": { + "input": "input.jsx", + "output": "output.jsx", + "errors": "output.errors.cjs", + "warnings": "output.warnings.cjs" + } +} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/index.ts b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/index.ts new file mode 100644 index 00000000..49f62dcd --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/index.ts @@ -0,0 +1 @@ +export { default } from './transform-grid-options-v32-2'; diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/manifest.ts b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/manifest.ts new file mode 100644 index 00000000..98dd550d --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/manifest.ts @@ -0,0 +1,8 @@ +import { type TransformManifest } from '@ag-grid-devtools/types'; + +const manifest: TransformManifest = { + name: 'Transform Grid options v32.2', + description: 'Transform deprecated Grid options', +}; + +export default manifest; 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 new file mode 100644 index 00000000..6f2980c1 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/replacements.ts @@ -0,0 +1,184 @@ +import { + getManualInterventionMessage, + isNonNullJsxPropertyValue, + migrateDeepProperty, + migrateOptionalValue, + migrateProperty, + ObjectPropertyValue, + ObjectPropertyValueTransformer, + removeProperty, + transformObjectListValue, + transformObjectProperties, + transformOptionalValue, + transformPropertyValue, + type CodemodObjectPropertyReplacement, +} from '../../plugins/transform-grid-options/transform-grid-options'; +import { ast, AstCliContext, AstTransformContext, Types as t } from '@ag-grid-devtools/ast'; + +const MIGRATION_URL = 'https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/'; + +export const replacements: Array = transformObjectProperties({ + columnDefs: transformPropertyValue( + transformOptionalValue( + transformObjectListValue( + transformObjectProperties({ + checkboxSelection: removeProperty( + getManualInterventionMessage('checkboxSelection', MIGRATION_URL), + ), + headerCheckboxSelection: removeProperty( + getManualInterventionMessage('headerCheckboxSelection', MIGRATION_URL), + ), + headerCheckboxSelectionCurrentPageOnly: removeProperty( + getManualInterventionMessage('headerCheckboxSelectionCurrentPageOnly', MIGRATION_URL), + ), + headerCheckboxSelectionFilteredOnly: removeProperty( + getManualInterventionMessage('headerCheckboxSelectionFilteredOnly', MIGRATION_URL), + ), + showDisabledCheckboxes: removeProperty( + getManualInterventionMessage('showDisabledCheckboxes', MIGRATION_URL), + ), + }), + ), + ), + ), + + onRangeSelectionChanged: migrateProperty('onCellSelectionChanged', migrateOptionalValue()), + onRangeDeleteStart: migrateProperty('onCellSelectionDeleteStart', migrateOptionalValue()), + onRangeDeleteEnd: migrateProperty('onCellSelectionDeleteEnd', migrateOptionalValue()), + + rowSelection: migrateDeepProperty( + ['selection', 'mode'], + transformOptionalValue(apply(transformRowSelection)), + getManualInterventionMessage('rowSelection', MIGRATION_URL), + ), + suppressRowClickSelection: removeProperty( + getManualInterventionMessage('suppressRowClickSelection', MIGRATION_URL), + ), + suppressRowDeselection: removeProperty( + getManualInterventionMessage('suppressRowDeselection', MIGRATION_URL), + ), + isRowSelectable: migrateDeepProperty( + ['selection', 'isRowSelectable'], + migrateOptionalValue(), + getManualInterventionMessage('isRowSelectable', MIGRATION_URL), + ), + rowMultiSelectWithClick: migrateDeepProperty( + ['selection', 'enableMultiSelectWithClick'], + migrateOptionalValue(), + getManualInterventionMessage('rowMultiSelectWithClick', MIGRATION_URL), + ), + + groupSelectsChildren: removeProperty( + getManualInterventionMessage('groupSelectsChildren', MIGRATION_URL), + ), + groupSelectsFiltered: removeProperty( + getManualInterventionMessage('groupSelectsFiltered', MIGRATION_URL), + ), + + enableRangeSelection: migrateDeepProperty( + ['selection', 'mode'], + transformOptionalValue(apply(transformCellSelection)), + getManualInterventionMessage('enableRangeSelection', MIGRATION_URL), + ), + suppressMultiRangeSelection: migrateDeepProperty( + ['selection', 'suppressMultiRanges'], + migrateOptionalValue(), + getManualInterventionMessage('suppressMultiRangeSelection', MIGRATION_URL), + ), + suppressClearOnFillReduction: migrateDeepProperty( + ['selection', 'suppressClearOnFillReduction'], + migrateOptionalValue(), + getManualInterventionMessage('suppressClearOnFillReduction', MIGRATION_URL), + ), + enableRangeHandle: migrateDeepProperty( + ['selection', 'handle', 'mode'], + transformOptionalValue(apply(transformRangeHandle)), + getManualInterventionMessage('enableRangeHandle', MIGRATION_URL), + ), + enableFillHandle: migrateDeepProperty( + ['selection', 'handle', 'mode'], + transformOptionalValue(apply(transformFillHandle)), + getManualInterventionMessage('enableFillHandle', MIGRATION_URL), + ), + fillHandleDirection: migrateDeepProperty( + ['selection', 'handle', 'direction'], + migrateOptionalValue(), + getManualInterventionMessage('fillHandleDirection', MIGRATION_URL), + ), + fillOperation: migrateDeepProperty( + ['selection', 'handle', 'setFillValue'], + migrateOptionalValue(), + getManualInterventionMessage('fillOperation', MIGRATION_URL), + ), + + suppressCopyRowsToClipboard: removeProperty( + getManualInterventionMessage('suppressCopyRowsToClipboard', MIGRATION_URL), + ), + suppressCopySingleCellRanges: removeProperty( + getManualInterventionMessage('suppressCopySingleCellRanges', MIGRATION_URL), + ), +}); + +function transformFillHandle(value: ObjectPropertyValue): t.Expression | null { + if (value.isBooleanLiteral()) { + if (value.node.value) { + return ast.expression`'fill'`; + } + } + + return null; +} + +function transformRangeHandle(value: ObjectPropertyValue): t.Expression | null { + if (value.isBooleanLiteral()) { + if (value.node.value) { + return ast.expression`'range'`; + } + } + return null; +} + +function transformRowSelection(value: ObjectPropertyValue): t.Expression | null { + if (value.isStringLiteral()) { + switch (value.node.value) { + case 'single': + return ast.expression`'singleRow'`; + case 'multiple': + return ast.expression`'multiRow'`; + default: + break; + } + } + + return null; +} + +function transformCellSelection(value: ObjectPropertyValue): t.Expression | null { + if (value.isBooleanLiteral()) { + if (value.node.value) { + return ast.expression`'cell'`; + } + } + + return null; +} + +function apply>( + transform: (v: ObjectPropertyValue) => t.Expression | null, +): ObjectPropertyValueTransformer { + return { + property(value, accessor, context) { + return transform(value); + }, + jsxAttribute(value, element, attribute, context) { + if (!isNonNullJsxPropertyValue(value)) return null; + return transform(value); + }, + angularAttribute(value, component, element, attribute, context) { + return value; + }, + vueAttribute(value, component, element, attribute, context) { + return value === true ? value : value.node; + }, + }; +} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/transform-grid-options-v32-2.test.ts b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/transform-grid-options-v32-2.test.ts new file mode 100644 index 00000000..b2136ccc --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/transform-grid-options-v32-2.test.ts @@ -0,0 +1,16 @@ +import { dirname, join } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { describe, expect, onTestFinished, test } from 'vitest'; +import { loadTransformScenarios } from '../../test/runners/transform'; + +import transformGridOptionsV32_2 from './transform-grid-options-v32-2'; + +const __dirname = dirname(fileURLToPath(import.meta.url)); + +describe(transformGridOptionsV32_2, () => { + const scenariosPath = join(__dirname, './__fixtures__/scenarios'); + loadTransformScenarios(scenariosPath, { + transforms: [transformGridOptionsV32_2], + vitest: { describe, expect, test, onTestFinished }, + }); +}); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/transform-grid-options-v32-2.ts b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/transform-grid-options-v32-2.ts new file mode 100644 index 00000000..5edf929c --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/transform-grid-options-v32-2.ts @@ -0,0 +1,11 @@ +import { type AstCliContext, type AstTransform } from '@ag-grid-devtools/ast'; +import { transformGridOptions } from '../../plugins/transform-grid-options'; +import { replacements } from './replacements'; + +const plugin: AstTransform = transformGridOptions(replacements); + +const transform: AstTransform = function transformGridOptionsV32_2(babel) { + return plugin(babel); +}; + +export default transform; diff --git a/packages/cli/src/codemods/versions/32.2.0/manifest.ts b/packages/cli/src/codemods/versions/32.2.0/manifest.ts index c1dfcf04..493f6263 100644 --- a/packages/cli/src/codemods/versions/32.2.0/manifest.ts +++ b/packages/cli/src/codemods/versions/32.2.0/manifest.ts @@ -2,7 +2,12 @@ import { type TransformManifest, type VersionManifest } from '@ag-grid-devtools/ import transformGridApiMethodsV32_2 from '../../transforms/transform-grid-api-methods-v32-2/manifest.ts'; -const transforms: Array = [transformGridApiMethodsV32_2]; +import transformGridOptionsV32_2 from '../../transforms/transform-grid-options-v32-2/manifest.ts'; + +const transforms: Array = [ + transformGridApiMethodsV32_2, + transformGridOptionsV32_2, +]; const manifest: VersionManifest = { version: '32.2.0', diff --git a/packages/cli/src/codemods/versions/32.2.0/transforms.ts b/packages/cli/src/codemods/versions/32.2.0/transforms.ts index 11cd0bae..89162cfd 100644 --- a/packages/cli/src/codemods/versions/32.2.0/transforms.ts +++ b/packages/cli/src/codemods/versions/32.2.0/transforms.ts @@ -2,6 +2,11 @@ import { type AstCliContext, type AstTransform } from '@ag-grid-devtools/ast'; import transformGridApiMethodsV32_2 from '../../transforms/transform-grid-api-methods-v32-2'; -const transforms: Array> = [transformGridApiMethodsV32_2]; +import transformGridOptionsV32_2 from '../../transforms/transform-grid-options-v32-2'; + +const transforms: Array> = [ + transformGridApiMethodsV32_2, + transformGridOptionsV32_2, +]; export default transforms; diff --git a/packages/cli/src/codemods/versions/manifest.ts b/packages/cli/src/codemods/versions/manifest.ts index eb67a34e..88e7c83d 100644 --- a/packages/cli/src/codemods/versions/manifest.ts +++ b/packages/cli/src/codemods/versions/manifest.ts @@ -10,6 +10,8 @@ import v31_3_0 from './31.3.0/manifest'; import v32_0_0 from './32.0.0/manifest'; -const versions: Array = [v31_0_0, v31_1_0, v31_2_0, v31_3_0, v32_0_0]; +import v32_2_0 from './32.2.0/manifest'; + +const versions: Array = [v31_0_0, v31_1_0, v31_2_0, v31_3_0, v32_0_0, v32_2_0]; export default versions; diff --git a/packages/codemods-tasks/tasks/create-transform.mjs b/packages/codemods-tasks/tasks/create-transform.mjs index 0b45183d..a7bfcd0c 100644 --- a/packages/codemods-tasks/tasks/create-transform.mjs +++ b/packages/codemods-tasks/tasks/create-transform.mjs @@ -22,7 +22,8 @@ import { } from './src/version.mjs'; const __dirname = dirname(new URL(import.meta.url).pathname); -const TEMPLATE_DIR = join(__dirname, '../templates/create-transform'); +const TEMPLATES_DIR = join(__dirname, '..', 'templates'); +const TEMPLATE_DIR = join(TEMPLATES_DIR, 'create-transform'); const PROJECT_PLUGINS_DIR = './plugins'; const PROJECT_TRANSFORMS_DIR = './transforms'; @@ -155,8 +156,8 @@ const VARIABLES = [ export default async function task(...args) { const variables = await prompt(VARIABLES, { args, input: stdin, output: stderr }); if (!variables) throw null; - const { outputPath, filename, identifier, pluginsDir, plugin, versionsDir, release } = variables; - const pluginTemplate = plugin ? getPluginTemplatePath({ pluginsDir, plugin }) : null; + const { outputPath, filename, identifier, plugin, versionsDir, release } = variables; + const pluginTemplate = plugin ? getPluginTemplatePath(plugin) : null; const templateDir = pluginTemplate ?? TEMPLATE_DIR; await copyTemplateDirectory(templateDir, outputPath, variables); if (release) { @@ -225,10 +226,8 @@ function loadPluginManifest({ plugin, pluginsDir }) { return JSON.parse(readFileSync(pluginManifestPath, 'utf-8')); } -function getPluginTemplatePath({ pluginsDir, plugin }) { - const pluginPath = join(pluginsDir, plugin); - const { template } = loadPluginManifest({ plugin, pluginsDir }); - return join(pluginPath, template); +function getPluginTemplatePath(plugin) { + return join(TEMPLATES_DIR, `plugin-${plugin}`); } function isValidTransformName(value) {