Skip to content
This repository was archived by the owner on Sep 30, 2025. It is now read-only.

Commit ea6b542

Browse files
Handle buttonFrom function in migration (#10575)
### WHY are these changes introduced? Resolves #10260 ### WHAT is this pull request doing? Adds a comment for manual migration of usages of the `buttonFrom` function. There are approximately 100 usages of it in `web` so handling these manually is quicker than trying to write a codemod for them. --------- Co-authored-by: Aaron Casanova <32409546+aaronccasanova@users.noreply.github.com>
1 parent c232efa commit ea6b542

File tree

4 files changed

+82
-3
lines changed

4 files changed

+82
-3
lines changed

.changeset/dull-dingos-collect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris-migrator': patch
3+
---
4+
5+
Handled `buttonFrom` and `buttonsFrom` functions in `Button` migration
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {buttonFrom, buttonsFrom} from '@shopify/polaris';
2+
3+
const myButtonFrom = buttonFrom;
4+
5+
export function App() {
6+
const primaryFooterActionMarkup = buttonFrom(
7+
{content: 'Edit', onAction: () => {}},
8+
{
9+
primary: true,
10+
},
11+
);
12+
13+
const myButtonMarkup = myButtonFrom(
14+
{content: 'Edit', onAction: () => {}},
15+
{
16+
primary: true,
17+
},
18+
);
19+
20+
const multipleButtonsMarkup = buttonsFrom(
21+
{content: 'Edit', onAction: () => {}},
22+
{
23+
primary: true,
24+
},
25+
);
26+
27+
return primaryFooterActionMarkup;
28+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {buttonFrom} from '@shopify/polaris';
2+
3+
const myButtonFrom =
4+
/* polaris-migrator: Unable to migrate the following expression. Please upgrade manually. */
5+
buttonFrom;
6+
7+
export function App() {
8+
const primaryFooterActionMarkup =
9+
/* polaris-migrator: Unable to migrate the following expression. Please upgrade manually. */
10+
buttonFrom(
11+
{content: 'Edit', onAction: () => {}},
12+
{
13+
primary: true,
14+
},
15+
);
16+
17+
const myButtonMarkup = myButtonFrom(
18+
{content: 'Edit', onAction: () => {}},
19+
{
20+
primary: true,
21+
},
22+
);
23+
24+
const multipleButtonsMarkup =
25+
/* polaris-migrator: Unable to migrate the following expression. Please upgrade manually. */
26+
buttonsFrom(
27+
{content: 'Edit', onAction: () => {}},
28+
{
29+
primary: true,
30+
},
31+
);
32+
33+
return primaryFooterActionMarkup;
34+
}

polaris-migrator/src/migrations/v12-react-update-button-component/transform.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,27 @@ export default function transformer(
2222
) {
2323
const source = j(fileInfo.source);
2424

25-
// If `Button` component name is not imported, exit
25+
// If `Button` component name or `buttonFrom` function is not imported, exit
2626
if (
2727
!(
2828
hasImportDeclaration(j, source, '@shopify/polaris') &&
2929
(hasImportSpecifier(j, source, 'Button', '@shopify/polaris') ||
30-
hasImportSpecifier(j, source, 'ButtonProps', '@shopify/polaris'))
30+
hasImportSpecifier(j, source, 'ButtonProps', '@shopify/polaris') ||
31+
hasImportSpecifier(j, source, 'buttonFrom', '@shopify/polaris') ||
32+
hasImportSpecifier(j, source, 'buttonsFrom', '@shopify/polaris'))
3133
)
3234
) {
3335
return fileInfo.source;
3436
}
3537

38+
const localFunctionName =
39+
getImportSpecifierName(j, source, 'buttonFrom', '@shopify/polaris') ||
40+
'buttonFrom';
41+
42+
const localFunctionPluralName =
43+
getImportSpecifierName(j, source, 'buttonsFrom', '@shopify/polaris') ||
44+
'buttonsFrom';
45+
3646
const localElementName =
3747
getImportSpecifierName(j, source, 'Button', '@shopify/polaris') || 'Button';
3848

@@ -308,7 +318,9 @@ export default function transformer(
308318
.filter(
309319
(path) =>
310320
path.node.name === localElementName ||
311-
path.node.name === localElementTypeName,
321+
path.node.name === localElementTypeName ||
322+
path.node.name === localFunctionName ||
323+
path.node.name === localFunctionPluralName,
312324
)
313325
.forEach((path) => {
314326
if (path.node.type !== 'Identifier') return;

0 commit comments

Comments
 (0)