Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1dff9d0
add tests
erwanMarmelab May 28, 2025
f4c497d
v1 of the codemod -> replace import
erwanMarmelab May 28, 2025
7e2b2ee
stop after import if nothing to change
erwanMarmelab May 28, 2025
bf00c46
codemod -> replace the Datagrid component
erwanMarmelab May 28, 2025
0b7d2c5
codemod -> wrap every fields with a `<DataTable.Col source="xxx">`
erwanMarmelab May 28, 2025
f79eb38
codemod -> delete the optimized prop of the Datagrid component
erwanMarmelab May 28, 2025
63ec8cf
codemod -> replace the rowStyle prop of the Datagrid component by rowSx
erwanMarmelab May 28, 2025
1ea7b29
codemod -> replace the & .RaDatagrid-xxxx key of the sx prop of the D…
erwanMarmelab May 28, 2025
1a645b7
fix the opening element
erwanMarmelab May 30, 2025
68d8893
codemod -> don't wrap if it is a TextField or a NumberField
erwanMarmelab May 30, 2025
e083439
codemod -> clean imports if you don't still use TextField or NumberField
erwanMarmelab May 30, 2025
5817464
adapt tests
erwanMarmelab May 30, 2025
6ac08a2
don't apply an empty source
erwanMarmelab May 30, 2025
5df9956
fix wrong quote -> from `'` to `"`
erwanMarmelab May 30, 2025
d948132
fix object structure (eg for sx definition)
erwanMarmelab May 30, 2025
61fb0d2
improve tests to add a new usecase
erwanMarmelab May 30, 2025
d70f0a4
codemod -> if exist display label instead of source
erwanMarmelab May 30, 2025
865de35
simplify the datagrid replace code
erwanMarmelab May 30, 2025
54a4bee
fix test
erwanMarmelab Jun 4, 2025
7d36f5e
disable prettier on test
erwanMarmelab Jun 4, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable import/no-extraneous-dependencies */
import * as React from 'react';
import { List, Datagrid, TextField } from 'react-admin';

const PostList = () => (
<List>
<Datagrid>
<TextField source="id" label="Post number" />
<TextField source="title" />
<TextField source="body" />
</Datagrid>
</List>
);

export default PostList;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable import/no-extraneous-dependencies */
import * as React from 'react';
import { List, DataTable } from 'react-admin';

const PostList = () => (
<List>
<DataTable>
<DataTable.Col source="id" label="Post number" />
<DataTable.Col source="title" />
<DataTable.Col source="body" />
</DataTable>
</List>
);

export default PostList;
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* eslint-disable import/no-extraneous-dependencies */
import * as React from 'react';
import {
List,
Datagrid,
TextField,
EmailField,
NumberField,
EditButton,
ReferenceField,
UrlField,
DateField,
} from 'react-admin';

// @ts-ignore
import { MyCustomField } from './MyCustomField';

const PostList = () => (
<List>
<Datagrid>
<TextField source="id" />
<EmailField source="email" />
<EmailField
source="author_email"
label="Email of the author of the post"
/>
<NumberField source="nb_vues" />
<NumberField
source="price"
locales="fr-FR"
options={{ style: 'currency', currency: 'USD' }}
/>
<TextField source="title" />
<ReferenceField source="userId" reference="users">
<TextField source="name" />
</ReferenceField>
<UrlField source="url" />
<DateField source="createdAt" />
<MyCustomField source="code" />
<EditButton />
</Datagrid>
</List>
);

export default PostList;
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* eslint-disable import/no-extraneous-dependencies */
import * as React from 'react';
import {
List,
DataTable,
TextField,
EmailField,
EditButton,
ReferenceField,
UrlField,
DateField,
} from 'react-admin';

// @ts-ignore
import { MyCustomField } from './MyCustomField';

const PostList = () => (
<List>
<DataTable>
<DataTable.Col source="id" />
<DataTable.Col source="email">
<EmailField source="email" />
</DataTable.Col>
<DataTable.Col label="Email of the author of the post">
<EmailField
source="author_email"
label="Email of the author of the post"
/>
</DataTable.Col>
<DataTable.NumberCol source="nb_vues" />
<DataTable.NumberCol
source="price"
locales="fr-FR"
options={{ style: 'currency', currency: 'USD' }}
/>
<DataTable.Col source="title" />
<DataTable.Col source="userId">
<ReferenceField source="userId" reference="users">
<TextField source="name" />
</ReferenceField>
</DataTable.Col>
<DataTable.Col source="url">
<UrlField source="url" />
</DataTable.Col>
<DataTable.Col source="createdAt">
<DateField source="createdAt" />
</DataTable.Col>
<DataTable.Col source="code">
<MyCustomField source="code" />
</DataTable.Col>
<DataTable.Col>
<EditButton />
</DataTable.Col>
</DataTable>
</List>
);

export default PostList;
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-disable prettier/prettier */
/* eslint-disable import/no-extraneous-dependencies */
import * as React from 'react';
import { List, Datagrid, TextField, useRecordContext } from 'react-admin';

const CustomEmpty = () => <div>No posts found</div>;

const PostPanel = () => {
const record = useRecordContext();
return <div dangerouslySetInnerHTML={{ __html: record.body }} />;
};

const postRowStyle = (record, index) => ({
backgroundColor: record.nb_views >= 500 ? '#efe' : 'white',
});

const PostList = () => (
<List>
<Datagrid
bulkActionButtons={false}
empty={<CustomEmpty />}
expand={<PostPanel />}
expandSingle
rowClick={false}
optimized
rowStyle={postRowStyle}
sx={{
'& .RaDatagrid-row': {
backgroundColor: 'white',
},
'& .RaDatagrid-row:hover': {
backgroundColor: '#f5f5f5',
},
}}>
<TextField source="id" />
<TextField source="title" />
<TextField source="body" />
</Datagrid>
</List>
);

export default PostList;
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* eslint-disable prettier/prettier */
/* eslint-disable import/no-extraneous-dependencies */
import * as React from 'react';
import { List, DataTable, useRecordContext } from 'react-admin';

const CustomEmpty = () => <div>No posts found</div>;

const PostPanel = () => {
const record = useRecordContext();
return <div dangerouslySetInnerHTML={{ __html: record.body }} />;
};

const postRowStyle = (record, index) => ({
backgroundColor: record.nb_views >= 500 ? '#efe' : 'white',
});

const PostList = () => (
<List>
<DataTable
bulkActionButtons={false}
empty={<CustomEmpty />}
expand={<PostPanel />}
expandSingle
rowClick={false}
rowSx={postRowStyle}
sx={{
'& .RaDataTable-row': {
backgroundColor: 'white',
},
'& .RaDataTable-row:hover': {
backgroundColor: '#f5f5f5',
},
}}>
<DataTable.Col source="id" />
<DataTable.Col source="title" />
<DataTable.Col source="body" />
</DataTable>
</List>
);

export default PostList;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { defineTest } from 'jscodeshift/dist/testUtils';

jest.autoMockOff();

defineTest(
__dirname,
'replace-Datagrid-DataTable',
null,
'replace-Datagrid-DataTable-Basic',
{ parser: 'tsx' }
);
defineTest(
__dirname,
'replace-Datagrid-DataTable',
null,
'replace-Datagrid-DataTable-ManyChildren',
{ parser: 'tsx' }
);
defineTest(
__dirname,
'replace-Datagrid-DataTable',
null,
'replace-Datagrid-DataTable-Props',
{ parser: 'tsx' }
);
Loading
Loading