Skip to content

Commit bf00c46

Browse files
committed
codemod -> replace the Datagrid component
1 parent 7e2b2ee commit bf00c46

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

packages/ra-core/codemods/replace-Datagrid-DataTable.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,36 @@ const replaceImport = (root, j) => {
5555
node.source
5656
)
5757
);
58+
return true;
5859
};
5960

6061
const replaceComponent = (root, j) => {
61-
// TODO
62+
// Find all instances of Datagrid
63+
const datagridComponents = root.find(j.JSXElement, {
64+
openingElement: {
65+
name: {
66+
type: 'JSXIdentifier',
67+
name: 'Datagrid',
68+
},
69+
},
70+
});
71+
72+
if (!datagridComponents.length) {
73+
return false;
74+
}
75+
76+
// Replace Datagrid with DataTable
77+
datagridComponents.replaceWith(({ node }) => {
78+
const openingElement = j.jsxOpeningElement(
79+
j.jsxIdentifier('DataTable'),
80+
node.openingElement.attributes,
81+
node.openingElement.selfClosing
82+
);
83+
const closingElement = j.jsxClosingElement(
84+
j.jsxIdentifier('DataTable')
85+
);
86+
return j.jsxElement(openingElement, closingElement, node.children);
87+
});
88+
6289
return true;
6390
};

0 commit comments

Comments
 (0)