Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[codemod] Add missing preset-safe for the data-grid #15709

Merged
merged 5 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 57 additions & 21 deletions packages/x-codemod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ The corresponding sub-sections are listed below

- [`preset-safe-for-tree-view`](#preset-safe-for-tree-view-v800)
- [`preset-safe-for-charts`](#preset-safe-for-charts-v800)
- [`preset-safe-for-data-grid`](#preset-safe-for-data-grid-v800)
- [`preset-safe-for-pickers`](#preset-safe-for-pickers-v800)

### Tree View codemods

Expand All @@ -95,31 +97,31 @@ The list includes these transformers
Renames the Tree View component to Simple Tree View

```diff
-import { TreeView } from '@mui/x-tree-view';
+import { SimpleTreeView } from '@mui/x-tree-view';
- import { TreeView } from '@mui/x-tree-view';
arminmeh marked this conversation as resolved.
Show resolved Hide resolved
+ import { SimpleTreeView } from '@mui/x-tree-view';

-import { TreeView } from '@mui/x-tree-view/TreeView';
+import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView';
- import { TreeView } from '@mui/x-tree-view/TreeView';
+ import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView';

return (
- <TreeView>
+ <SimpleTreeView>
<TreeItem itemId="1" label="First item" />
- </TreeView>
+ </SimpleTreeView>
);
return (
- <TreeView>
+ <SimpleTreeView>
<TreeItem itemId="1" label="First item" />
- </TreeView>
+ </SimpleTreeView>
);
```

#### `rename-tree-item-2`

Renames the `TreeItem2` component to `TreeItem` (same for any subcomponents or utils like `useTreeItem2` or `TreeItem2Icon`).

```diff
-import { TreeItem2 } from '@mui/x-tree-view';
+import { TreeItem } from '@mui/x-tree-view';
- import { TreeItem2 } from '@mui/x-tree-view';
+ import { TreeItem } from '@mui/x-tree-view';

-import { TreeItem2 } from '@mui/x-tree-view/TreeItem2';
+import { TreeItem } from '@mui/x-tree-view/TreeItem';
- import { TreeItem2 } from '@mui/x-tree-view/TreeItem2';
+ import { TreeItem } from '@mui/x-tree-view/TreeItem';
```

### Charts codemods
Expand Down Expand Up @@ -159,7 +161,7 @@ Renames `ResponsiveChartContainer` and `ResponsiveChartContainerPro` by `ChartCo

- <ResponsiveChartContainer>
+ <ChartContainer>
<BarPlot />
<BarPlot />
- </ResponsiveChartContainer>
+ </ChartContainer>
```
Expand Down Expand Up @@ -212,17 +214,51 @@ The list includes these transformers
Remove feature flags for stabilized `experimentalFeatures`.

```diff
<DataGridPremium
- experimentalFeatures={{
- ariaV8: true,
- }}
/>
<DataGridPremium
- experimentalFeatures={{
- ariaV8: true,
- }}
/>
```

```bash
npx @mui/x-codemod@latest v8.0.0/data-grid/remove-stabilized-experimentalFeatures <path>
```

### Pickers codemods

#### `preset-safe` for pickers v8.0.0
arminmeh marked this conversation as resolved.
Show resolved Hide resolved

The `preset-safe` codemods for pickers.
arminmeh marked this conversation as resolved.
Show resolved Hide resolved

```bash
npx @mui/x-codemod@latest v8.0.0/pickers/preset-safe <path|folder>
arminmeh marked this conversation as resolved.
Show resolved Hide resolved
```

The list includes these transformers

- [`rename-and-move-field-value-type`](#rename-and-move-field-value-type)

#### `rename-and-move-field-value-type`

Renames `FieldValueType` to `PickerValueType`.

```diff
- import { FieldValueType } from '@mui/x-date-pickers';
+ import { PickerValueType } from '@mui/x-date-pickers';

interface MyComponentProps {
- valueType: FieldValueType;
+ valueType: PickerValueType;
foo: string;
bar: number;
}
```

```bash
npx @mui/x-codemod@latest v8.0.0/pickers/rename-and-move-field-value-type <path>
arminmeh marked this conversation as resolved.
Show resolved Hide resolved
```

## v7.0.0

### 🚀 `preset-safe` for v7.0.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @ts-nocheck
import * as React from 'react';
import { DataGridPremium } from '@mui/x-data-grid-premium';

// prettier-ignore
<React.Fragment>
<DataGridPremium
experimentalFeatures={{
warnIfFocusStateIsNotSynced: true,
ariaV8: true,
}}
/>
<DataGridPremium
experimentalFeatures={{
ariaV8: true,
}}
/>
<DataGridPremium {...props} />
</React.Fragment>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @ts-nocheck
import * as React from 'react';
import { DataGridPremium } from '@mui/x-data-grid-premium';

// prettier-ignore
<React.Fragment>
<DataGridPremium
experimentalFeatures={{
warnIfFocusStateIsNotSynced: true,
}}
/>
<DataGridPremium />
<DataGridPremium {...props} />
</React.Fragment>;
9 changes: 9 additions & 0 deletions packages/x-codemod/src/v8.0.0/data-grid/preset-safe/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import removeExperimentalFeatures from '../remove-stabilized-experimentalFeatures';

import { JsCodeShiftAPI, JsCodeShiftFileInfo } from '../../../types';

export default function transformer(file: JsCodeShiftFileInfo, api: JsCodeShiftAPI, options: any) {
file.source = removeExperimentalFeatures(file, api, options);

return file.source;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import path from 'path';
import { expect } from 'chai';
import jscodeshift from 'jscodeshift';
import transform from './index';
import readFile from '../../../util/readFile';

function read(fileName) {
return readFile(path.join(__dirname, fileName));
}

describe('v8.0.0/data-grid', () => {
describe('preset-safe', () => {
it('transforms code as needed', () => {
const actual = transform(
{
source: read('./actual.spec.tsx'),
path: require.resolve('./actual.spec.tsx'),
},
{ jscodeshift: jscodeshift.withParser('tsx') },
{},
);

const expected = read('./expected.spec.tsx');
expect(actual).to.equal(expected, 'The transformed version should be correct');
});

it('should be idempotent for expression', () => {
const actual = transform(
{
source: read('./expected.spec.tsx'),
path: require.resolve('./expected.spec.tsx'),
},
{ jscodeshift: jscodeshift.withParser('tsx') },
{},
);

const expected = read('./expected.spec.tsx');
expect(actual).to.equal(expected, 'The transformed version should be correct');
});
});
});
2 changes: 2 additions & 0 deletions packages/x-codemod/src/v8.0.0/preset-safe/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import transformTreeView from '../tree-view/preset-safe';
import transformPickers from '../pickers/preset-safe';
import transformCharts from '../charts/preset-safe';
import transformDataGrid from '../data-grid/preset-safe';
import { JsCodeShiftAPI, JsCodeShiftFileInfo } from '../../types';

export default function transformer(file: JsCodeShiftFileInfo, api: JsCodeShiftAPI, options: any) {
file.source = transformTreeView(file, api, options);
file.source = transformPickers(file, api, options);
file.source = transformCharts(file, api, options);
file.source = transformDataGrid(file, api, options);

return file.source;
}
Loading