From 591677cd8744e096f9dc2bc91840fc24a237bfcd Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Wed, 21 Aug 2024 14:51:23 +0100 Subject: [PATCH 01/15] fix create-transform task --- .../plugins/transform-grid-api-methods/plugin.json | 3 +-- .../plugins/transform-grid-options/plugin.json | 3 +-- packages/codemods-tasks/tasks/create-transform.mjs | 13 ++++++------- 3 files changed, 8 insertions(+), 11 deletions(-) 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/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) { From b35d6fe30c84499c8f878d47552d257c0432fc81 Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Wed, 4 Sep 2024 16:36:52 +0100 Subject: [PATCH 02/15] add grid options codemod for v32.2 --- package.json | 3 ++- .../transform-grid-options-v32-2/README.md | 27 +++++++++++++++++++ .../scenarios/js/hello-world/input.js | 9 +++++++ .../js/hello-world/output.errors.cjs | 1 + .../scenarios/js/hello-world/output.js | 8 ++++++ .../js/hello-world/output.warnings.cjs | 1 + .../scenarios/js/hello-world/scenario.json | 8 ++++++ .../transform-grid-options-v32-2/index.ts | 1 + .../transform-grid-options-v32-2/manifest.ts | 8 ++++++ .../replacements.ts | 17 ++++++++++++ .../transform-grid-options-v32-2.test.ts | 16 +++++++++++ .../transform-grid-options-v32-2.ts | 11 ++++++++ .../src/codemods/versions/32.2.0/manifest.ts | 7 ++++- .../codemods/versions/32.2.0/transforms.ts | 7 ++++- 14 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/README.md create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/input.js create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/output.errors.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/output.js create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/output.warnings.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/scenario.json create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/index.ts create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/manifest.ts create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/replacements.ts create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/transform-grid-options-v32-2.test.ts create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/transform-grid-options-v32-2.ts diff --git a/package.json b/package.json index 2d7b94de..02e4fdbb 100644 --- a/package.json +++ b/package.json @@ -43,5 +43,6 @@ "vite": "5.4.1", "vitest": "1.6.0", "@vitest/coverage-v8": "1.6.0" - } + }, + "packageManager": "pnpm@9.7.0+sha512.dc09430156b427f5ecfc79888899e1c39d2d690f004be70e05230b72cb173d96839587545d09429b55ac3c429c801b4dc3c0e002f653830a420fa2dd4e3cf9cf" } 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/js/hello-world/input.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/input.js new file mode 100644 index 00000000..d9d59b54 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/input.js @@ -0,0 +1,9 @@ +import { createGrid } from '@ag-grid-community/core'; + +const gridApi = createGrid(document.body, { + columnDefs: [], + rowData: [], + hello: 'world', + goodbye: 'world', + friendly: true, +}); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/output.errors.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/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/hello-world/output.errors.cjs @@ -0,0 +1 @@ +module.exports = []; diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/output.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/output.js new file mode 100644 index 00000000..d0c30ca4 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/output.js @@ -0,0 +1,8 @@ +import { createGrid } from '@ag-grid-community/core'; + +const gridApi = createGrid(document.body, { + columnDefs: [], + rowData: [], + greet: 'world', + unfriendly: false +}); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/output.warnings.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/output.warnings.cjs new file mode 100644 index 00000000..e0a30c5d --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/output.warnings.cjs @@ -0,0 +1 @@ +module.exports = []; diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/scenario.json b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/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/hello-world/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/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..3c767942 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/replacements.ts @@ -0,0 +1,17 @@ +import { + getDeprecationMessage, + invertOptionalBooleanValue, + migrateOptionalValue, + migrateProperty, + removeProperty, + transformObjectProperties, + type CodemodObjectPropertyReplacement, +} from '../../plugins/transform-grid-options/transform-grid-options'; + +const MIGRATION_URL = 'https://ag-grid.com/javascript-data-grid/upgrading-to-ag-grid-32-2/'; + +export const replacements: Array = transformObjectProperties({ + hello: migrateProperty('greet', migrateOptionalValue()), + goodbye: removeProperty(getDeprecationMessage('goodbye', MIGRATION_URL)), + friendly: migrateProperty('unfriendly', invertOptionalBooleanValue()), +}); 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; From 6bafed6b3309f8bb1a999c99bd6962e3e1f6788e Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Thu, 12 Sep 2024 09:35:04 +0100 Subject: [PATCH 03/15] fix simple js test --- .../transform-grid-options.ts | 88 +++++++++++++- .../scenarios/js/hello-world/input.js | 9 -- .../scenarios/js/hello-world/output.js | 8 -- .../js/single-row-selection/input.js | 13 +++ .../output.errors.cjs | 0 .../js/single-row-selection/output.js | 15 +++ .../output.warnings.cjs | 0 .../scenario.json | 0 .../replacements.ts | 110 +++++++++++++++++- 9 files changed, 219 insertions(+), 24 deletions(-) delete mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/input.js delete mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/output.js create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/input.js rename packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/{hello-world => single-row-selection}/output.errors.cjs (100%) create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.js rename packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/{hello-world => single-row-selection}/output.warnings.cjs (100%) rename packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/{hello-world => single-row-selection}/scenario.json (100%) 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..9aa52404 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,93 @@ export function migrateProperty>( return transformer; } +export function migrateDeepProperty>( + path: string[], + transform: ObjectPropertyValueTransformer, +): ObjectPropertyTransformer { + if (path.length === 1) { + return migrateProperty(path[0], transform); + } + + const transformer: ObjectPropertyTransformer = { + init(node, context) { + if (node.shouldSkip) { + return; + } + node.skip(); + + // find or create sibling root prop + // recurse into prop with find or create + // at lowest level, add transformed value to properties + if (!node.parentPath.isObjectExpression()) return; + let rootNode = node.parentPath; + 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; + if (i === path.length - 1) { + const accessor = createStaticPropertyKey(rootAccessor.key, rootAccessor.computed); + const value = node.get('value'); + if (Array.isArray(value)) return; + const updatedValue = transform.property( + value as NodePath, + accessor!, + context, + )!; + rewriteObjectPropertyInitializer(initializer, rootAccessor, updatedValue); + } + } + + node.remove(); + }, + + get(node, context) {}, + + set(node, context) {}, + + angularAttribute(attributeNode, component, element, context) {}, + + jsxAttribute(node, element, context) {}, + + vueAttribute(templateNode, component, element, context) {}, + }; + + return transformer; +} + +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.isObjectProperty() && p.node.key === accessor.key) as + | NodePath + | undefined; +} + +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> { diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/input.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/input.js deleted file mode 100644 index d9d59b54..00000000 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/input.js +++ /dev/null @@ -1,9 +0,0 @@ -import { createGrid } from '@ag-grid-community/core'; - -const gridApi = createGrid(document.body, { - columnDefs: [], - rowData: [], - hello: 'world', - goodbye: 'world', - friendly: true, -}); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/output.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/output.js deleted file mode 100644 index d0c30ca4..00000000 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/output.js +++ /dev/null @@ -1,8 +0,0 @@ -import { createGrid } from '@ag-grid-community/core'; - -const gridApi = createGrid(document.body, { - columnDefs: [], - rowData: [], - greet: 'world', - unfriendly: false -}); 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..ec44ae48 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/input.js @@ -0,0 +1,13 @@ +import { createGrid } from '@ag-grid-community/core'; + +const gridApi = createGrid(document.body, { + columnDefs: [], + rowData: [], + onRangeSelectionChanged: () => {}, + onRangeDeleteStart: () => {}, + onRangeDeleteEnd: () => {}, + + rowSelection: 'single', + suppressRowClickSelection: true, + isRowSelectable: (params) => params.data.year < 2007, +}); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/output.errors.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.errors.cjs similarity index 100% rename from packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/output.errors.cjs rename to packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.errors.cjs 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..5cfdb218 --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.js @@ -0,0 +1,15 @@ +import { createGrid } from '@ag-grid-community/core'; + +const gridApi = createGrid(document.body, { + columnDefs: [], + rowData: [], + onCellSelectionChanged: () => {}, + onCellSelectionDeleteStart: () => {}, + onCellSelectionDeleteEnd: () => {}, + + selection: { + mode: "singleRow", + suppressClickSelection: true, + isRowSelectable: (params) => params.data.year < 2007 + } +}); diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/output.warnings.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.warnings.cjs similarity index 100% rename from packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/output.warnings.cjs rename to packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.warnings.cjs diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/scenario.json b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/scenario.json similarity index 100% rename from packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/hello-world/scenario.json rename to packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/scenario.json 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 3c767942..d4bab62c 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,17 +1,115 @@ import { - getDeprecationMessage, - invertOptionalBooleanValue, + migrateDeepProperty, migrateOptionalValue, migrateProperty, - removeProperty, + ObjectPropertyValue, + ObjectPropertyValueTransformer, transformObjectProperties, + transformOptionalValue, type CodemodObjectPropertyReplacement, } from '../../plugins/transform-grid-options/transform-grid-options'; +import { ast, AstCliContext, AstTransformContext, Types } 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({ - hello: migrateProperty('greet', migrateOptionalValue()), - goodbye: removeProperty(getDeprecationMessage('goodbye', MIGRATION_URL)), - friendly: migrateProperty('unfriendly', invertOptionalBooleanValue()), + onRangeSelectionChanged: migrateProperty('onCellSelectionChanged', migrateOptionalValue()), + onRangeDeleteStart: migrateProperty('onCellSelectionDeleteStart', migrateOptionalValue()), + onRangeDeleteEnd: migrateProperty('onCellSelectionDeleteEnd', migrateOptionalValue()), + + rowSelection: migrateDeepProperty( + ['selection', 'mode'], + transformOptionalValue(tf(transformRowSelection)), + ), + suppressRowClickSelection: migrateDeepProperty( + ['selection', 'suppressClickSelection'], + migrateOptionalValue(), + ), + isRowSelectable: migrateDeepProperty(['selection', 'isRowSelectable'], migrateOptionalValue()), + rowMultiSelectWithClick: migrateDeepProperty( + ['selection', 'enableMultiSelectWithClick'], + migrateOptionalValue(), + ), + + enableRangeSelection: migrateDeepProperty( + ['selection', 'mode'], + transformOptionalValue(tf(transformCellSelection)), + ), + suppressMultiRangeSelection: migrateDeepProperty( + ['selection', 'suppressMultiRanges'], + migrateOptionalValue(), + ), + suppressClearOnFillReduction: migrateDeepProperty( + ['selection', 'suppressClearOnFillReduction'], + migrateOptionalValue(), + ), + enableRangeHandle: migrateDeepProperty(['selection', 'handle'], migrateOptionalValue()), + enableFillHandle: migrateDeepProperty( + ['selection', 'handle', 'mode'], + transformOptionalValue(tf(transformFillHandle)), + ), + fillHandleDirection: migrateDeepProperty( + ['selection', 'handle', 'direction'], + migrateOptionalValue(), + ), }); + +function transformFillHandle(value: ObjectPropertyValue): Types.Expression { + if (value.isBooleanLiteral()) { + switch (value.node.value) { + case true: + return ast.expression`'fill'`; + default: + break; + } + } + + return ast.expression`undefined`; +} + +function transformRowSelection(value: ObjectPropertyValue): Types.Expression { + if (value.isStringLiteral()) { + switch (value.node.value) { + case 'single': + return ast.expression`'singleRow'`; + case 'multiple': + return ast.expression`'multiRow'`; + default: + break; + } + } + + return ast.expression`undefined`; +} + +function transformCellSelection(value: ObjectPropertyValue): Types.Expression { + if (value.isBooleanLiteral()) { + switch (value.node.value) { + case true: + return ast.expression`'cell'`; + default: + break; + } + } + + return ast.expression`undefined`; +} + +function tf>( + tff: (v: ObjectPropertyValue) => Types.Expression, +): ObjectPropertyValueTransformer { + return { + property(value, accessor, context) { + return tff(value); + }, + jsxAttribute(value, element, attribute, context) { + return value === true ? value : value.node; + }, + angularAttribute(value, component, element, attribute, context) { + return value; + }, + vueAttribute(value, component, element, attribute, context) { + return value === true ? value : value.node; + }, + }; +} From 40f2ca3fd17fb6d5806c2223cc0200224070ea62 Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Fri, 13 Sep 2024 17:04:49 +0100 Subject: [PATCH 04/15] wip --- .../transform-grid-options.ts | 48 +++++++++++++++---- .../scenarios/jsx/single-row-select/input.jsx | 15 ++++++ .../jsx/single-row-select/output.errors.cjs | 1 + .../jsx/single-row-select/output.jsx | 19 ++++++++ .../jsx/single-row-select/output.warnings.cjs | 1 + .../jsx/single-row-select/scenario.json | 8 ++++ 6 files changed, 84 insertions(+), 8 deletions(-) create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/input.jsx create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/output.errors.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/output.jsx create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/output.warnings.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/scenario.json 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 9aa52404..9d9e206c 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 @@ -779,7 +779,41 @@ export function migrateDeepProperty angularAttribute(attributeNode, component, element, context) {}, - jsxAttribute(node, element, context) {}, + jsxAttribute(node, element, context) { + if (node.shouldSkip) return; + node.skip(); + + if (!node.parentPath.isJSXOpeningElement()) return; + const root = node.parentPath; + + const rootSibling = root.get('attributes').find((att): att is NodePath => { + return att.isJSXAttribute() && att.get('name').node.name === path[0]; + }); + + const jsxExpressionContainer = rootSibling?.get('value'); + if (!jsxExpressionContainer?.isJSXExpressionContainer()) return; + const objExp = jsxExpressionContainer.get('expression'); + if (!objExp.isObjectExpression()) return; + + 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; + if (i === path.length - 1) { + const staticKey = createStaticPropertyKey(accessor.key, accessor.computed); + const value = node.get('value'); + transform.jsxAttribute(value); + } + } + }, vueAttribute(templateNode, component, element, context) {}, }; @@ -787,6 +821,8 @@ export function migrateDeepProperty return transformer; } +function findJSXSiblingAttribute(); + function createSiblingPropertyInitializer( objExp: NodePath, accessor: PropertyAccessor, @@ -1067,8 +1103,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 { @@ -1080,13 +1115,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-v32-2/__fixtures__/scenarios/jsx/single-row-select/input.jsx b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/input.jsx new file mode 100644 index 00000000..71c2dc4e --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/input.jsx @@ -0,0 +1,15 @@ +import { AgGridReact } from '@ag-grid-community/react'; + +function MyComponent(props) { + const onRangeSelectionChanged = useCallback(() => {}, []); + + return ( + + ); +} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/output.errors.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/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-select/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-select/output.jsx b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/output.jsx new file mode 100644 index 00000000..4821974c --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/output.jsx @@ -0,0 +1,19 @@ +import { AgGridReact } from '@ag-grid-community/react'; + +function MyComponent(props) { + const onRangeSelectionChanged = useCallback(() => {}, []); + + const selection = useMemo(() => ({ + mode: 'singleRow', + suppressClickSelection: true, + }), []); + + return ( + () + ); +} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/output.warnings.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/output.warnings.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-select/output.warnings.cjs @@ -0,0 +1 @@ +module.exports = []; diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/scenario.json b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/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-select/scenario.json @@ -0,0 +1,8 @@ +{ + "scenario": { + "input": "input.jsx", + "output": "output.jsx", + "errors": "output.errors.cjs", + "warnings": "output.warnings.cjs" + } +} From 82425ee26c194dbe5a3475e0103d3470d22fd8d7 Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Tue, 17 Sep 2024 16:36:26 +0100 Subject: [PATCH 05/15] codemods for selection properties --- .../transform-grid-options.ts | 51 +++++++++-- .../replacements.ts | 1 - .../replacements.ts | 86 +++++++++++++------ 3 files changed, 108 insertions(+), 30 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 9d9e206c..d8212ecc 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 @@ -786,9 +786,13 @@ export function migrateDeepProperty if (!node.parentPath.isJSXOpeningElement()) return; const root = node.parentPath; - const rootSibling = root.get('attributes').find((att): att is NodePath => { + let rootSibling = root.get('attributes').find((att): att is NodePath => { return att.isJSXAttribute() && att.get('name').node.name === path[0]; }); + if (!rootSibling) { + rootSibling = createJSXSiblingAttribute(root, path[0]); + } + if (!rootSibling) return; const jsxExpressionContainer = rootSibling?.get('value'); if (!jsxExpressionContainer?.isJSXExpressionContainer()) return; @@ -808,11 +812,24 @@ export function migrateDeepProperty if (!newObj.isObjectExpression()) return; rootNode = newObj; if (i === path.length - 1) { - const staticKey = createStaticPropertyKey(accessor.key, accessor.computed); - const value = node.get('value'); - transform.jsxAttribute(value); + let value = node.get('value'); + if (!isNonNullNodePath(value)) { + const [transformed] = value.replaceWith( + t.jsxExpressionContainer(t.booleanLiteral(true)), + ); + value = transformed; + } + let updatedValue = transform.jsxAttribute(value as any, element, node, context); + if (!updatedValue || updatedValue === true) return; + if (t.isJSXExpressionContainer(updatedValue)) { + updatedValue = (updatedValue as unknown as t.JSXExpressionContainer).expression; + } + if (t.isJSXEmptyExpression(updatedValue)) return; + rewriteObjectPropertyInitializer(initializer, accessor, updatedValue); } } + + node.remove(); }, vueAttribute(templateNode, component, element, context) {}, @@ -821,7 +838,31 @@ export function migrateDeepProperty return transformer; } -function findJSXSiblingAttribute(); +function isNonNullNodePath(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, 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/replacements.ts b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/replacements.ts index d4bab62c..a4c4a6ea 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,14 +1,17 @@ import { + getManualInterventionMessage, + isNonNullJsxPropertyValue, migrateDeepProperty, migrateOptionalValue, migrateProperty, ObjectPropertyValue, ObjectPropertyValueTransformer, + removeProperty, transformObjectProperties, transformOptionalValue, type CodemodObjectPropertyReplacement, } from '../../plugins/transform-grid-options/transform-grid-options'; -import { ast, AstCliContext, AstTransformContext, Types } from '@ag-grid-devtools/ast'; +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/'; @@ -19,11 +22,13 @@ export const replacements: Array = transformOb rowSelection: migrateDeepProperty( ['selection', 'mode'], - transformOptionalValue(tf(transformRowSelection)), + transformOptionalValue(apply(transformRowSelection)), ), - suppressRowClickSelection: migrateDeepProperty( - ['selection', 'suppressClickSelection'], - migrateOptionalValue(), + suppressRowClickSelection: removeProperty( + getManualInterventionMessage('suppressRowClickSelection', MIGRATION_URL), + ), + suppressRowDeselection: removeProperty( + getManualInterventionMessage('suppressRowDeselection', MIGRATION_URL), ), isRowSelectable: migrateDeepProperty(['selection', 'isRowSelectable'], migrateOptionalValue()), rowMultiSelectWithClick: migrateDeepProperty( @@ -31,9 +36,16 @@ export const replacements: Array = transformOb migrateOptionalValue(), ), + groupSelectsChildren: removeProperty( + getManualInterventionMessage('groupSelectsChildren', MIGRATION_URL), + ), + groupSelectsFiltered: removeProperty( + getManualInterventionMessage('groupSelectsFiltered', MIGRATION_URL), + ), + enableRangeSelection: migrateDeepProperty( ['selection', 'mode'], - transformOptionalValue(tf(transformCellSelection)), + transformOptionalValue(apply(transformCellSelection)), ), suppressMultiRangeSelection: migrateDeepProperty( ['selection', 'suppressMultiRanges'], @@ -43,31 +55,55 @@ export const replacements: Array = transformOb ['selection', 'suppressClearOnFillReduction'], migrateOptionalValue(), ), - enableRangeHandle: migrateDeepProperty(['selection', 'handle'], migrateOptionalValue()), + enableRangeHandle: migrateDeepProperty( + ['selection', 'handle', 'mode'], + transformOptionalValue(apply(transformRangeHandle)), + ), enableFillHandle: migrateDeepProperty( ['selection', 'handle', 'mode'], - transformOptionalValue(tf(transformFillHandle)), + transformOptionalValue(apply(transformFillHandle)), ), fillHandleDirection: migrateDeepProperty( ['selection', 'handle', 'direction'], migrateOptionalValue(), ), + fillOperation: migrateDeepProperty( + ['selection', 'handle', 'setFillValue'], + migrateOptionalValue(), + ), + + suppressCopyRowsToClipboard: removeProperty( + getManualInterventionMessage('suppressCopyRowsToClipboard', MIGRATION_URL), + ), + suppressCopySingleCellRanges: removeProperty( + getManualInterventionMessage('suppressCopySingleCellRanges', MIGRATION_URL), + ), }); -function transformFillHandle(value: ObjectPropertyValue): Types.Expression { +function transformFillHandle(value: ObjectPropertyValue): t.Expression { if (value.isBooleanLiteral()) { - switch (value.node.value) { - case true: - return ast.expression`'fill'`; - default: - break; + if (value.node.value) { + return ast.expression`'fill'`; } + } else if (value.isJSXExpressionContainer()) { + return transformFillHandle((value as any).get('expression')); } return ast.expression`undefined`; } -function transformRowSelection(value: ObjectPropertyValue): Types.Expression { +function transformRangeHandle(value: ObjectPropertyValue): t.Expression { + if (value.isBooleanLiteral()) { + if (value.node.value) { + return ast.expression`'range'`; + } + } else if (value.isJSXExpressionContainer()) { + return transformRangeHandle((value as any).get('expression')); + } + return ast.expression`undefined`; +} + +function transformRowSelection(value: ObjectPropertyValue): t.Expression { if (value.isStringLiteral()) { switch (value.node.value) { case 'single': @@ -77,33 +113,35 @@ function transformRowSelection(value: ObjectPropertyValue): Types.Expression { default: break; } + } else if (value.isJSXExpressionContainer()) { + return transformRowSelection((value as any).get('expression')); } return ast.expression`undefined`; } -function transformCellSelection(value: ObjectPropertyValue): Types.Expression { +function transformCellSelection(value: ObjectPropertyValue): t.Expression { if (value.isBooleanLiteral()) { - switch (value.node.value) { - case true: - return ast.expression`'cell'`; - default: - break; + if (value.node.value) { + return ast.expression`'cell'`; } + } else if (value.isJSXExpressionContainer()) { + return transformCellSelection((value as any).get('expression')); } return ast.expression`undefined`; } -function tf>( - tff: (v: ObjectPropertyValue) => Types.Expression, +function apply>( + tff: (v: ObjectPropertyValue) => t.Expression, ): ObjectPropertyValueTransformer { return { property(value, accessor, context) { return tff(value); }, jsxAttribute(value, element, attribute, context) { - return value === true ? value : value.node; + if (isNonNullJsxPropertyValue(value)) return tff(value); + return null; }, angularAttribute(value, component, element, attribute, context) { return value; From 967424354ca89a1b0e64fc3819d8d10000fcfa06 Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Tue, 17 Sep 2024 16:36:35 +0100 Subject: [PATCH 06/15] add tests --- .../single-row-selection/input.component.ts | 34 +++++++++++++++++++ .../single-row-selection/output.component.ts | 34 +++++++++++++++++++ .../single-row-selection}/output.errors.cjs | 0 .../single-row-selection}/output.warnings.cjs | 0 .../single-row-selection/scenario.json | 8 +++++ .../js/cell-selection-fill-handle/input.js | 28 +++++++++++++++ .../output.errors.cjs | 1 + .../js/cell-selection-fill-handle/output.js | 33 ++++++++++++++++++ .../output.warnings.cjs | 10 ++++++ .../cell-selection-fill-handle/scenario.json | 8 +++++ .../scenarios/js/cell-selection/input.js | 24 +++++++++++++ .../js/cell-selection/output.errors.cjs | 1 + .../scenarios/js/cell-selection/output.js | 29 ++++++++++++++++ .../js/cell-selection/output.warnings.cjs | 10 ++++++ .../scenarios/js/cell-selection/scenario.json | 8 +++++ .../scenarios/js/multi-row-selection/input.js | 20 +++++++++++ .../js/multi-row-selection/output.errors.cjs | 1 + .../js/multi-row-selection/output.js | 21 ++++++++++++ .../multi-row-selection/output.warnings.cjs | 26 ++++++++++++++ .../js/multi-row-selection/scenario.json | 8 +++++ .../js/single-row-selection/input.js | 4 +++ .../js/single-row-selection/output.js | 5 ++- .../single-row-selection/output.warnings.cjs | 19 ++++++++++- .../jsx/cell-selection-fill-handle/input.jsx | 28 +++++++++++++++ .../output.errors.cjs | 1 + .../jsx/cell-selection-fill-handle/output.jsx | 32 +++++++++++++++++ .../output.warnings.cjs | 10 ++++++ .../scenario.json | 0 .../scenarios/jsx/cell-selection/input.jsx | 28 +++++++++++++++ .../jsx/cell-selection/output.errors.cjs | 1 + .../scenarios/jsx/cell-selection/output.jsx | 31 +++++++++++++++++ .../jsx/cell-selection/output.warnings.cjs | 10 ++++++ .../jsx/cell-selection/scenario.json | 8 +++++ .../jsx/multi-row-selection/input.jsx | 26 ++++++++++++++ .../jsx/multi-row-selection/output.errors.cjs | 1 + .../jsx/multi-row-selection/output.jsx | 23 +++++++++++++ .../multi-row-selection/output.warnings.cjs | 26 ++++++++++++++ .../jsx/multi-row-selection/scenario.json | 8 +++++ .../scenarios/jsx/single-row-select/input.jsx | 15 -------- .../jsx/single-row-select/output.jsx | 19 ----------- .../jsx/single-row-selection/input.jsx | 23 +++++++++++++ .../single-row-selection/output.errors.cjs | 1 + .../jsx/single-row-selection/output.jsx | 20 +++++++++++ .../single-row-selection/output.warnings.cjs | 18 ++++++++++ .../jsx/single-row-selection/scenario.json | 8 +++++ 45 files changed, 633 insertions(+), 36 deletions(-) create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/input.component.ts create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.component.ts rename packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/{jsx/single-row-select => angular/single-row-selection}/output.errors.cjs (100%) rename packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/{jsx/single-row-select => angular/single-row-selection}/output.warnings.cjs (100%) create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/scenario.json create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/input.js create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/output.errors.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/output.js create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/output.warnings.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-fill-handle/scenario.json create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/input.js create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/output.errors.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/output.js create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/output.warnings.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection/scenario.json create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/input.js create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/output.errors.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/output.js create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/output.warnings.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/multi-row-selection/scenario.json create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/input.jsx create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/output.errors.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/output.jsx create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/output.warnings.cjs rename packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/{single-row-select => cell-selection-fill-handle}/scenario.json (100%) create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/input.jsx create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/output.errors.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/output.jsx create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/output.warnings.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection/scenario.json create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/input.jsx create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/output.errors.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/output.jsx create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/output.warnings.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/multi-row-selection/scenario.json delete mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/input.jsx delete mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/output.jsx create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/input.jsx create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/output.errors.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/output.jsx create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/output.warnings.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection/scenario.json diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/input.component.ts b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/input.component.ts new file mode 100644 index 00000000..aa41b6eb --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/input.component.ts @@ -0,0 +1,34 @@ +// @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/single-row-selection/output.component.ts b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.component.ts new file mode 100644 index 00000000..552d6cfc --- /dev/null +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.component.ts @@ -0,0 +1,34 @@ +// @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("Goodbye, world!"); + }); + } +} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/output.errors.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.errors.cjs similarity index 100% rename from packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/output.errors.cjs rename to packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.errors.cjs diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/output.warnings.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.warnings.cjs similarity index 100% rename from packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/output.warnings.cjs rename to packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.warnings.cjs diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/scenario.json b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/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/single-row-selection/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-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/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 index ec44ae48..7b9dfba8 100644 --- 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 @@ -9,5 +9,9 @@ const gridApi = createGrid(document.body, { 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.js b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/single-row-selection/output.js index 5cfdb218..d5a98f59 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,10 +6,13 @@ const gridApi = createGrid(document.body, { onCellSelectionChanged: () => {}, onCellSelectionDeleteStart: () => {}, onCellSelectionDeleteEnd: () => {}, + suppressRowClickSelection: true, + suppressRowDeselection: true, + suppressCopyRowsToClipboard: true, + suppressCopySingleCellRanges: true, selection: { mode: "singleRow", - suppressClickSelection: true, 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 index e0a30c5d..ce6f30f1 100644 --- 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 @@ -1 +1,18 @@ -module.exports = []; +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/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/single-row-select/scenario.json b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/scenario.json similarity index 100% rename from packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/scenario.json rename to packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/cell-selection-fill-handle/scenario.json 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-select/input.jsx b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/input.jsx deleted file mode 100644 index 71c2dc4e..00000000 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/input.jsx +++ /dev/null @@ -1,15 +0,0 @@ -import { AgGridReact } from '@ag-grid-community/react'; - -function MyComponent(props) { - const onRangeSelectionChanged = useCallback(() => {}, []); - - return ( - - ); -} diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/output.jsx b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/output.jsx deleted file mode 100644 index 4821974c..00000000 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-select/output.jsx +++ /dev/null @@ -1,19 +0,0 @@ -import { AgGridReact } from '@ag-grid-community/react'; - -function MyComponent(props) { - const onRangeSelectionChanged = useCallback(() => {}, []); - - const selection = useMemo(() => ({ - mode: 'singleRow', - suppressClickSelection: true, - }), []); - - return ( - () - ); -} 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" + } +} From a5388b649b77bd19a44842a9ed33ae4ebec58d3a Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Wed, 18 Sep 2024 11:28:19 +0100 Subject: [PATCH 07/15] warn on unimplemented transformations --- .../transform-grid-options.ts | 29 ++++++++++++++----- .../single-row-selection/input.component.ts | 16 ++++++++++ .../single-row-selection/output.component.ts | 18 +++++++++++- .../single-row-selection/output.warnings.cjs | 19 +++++++++++- .../replacements.ts | 27 ++++++++++------- 5 files changed, 89 insertions(+), 20 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 d8212ecc..9fecaee3 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 @@ -729,6 +729,7 @@ export function migrateProperty>( export function migrateDeepProperty>( path: string[], transform: ObjectPropertyValueTransformer, + deprecationWarning?: string, ): ObjectPropertyTransformer { if (path.length === 1) { return migrateProperty(path[0], transform); @@ -773,11 +774,23 @@ export function migrateDeepProperty node.remove(); }, - get(node, context) {}, + get(node, context) { + if (node.shouldSkip) return; + node.skip(); - set(node, context) {}, + deprecationWarning && context.opts.warn(node, deprecationWarning); + }, - angularAttribute(attributeNode, component, element, context) {}, + 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; @@ -813,7 +826,7 @@ export function migrateDeepProperty rootNode = newObj; if (i === path.length - 1) { let value = node.get('value'); - if (!isNonNullNodePath(value)) { + if (isNullNodePath(value)) { const [transformed] = value.replaceWith( t.jsxExpressionContainer(t.booleanLiteral(true)), ); @@ -832,14 +845,16 @@ export function migrateDeepProperty node.remove(); }, - vueAttribute(templateNode, component, element, context) {}, + vueAttribute(templateNode, component, element, context) { + deprecationWarning && context.opts.warn(null, deprecationWarning); + }, }; return transformer; } -function isNonNullNodePath(x: NodePath): x is NodePath> { - return x.node != null; +function isNullNodePath(x: NodePath): x is NodePath { + return x.node == null; } function createJSXSiblingAttribute( diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/input.component.ts b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/input.component.ts index aa41b6eb..b7ce35b9 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/input.component.ts +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/input.component.ts @@ -11,6 +11,22 @@ import { IOlympicData } from './interfaces'; `, diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.component.ts b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.component.ts index 552d6cfc..b7ce35b9 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.component.ts +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.component.ts @@ -11,6 +11,22 @@ import { IOlympicData } from './interfaces'; `, @@ -28,7 +44,7 @@ export class AppComponent { .get('https://www.ag-grid.com/example-assets/olympic-winners.json') .subscribe((data) => { this.rowData = data; - console.log("Goodbye, world!"); + console.log("Hello, world!"); }); } } diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.warnings.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.warnings.cjs index e0a30c5d..a8e8c426 100644 --- a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.warnings.cjs +++ b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.warnings.cjs @@ -1 +1,18 @@ -module.exports = []; +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/replacements.ts b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/replacements.ts index a4c4a6ea..3990ebb8 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 @@ -23,6 +23,7 @@ export const replacements: Array = transformOb rowSelection: migrateDeepProperty( ['selection', 'mode'], transformOptionalValue(apply(transformRowSelection)), + getManualInterventionMessage('rowSelection', MIGRATION_URL), ), suppressRowClickSelection: removeProperty( getManualInterventionMessage('suppressRowClickSelection', MIGRATION_URL), @@ -30,10 +31,15 @@ export const replacements: Array = transformOb suppressRowDeselection: removeProperty( getManualInterventionMessage('suppressRowDeselection', MIGRATION_URL), ), - isRowSelectable: migrateDeepProperty(['selection', 'isRowSelectable'], migrateOptionalValue()), + isRowSelectable: migrateDeepProperty( + ['selection', 'isRowSelectable'], + migrateOptionalValue(), + getManualInterventionMessage('isRowSelectable', MIGRATION_URL), + ), rowMultiSelectWithClick: migrateDeepProperty( ['selection', 'enableMultiSelectWithClick'], migrateOptionalValue(), + getManualInterventionMessage('rowMultiSelectWithClick', MIGRATION_URL), ), groupSelectsChildren: removeProperty( @@ -46,30 +52,37 @@ export const replacements: Array = transformOb 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( @@ -85,8 +98,6 @@ function transformFillHandle(value: ObjectPropertyValue): t.Expression { if (value.node.value) { return ast.expression`'fill'`; } - } else if (value.isJSXExpressionContainer()) { - return transformFillHandle((value as any).get('expression')); } return ast.expression`undefined`; @@ -97,8 +108,6 @@ function transformRangeHandle(value: ObjectPropertyValue): t.Expression { if (value.node.value) { return ast.expression`'range'`; } - } else if (value.isJSXExpressionContainer()) { - return transformRangeHandle((value as any).get('expression')); } return ast.expression`undefined`; } @@ -113,8 +122,6 @@ function transformRowSelection(value: ObjectPropertyValue): t.Expression { default: break; } - } else if (value.isJSXExpressionContainer()) { - return transformRowSelection((value as any).get('expression')); } return ast.expression`undefined`; @@ -125,8 +132,6 @@ function transformCellSelection(value: ObjectPropertyValue): t.Expression { if (value.node.value) { return ast.expression`'cell'`; } - } else if (value.isJSXExpressionContainer()) { - return transformCellSelection((value as any).get('expression')); } return ast.expression`undefined`; @@ -140,8 +145,8 @@ function apply>( return tff(value); }, jsxAttribute(value, element, attribute, context) { - if (isNonNullJsxPropertyValue(value)) return tff(value); - return null; + if (!isNonNullJsxPropertyValue(value)) return null; + return value.isJSXExpressionContainer() ? tff((value as any).get('expression')) : tff(value); }, angularAttribute(value, component, element, attribute, context) { return value; From 2462ef6fcc0a589599a9e8af90b590ed9c078fcf Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Wed, 18 Sep 2024 11:28:49 +0100 Subject: [PATCH 08/15] rename scenario --- .../angular/{single-row-selection => warnings}/input.component.ts | 0 .../{single-row-selection => warnings}/output.component.ts | 0 .../angular/{single-row-selection => warnings}/output.errors.cjs | 0 .../{single-row-selection => warnings}/output.warnings.cjs | 0 .../angular/{single-row-selection => warnings}/scenario.json | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/{single-row-selection => warnings}/input.component.ts (100%) rename packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/{single-row-selection => warnings}/output.component.ts (100%) rename packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/{single-row-selection => warnings}/output.errors.cjs (100%) rename packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/{single-row-selection => warnings}/output.warnings.cjs (100%) rename packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/{single-row-selection => warnings}/scenario.json (100%) diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/input.component.ts b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/input.component.ts similarity index 100% rename from packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/input.component.ts rename to packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/input.component.ts diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.component.ts b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/output.component.ts similarity index 100% rename from packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.component.ts rename to packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/output.component.ts diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.errors.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/output.errors.cjs similarity index 100% rename from packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.errors.cjs rename to packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/output.errors.cjs diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.warnings.cjs b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/output.warnings.cjs similarity index 100% rename from packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/output.warnings.cjs rename to packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/output.warnings.cjs diff --git a/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/scenario.json b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/scenario.json similarity index 100% rename from packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/single-row-selection/scenario.json rename to packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/angular/warnings/scenario.json From e91f668b7a11bf00f405f512b9f62a390ec73367 Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Thu, 19 Sep 2024 10:36:34 +0100 Subject: [PATCH 09/15] add comments, tidy, reduce type casting --- .../transform-grid-options.ts | 85 +++++++++++++------ .../replacements.ts | 22 ++--- 2 files changed, 72 insertions(+), 35 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 9fecaee3..3a90e0e0 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 @@ -726,6 +726,19 @@ 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, @@ -737,16 +750,16 @@ export function migrateDeepProperty const transformer: ObjectPropertyTransformer = { init(node, context) { - if (node.shouldSkip) { - return; - } + if (node.shouldSkip) return; node.skip(); - // find or create sibling root prop - // recurse into prop with find or create - // at lowest level, add transformed value to properties if (!node.parentPath.isObjectExpression()) return; + + // Start off at the root node, where the target object should be defined let rootNode = node.parentPath; + + // 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 }; @@ -758,15 +771,13 @@ export function migrateDeepProperty 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) { const accessor = createStaticPropertyKey(rootAccessor.key, rootAccessor.computed); const value = node.get('value'); - if (Array.isArray(value)) return; - const updatedValue = transform.property( - value as NodePath, - accessor!, - context, - )!; + if (Array.isArray(value) || !value.isExpression()) return; + const updatedValue = transform.property(value, accessor!, context)!; rewriteObjectPropertyInitializer(initializer, rootAccessor, updatedValue); } } @@ -796,22 +807,31 @@ export function migrateDeepProperty if (node.shouldSkip) return; node.skip(); + // Parent should be the JSX element if (!node.parentPath.isJSXOpeningElement()) return; const root = node.parentPath; - let rootSibling = root.get('attributes').find((att): att is NodePath => { - return att.isJSXAttribute() && att.get('name').node.name === path[0]; - }); + // Find or create the root attribute of the target object + 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; + // Inject an empty object expression into the expression container 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]; @@ -824,20 +844,37 @@ export function migrateDeepProperty 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) { - let value = node.get('value'); + 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; } - let updatedValue = transform.jsxAttribute(value as any, element, node, context); - if (!updatedValue || updatedValue === true) return; - if (t.isJSXExpressionContainer(updatedValue)) { - updatedValue = (updatedValue as unknown as t.JSXExpressionContainer).expression; + // 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)) { + return; } - if (t.isJSXEmptyExpression(updatedValue)) return; rewriteObjectPropertyInitializer(initializer, accessor, updatedValue); } } @@ -887,9 +924,9 @@ function createSiblingPropertyInitializer( const [newPath] = objExp.replaceWith(t.objectExpression(objExp.node.properties.concat(prop))); return newPath .get('properties') - .find((p) => p.isObjectProperty() && p.node.key === accessor.key) as - | NodePath - | undefined; + .find( + (p): p is NodePath => p.isObjectProperty() && p.node.key === accessor.key, + ); } function findSiblingPropertyInitializer( 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 3990ebb8..1688586c 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 @@ -93,26 +93,26 @@ export const replacements: Array = transformOb ), }); -function transformFillHandle(value: ObjectPropertyValue): t.Expression { +function transformFillHandle(value: ObjectPropertyValue): t.Expression | null { if (value.isBooleanLiteral()) { if (value.node.value) { return ast.expression`'fill'`; } } - return ast.expression`undefined`; + return null; } -function transformRangeHandle(value: ObjectPropertyValue): t.Expression { +function transformRangeHandle(value: ObjectPropertyValue): t.Expression | null { if (value.isBooleanLiteral()) { if (value.node.value) { return ast.expression`'range'`; } } - return ast.expression`undefined`; + return null; } -function transformRowSelection(value: ObjectPropertyValue): t.Expression { +function transformRowSelection(value: ObjectPropertyValue): t.Expression | null { if (value.isStringLiteral()) { switch (value.node.value) { case 'single': @@ -124,29 +124,29 @@ function transformRowSelection(value: ObjectPropertyValue): t.Expression { } } - return ast.expression`undefined`; + return null; } -function transformCellSelection(value: ObjectPropertyValue): t.Expression { +function transformCellSelection(value: ObjectPropertyValue): t.Expression | null { if (value.isBooleanLiteral()) { if (value.node.value) { return ast.expression`'cell'`; } } - return ast.expression`undefined`; + return null; } function apply>( - tff: (v: ObjectPropertyValue) => t.Expression, + transform: (v: ObjectPropertyValue) => t.Expression | null, ): ObjectPropertyValueTransformer { return { property(value, accessor, context) { - return tff(value); + return transform(value); }, jsxAttribute(value, element, attribute, context) { if (!isNonNullJsxPropertyValue(value)) return null; - return value.isJSXExpressionContainer() ? tff((value as any).get('expression')) : tff(value); + return transform(value); }, angularAttribute(value, component, element, attribute, context) { return value; From 64fe0baf67cdb8204638c864680e7567344bc956 Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Thu, 19 Sep 2024 10:45:01 +0100 Subject: [PATCH 10/15] uncommit --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index f4224f42..25ca3bc5 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,5 @@ "vite": "5.4.4", "vitest": "1.6.0", "@vitest/coverage-v8": "1.6.0" - }, - "packageManager": "pnpm@9.7.0+sha512.dc09430156b427f5ecfc79888899e1c39d2d690f004be70e05230b72cb173d96839587545d09429b55ac3c429c801b4dc3c0e002f653830a420fa2dd4e3cf9cf" + } } From b22aa9f821a7854f1b0df3034162b1c7fbd02ae0 Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Thu, 19 Sep 2024 10:50:15 +0100 Subject: [PATCH 11/15] missing manifest --- packages/cli/src/codemods/versions/manifest.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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; From 5c7e315e1cfbb65c2d47b4e233ca5c900413e4c1 Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Thu, 19 Sep 2024 10:51:51 +0100 Subject: [PATCH 12/15] update test --- packages/cli/src/codemods/lib.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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({ From d0fe573a0b248986b314abfb23463726cae48cbb Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Thu, 19 Sep 2024 11:00:13 +0100 Subject: [PATCH 13/15] Increment package version --- packages/cli/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ", From c2a6ad1b8dd4eed2af5b007ea54515c92f45ab9d Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Thu, 19 Sep 2024 11:16:45 +0100 Subject: [PATCH 14/15] test case for deprecated colDef props --- .../scenarios/js/columnDefs/input.js | 18 +++++++++++++ .../scenarios/js/columnDefs/output.errors.cjs | 1 + .../scenarios/js/columnDefs/output.js | 22 ++++++++++++++++ .../js/columnDefs/output.warnings.cjs | 26 +++++++++++++++++++ .../scenarios/js/columnDefs/scenario.json | 8 ++++++ .../replacements.ts | 26 +++++++++++++++++++ 6 files changed, 101 insertions(+) create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/input.js create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/output.errors.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/output.js create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/output.warnings.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/columnDefs/scenario.json 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/replacements.ts b/packages/cli/src/codemods/transforms/transform-grid-options-v32-2/replacements.ts index 1688586c..6f2980c1 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 @@ -7,8 +7,10 @@ import { 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'; @@ -16,6 +18,30 @@ import { ast, AstCliContext, AstTransformContext, Types as t } from '@ag-grid-de 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()), From 689ff48f90d7af27490ea0a36861350dd945d26b Mon Sep 17 00:00:00 2001 From: Elias Malik Date: Thu, 19 Sep 2024 12:28:54 +0100 Subject: [PATCH 15/15] pre-compute the value and exit early if no valid transformation --- .../transform-grid-options.ts | 75 ++++++++++--------- .../js/cell-selection-expressions/input.js | 28 +++++++ .../output.errors.cjs | 1 + .../js/cell-selection-expressions/output.js | 29 +++++++ .../output.warnings.cjs | 18 +++++ .../cell-selection-expressions/scenario.json | 8 ++ .../input.jsx | 25 +++++++ .../output.errors.cjs | 1 + .../output.jsx | 22 ++++++ .../output.warnings.cjs | 22 ++++++ .../scenario.json | 8 ++ 11 files changed, 203 insertions(+), 34 deletions(-) create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/input.js create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/output.errors.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/output.js create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/output.warnings.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/js/cell-selection-expressions/scenario.json create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/input.jsx create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/output.errors.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/output.jsx create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/output.warnings.cjs create mode 100644 packages/cli/src/codemods/transforms/transform-grid-options-v32-2/__fixtures__/scenarios/jsx/single-row-selection-expressions/scenario.json 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 3a90e0e0..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 @@ -758,6 +758,15 @@ export function migrateDeepProperty // 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++) { @@ -774,10 +783,6 @@ export function migrateDeepProperty // On the final path part, apply the transformation and set the value if (i === path.length - 1) { - const accessor = createStaticPropertyKey(rootAccessor.key, rootAccessor.computed); - const value = node.get('value'); - if (Array.isArray(value) || !value.isExpression()) return; - const updatedValue = transform.property(value, accessor!, context)!; rewriteObjectPropertyInitializer(initializer, rootAccessor, updatedValue); } } @@ -811,7 +816,37 @@ export function migrateDeepProperty if (!node.parentPath.isJSXOpeningElement()) return; const root = node.parentPath; - // Find or create the root attribute of the target object + // 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( @@ -823,7 +858,7 @@ export function migrateDeepProperty } if (!rootSibling) return; - // Inject an empty object expression into the expression container + // Fish out the reference to the object expression const jsxExpressionContainer = rootSibling?.get('value'); if (!jsxExpressionContainer?.isJSXExpressionContainer()) return; const objExp = jsxExpressionContainer.get('expression'); @@ -847,34 +882,6 @@ export function migrateDeepProperty // On the final path part, apply the transformation and set the value if (i === path.length - 1) { - 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)) { - return; - } rewriteObjectPropertyInitializer(initializer, accessor, updatedValue); } } 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/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" + } +}