Skip to content

Commit 7134b42

Browse files
AG-12669 - Deprecate getInfiniteRowCount (#84)
1 parent 21d5aef commit 7134b42

File tree

18 files changed

+230
-0
lines changed

18 files changed

+230
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# `transform-grid-api-methods-v32-2`
2+
3+
> _Transform deprecated Grid API method invocations_
4+
5+
See the [`transform-grid-api-methods`](../../plugins/transform-grid-api-methods/) plugin for usage instructions.
6+
7+
## Common tasks
8+
9+
### Add a test case
10+
11+
Create a new unit test scenario for this transform:
12+
13+
```
14+
pnpm run task:create-test --type transform --target transform-grid-api-methods-v32-2
15+
```
16+
17+
### Add a new rule
18+
19+
Replacement rules are specified in [`replacements.ts`](./replacements.ts)
20+
21+
### Add to a codemod release
22+
23+
Add this source code transformation to a codemod release:
24+
25+
```
26+
pnpm run task:include-transform --transform transform-grid-api-methods-v32-2
27+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { createGrid } from '@ag-grid-community/core';
2+
3+
const gridApi = createGrid(document.body, {
4+
columnDefs: [],
5+
rowData: [],
6+
});
7+
8+
gridApi.getInfiniteRowCount();
9+
gridApi?.getInfiniteRowCount();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { createGrid } from '@ag-grid-community/core';
2+
3+
const gridApi = createGrid(document.body, {
4+
columnDefs: [],
5+
rowData: [],
6+
});
7+
8+
gridApi.getDisplayedRowCount();
9+
gridApi?.getDisplayedRowCount();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"scenario": {
3+
"input": "input.js",
4+
"output": "output.js"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @ts-nocheck
2+
import { createGrid } from '@ag-grid-community/core';
3+
4+
const gridApi = createGrid(document.body, {
5+
columnDefs: [],
6+
rowData: [],
7+
});
8+
9+
gridApi.getInfiniteRowCount();
10+
gridApi?.getInfiniteRowCount();
11+
gridApi!.getInfiniteRowCount();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @ts-nocheck
2+
import { createGrid } from '@ag-grid-community/core';
3+
4+
const gridApi = createGrid(document.body, {
5+
columnDefs: [],
6+
rowData: [],
7+
});
8+
9+
gridApi.getDisplayedRowCount();
10+
gridApi?.getDisplayedRowCount();
11+
gridApi!.getDisplayedRowCount();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"scenario": {
3+
"input": "input.ts",
4+
"output": "output.ts"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './transform-grid-api-methods-v32-2';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { type TransformManifest } from '@ag-grid-devtools/types';
2+
3+
const manifest: TransformManifest = {
4+
name: 'Transform Grid API methods v32.2',
5+
description: 'Transform deprecated Grid API method invocations',
6+
};
7+
8+
export default manifest;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ast, matchNode, pattern as p, replace, template } from '@ag-grid-devtools/ast';
2+
import {
3+
type GridApiDeprecation,
4+
type GridApiReplacement,
5+
} from '../../plugins/transform-grid-api-methods';
6+
7+
export const replacements: Array<GridApiReplacement> = [
8+
...['', '?', '!'].map((apiOptionalChaining) =>
9+
replace(
10+
matchNode(({ api }) => ast.expression`${api}${apiOptionalChaining}.getInfiniteRowCount()`, {
11+
api: p.expression(),
12+
}),
13+
template(({ api }) => {
14+
return ast.expression`${api}${apiOptionalChaining}.getDisplayedRowCount()`;
15+
}),
16+
),
17+
),
18+
];
19+
20+
export const deprecations: Array<GridApiDeprecation> = [];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { dirname, join } from 'node:path';
2+
import { fileURLToPath } from 'node:url';
3+
import { describe, expect, onTestFinished, test } from 'vitest';
4+
import { loadTransformScenarios } from '../../test/runners/transform';
5+
6+
import transformGridApiMethodsV32_2 from './transform-grid-api-methods-v32-2';
7+
8+
const __dirname = dirname(fileURLToPath(import.meta.url));
9+
10+
describe(transformGridApiMethodsV32_2, () => {
11+
const scenariosPath = join(__dirname, './__fixtures__/scenarios');
12+
loadTransformScenarios(scenariosPath, {
13+
transforms: [transformGridApiMethodsV32_2],
14+
vitest: { describe, expect, test, onTestFinished },
15+
});
16+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { type AstCliContext, type AstTransform } from '@ag-grid-devtools/ast';
2+
import { transformGridApiMethods } from '../../plugins/transform-grid-api-methods';
3+
import { deprecations, replacements } from './replacements';
4+
5+
const plugin: AstTransform<AstCliContext> = transformGridApiMethods({ replacements, deprecations });
6+
7+
const transform: AstTransform<AstCliContext> = function transformGridApiMethodsV32_0(babel) {
8+
return plugin(babel);
9+
};
10+
11+
export default transform;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# 32.2.0
2+
3+
Codemod for upgrading to [AG Grid v32.2.0](https://github.com/ag-grid/ag-grid/releases/tag/v32.2.0)
4+
5+
## Usage
6+
7+
```
8+
npx @ag-grid-devtools/cli migrate --to 32.2.0
9+
```
10+
11+
Source code transformations applied by this codemod are specified in [`transforms.ts`](./transforms.ts).
12+
13+
## Common tasks
14+
15+
### Add a transform
16+
17+
Option 1: Create a new source code transformation to add to this codemod release version:
18+
19+
```
20+
pnpm run task:create-transform --release 32.2.0
21+
```
22+
23+
Option 2: Add an existing source code transformation to this codemod release version:
24+
25+
```
26+
pnpm run task:include-transform --version 32.2.0
27+
```
28+
29+
### Add a test case
30+
31+
Create a new unit test scenario for this version:
32+
33+
```
34+
pnpm run task:create-test --type version --target 32.2.0
35+
```

packages/cli/src/codemods/versions/32.2.0/__fixtures__/scenarios/.gitignore

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { dirname, join } from 'node:path';
2+
import { fileURLToPath } from 'node:url';
3+
import { describe, expect, onTestFinished, test } from 'vitest';
4+
import { loadCodemodExampleScenarios } from '../../test/runners/codemod';
5+
6+
import codemod from './codemod';
7+
8+
const __dirname = dirname(fileURLToPath(import.meta.url));
9+
10+
describe(codemod, () => {
11+
const scenariosPath = join(__dirname, './__fixtures__/scenarios');
12+
loadCodemodExampleScenarios(scenariosPath, {
13+
codemod,
14+
vitest: { describe, expect, test, onTestFinished },
15+
});
16+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { transformFileAst } from '@ag-grid-devtools/codemod-utils';
2+
import {
3+
type Codemod,
4+
type CodemodInput,
5+
type CodemodOptions,
6+
type CodemodResult,
7+
} from '@ag-grid-devtools/types';
8+
9+
import transforms from './transforms';
10+
11+
const codemod: Codemod = function codemodV32_2_0(
12+
file: CodemodInput,
13+
options: CodemodOptions,
14+
): CodemodResult {
15+
const { path, source } = file;
16+
const { fs, userConfig } = options;
17+
return transformFileAst(source, transforms, {
18+
filename: path,
19+
fs,
20+
userConfig,
21+
});
22+
};
23+
24+
export default codemod;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { type TransformManifest, type VersionManifest } from '@ag-grid-devtools/types';
2+
3+
import transformGridApiMethodsV32_2 from '../../transforms/transform-grid-api-methods-v32-2/manifest.ts';
4+
5+
const transforms: Array<TransformManifest> = [transformGridApiMethodsV32_2];
6+
7+
const manifest: VersionManifest = {
8+
version: '32.2.0',
9+
codemodPath: 'versions/32.2.0',
10+
transforms,
11+
};
12+
13+
export default manifest;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { type AstCliContext, type AstTransform } from '@ag-grid-devtools/ast';
2+
3+
import transformGridApiMethodsV32_2 from '../../transforms/transform-grid-api-methods-v32-2';
4+
5+
const transforms: Array<AstTransform<AstCliContext>> = [transformGridApiMethodsV32_2];
6+
7+
export default transforms;

0 commit comments

Comments
 (0)