-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
113 additions
and
25 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
packages/blade/codemods/brand-refresh/transformers/__tests__/migrate-table.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { applyTransform } from '@hypermod/utils'; | ||
import * as transformer from '..'; | ||
|
||
it('should migrate the ActionList component', async () => { | ||
const result = await applyTransform( | ||
transformer, | ||
` | ||
const App = () => ( | ||
<> | ||
<Table {...args} data={data} surfaceLevel={3}> | ||
{(tableData) => ( | ||
<> | ||
<TableHeader> | ||
<TableHeaderRow> | ||
<TableHeaderCell headerKey="PAYMENT_ID">ID</TableHeaderCell> | ||
<TableHeaderCell headerKey="AMOUNT">Amount</TableHeaderCell> | ||
<TableHeaderCell headerKey="ACCOUNT">Account</TableHeaderCell> | ||
</TableHeaderRow> | ||
</TableHeader> | ||
<TableBody> | ||
{tableData.map((tableItem, index) => ( | ||
<TableRow key={index} item={tableItem}> | ||
<TableCell> | ||
<Code size="medium">{tableItem.paymentId}</Code> | ||
</TableCell> | ||
<TableCell> | ||
<Amount value={tableItem.amount} /> | ||
</TableCell> | ||
<TableCell>{tableItem.account}</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</> | ||
)} | ||
</Table> | ||
</> | ||
); | ||
`, | ||
{ parser: 'tsx' }, | ||
); | ||
|
||
expect(result).toMatchInlineSnapshot(` | ||
"const App = () => ( | ||
<> | ||
<Table {...args} data={data}> | ||
{(tableData) => ( | ||
<> | ||
<TableHeader> | ||
<TableHeaderRow> | ||
<TableHeaderCell headerKey="PAYMENT_ID">ID</TableHeaderCell> | ||
<TableHeaderCell headerKey="AMOUNT">Amount</TableHeaderCell> | ||
<TableHeaderCell headerKey="ACCOUNT">Account</TableHeaderCell> | ||
</TableHeaderRow> | ||
</TableHeader> | ||
<TableBody> | ||
{tableData.map((tableItem, index) => ( | ||
<TableRow key={index} item={tableItem}> | ||
<TableCell> | ||
<Code size="medium">{tableItem.paymentId}</Code> | ||
</TableCell> | ||
<TableCell> | ||
<Amount value={tableItem.amount} /> | ||
</TableCell> | ||
<TableCell>{tableItem.account}</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</> | ||
)} | ||
</Table> | ||
</> | ||
);" | ||
`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/blade/codemods/brand-refresh/transformers/migrate-actionlist-and-table.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { red } from './utils'; | ||
|
||
function migrateActionListAndTable({ root, j, file }): void { | ||
// ActionList & Table components: Remove the `surfaceLevel` prop | ||
// <ActionList surfaceLevel={2}> -> <ActionList > | ||
// <Table surfaceLevel={2}> -> <Table > | ||
try { | ||
root | ||
.find(j.JSXElement) | ||
.filter( | ||
(path) => | ||
path.value.openingElement.name.name === 'ActionList' || | ||
path.value.openingElement.name.name === 'Table', | ||
) | ||
.find(j.JSXAttribute) | ||
.filter((path) => path.node.name.name === 'surfaceLevel') | ||
.remove(); | ||
} catch (error) { | ||
console.error( | ||
red( | ||
`⛔️ ${file.path}: Oops! Ran into an issue while removing the "surfaceLevel" prop from "ActionList"/"Table".`, | ||
), | ||
`\n${red(error.stack)}\n`, | ||
); | ||
} | ||
} | ||
|
||
export default migrateActionListAndTable; |
23 changes: 0 additions & 23 deletions
23
packages/blade/codemods/brand-refresh/transformers/migrate-actionlist.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters