-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow migrator to target subcomponents and change prop values (#10071)
Closes #10084 First pass at allowing prop values to be changed through migrations. Also needed to allow support for finding compound components in the rename prop migration **Question** Should this be merged into main? Or left in next until it's tested?
- Loading branch information
1 parent
e6a2d35
commit 23c1391
Showing
8 changed files
with
192 additions
and
18 deletions.
There are no files selected for viewing
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,5 @@ | ||
--- | ||
'@shopify/polaris-migrator': minor | ||
--- | ||
|
||
Added support for compound components and adding new prop values in the react-rename-component-prop migration |
23 changes: 23 additions & 0 deletions
23
...ns/react-rename-component-prop/tests/react-rename-component-prop-with-new-value.input.tsx
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,23 @@ | ||
import React from 'react'; | ||
|
||
interface MyComponentProps { | ||
prop?: string; | ||
newProp?: string; | ||
children?: React.ReactNode; | ||
} | ||
|
||
const Child = (props: {prop: string}) => <>{props.prop}</>; | ||
|
||
function MyComponent(props: MyComponentProps) { | ||
const value = props.newProp ?? props.prop; | ||
return <div data-prop={value}>{props.children}</div>; | ||
} | ||
|
||
export function App() { | ||
return ( | ||
<MyComponent prop="value"> | ||
Hello | ||
<Child prop="value" /> | ||
</MyComponent> | ||
); | ||
} |
23 changes: 23 additions & 0 deletions
23
...s/react-rename-component-prop/tests/react-rename-component-prop-with-new-value.output.tsx
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,23 @@ | ||
import React from 'react'; | ||
|
||
interface MyComponentProps { | ||
prop?: string; | ||
newProp?: string; | ||
children?: React.ReactNode; | ||
} | ||
|
||
const Child = (props: {prop: string}) => <>{props.prop}</>; | ||
|
||
function MyComponent(props: MyComponentProps) { | ||
const value = props.newProp ?? props.prop; | ||
return <div data-prop={value}>{props.children}</div>; | ||
} | ||
|
||
export function App() { | ||
return ( | ||
<MyComponent newProp="new value"> | ||
Hello | ||
<Child prop="value" /> | ||
</MyComponent> | ||
); | ||
} |
30 changes: 30 additions & 0 deletions
30
...rename-component-prop/tests/react-rename-compound-component-prop-with-new-value.input.tsx
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,30 @@ | ||
import React from 'react'; | ||
|
||
interface MyComponentProps { | ||
prop?: string; | ||
newProp?: string; | ||
children?: React.ReactNode; | ||
} | ||
|
||
const Child = (props: {prop: string}) => <>{props.prop}</>; | ||
|
||
function MyComponent(props: MyComponentProps) { | ||
const value = props.newProp ?? props.prop; | ||
return <div data-prop={value}>{props.children}</div>; | ||
} | ||
|
||
function SubComponent({...props}: any) { | ||
return <div {...props} />; | ||
} | ||
|
||
export function App() { | ||
return ( | ||
<MyComponent> | ||
<MyComponent.SubComponent prop="value" /> | ||
Hello | ||
<Child prop="value" /> | ||
</MyComponent> | ||
); | ||
} | ||
|
||
MyComponent.SubComponent = SubComponent; |
30 changes: 30 additions & 0 deletions
30
...ename-component-prop/tests/react-rename-compound-component-prop-with-new-value.output.tsx
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,30 @@ | ||
import React from 'react'; | ||
|
||
interface MyComponentProps { | ||
prop?: string; | ||
newProp?: string; | ||
children?: React.ReactNode; | ||
} | ||
|
||
const Child = (props: {prop: string}) => <>{props.prop}</>; | ||
|
||
function MyComponent(props: MyComponentProps) { | ||
const value = props.newProp ?? props.prop; | ||
return <div data-prop={value}>{props.children}</div>; | ||
} | ||
|
||
function SubComponent({...props}: any) { | ||
return <div {...props} />; | ||
} | ||
|
||
export function App() { | ||
return ( | ||
<MyComponent> | ||
<MyComponent.SubComponent newProp="new value" /> | ||
Hello | ||
<Child prop="value" /> | ||
</MyComponent> | ||
); | ||
} | ||
|
||
MyComponent.SubComponent = SubComponent; |
35 changes: 29 additions & 6 deletions
35
polaris-migrator/src/migrations/react-rename-component-prop/tests/transform.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 |
---|---|---|
@@ -1,16 +1,39 @@ | ||
import {check} from '../../../utilities/check'; | ||
|
||
const transform = 'react-rename-component-prop'; | ||
const fixtures = ['react-rename-component-prop']; | ||
|
||
for (const fixture of fixtures) { | ||
check(__dirname, { | ||
fixture, | ||
transform, | ||
const fixtures = [ | ||
{ | ||
name: 'react-rename-component-prop', | ||
options: { | ||
componentName: 'MyComponent', | ||
from: 'prop', | ||
to: 'newProp', | ||
}, | ||
}, | ||
{ | ||
name: 'react-rename-component-prop-with-new-value', | ||
options: { | ||
componentName: 'MyComponent', | ||
from: 'prop', | ||
to: 'newProp', | ||
newValue: 'new value', | ||
}, | ||
}, | ||
{ | ||
name: 'react-rename-compound-component-prop-with-new-value', | ||
options: { | ||
componentName: 'MyComponent.SubComponent', | ||
from: 'prop', | ||
to: 'newProp', | ||
newValue: 'new value', | ||
}, | ||
}, | ||
]; | ||
|
||
for (const fixture of fixtures) { | ||
check(__dirname, { | ||
fixture: fixture.name, | ||
transform, | ||
options: fixture.options, | ||
}); | ||
} |
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
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