forked from Shopify/polaris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix rename prop migration (Shopify#10215)
### WHY are these changes introduced? `react-rename-component-prop` migration was not working as expected when there were multiple props on a component <img width="552" alt="Screenshot 2023-08-24 at 10 12 10 AM" src="https://github.com/Shopify/polaris/assets/3474483/5ca5de71-f587-49cf-87ea-5fc73d298864"> ### WHAT is this pull request doing? - Adds more test cases - Fixes migration <img width="590" alt="Screenshot 2023-08-24 at 10 12 35 AM" src="https://github.com/Shopify/polaris/assets/3474483/8dc1ee41-1900-4383-81e0-7635b2d2fa0b"> --------- Co-authored-by: Aaron Casanova <32409546+aaronccasanova@users.noreply.github.com>
- Loading branch information
1 parent
2deb216
commit 3d4ef92
Showing
11 changed files
with
61 additions
and
91 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': patch | ||
--- | ||
|
||
Fixed a bug in the rename prop migration |
11 changes: 11 additions & 0 deletions
11
...ions/react-rename-component-prop/tests/react-rename-component-prop-with-boolean.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,11 @@ | ||
import React from 'react'; | ||
|
||
declare function MyComponent(props: any): JSX.Element; | ||
|
||
export function App() { | ||
return ( | ||
<MyComponent foo="bar" booleanProp> | ||
Hello world | ||
</MyComponent> | ||
); | ||
} |
11 changes: 11 additions & 0 deletions
11
...ons/react-rename-component-prop/tests/react-rename-component-prop-with-boolean.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,11 @@ | ||
import React from 'react'; | ||
|
||
declare function MyComponent(props: any): JSX.Element; | ||
|
||
export function App() { | ||
return ( | ||
<MyComponent foo="bar" variant="boolean-prop-value"> | ||
Hello world | ||
</MyComponent> | ||
); | ||
} |
14 changes: 2 additions & 12 deletions
14
...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
16 changes: 3 additions & 13 deletions
16
...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
16 changes: 3 additions & 13 deletions
16
...or/src/migrations/react-rename-component-prop/tests/react-rename-component-prop.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
16 changes: 3 additions & 13 deletions
16
...r/src/migrations/react-rename-component-prop/tests/react-rename-component-prop.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
23 changes: 5 additions & 18 deletions
23
...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 |
---|---|---|
@@ -1,30 +1,17 @@ | ||
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>; | ||
} | ||
declare function MyComponent(props: any): JSX.Element; | ||
declare function CompoundComponent(props: any): JSX.Element; | ||
declare function Child(props: any): JSX.Element; | ||
|
||
function SubComponent({...props}: any) { | ||
return <div {...props} />; | ||
} | ||
MyComponent.CompoundComponent = CompoundComponent; | ||
|
||
export function App() { | ||
return ( | ||
<MyComponent> | ||
<MyComponent.SubComponent prop="value" /> | ||
<MyComponent.CompoundComponent prop="value" /> | ||
Hello | ||
<Child prop="value" /> | ||
</MyComponent> | ||
); | ||
} | ||
|
||
MyComponent.SubComponent = SubComponent; |
23 changes: 5 additions & 18 deletions
23
...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 |
---|---|---|
@@ -1,30 +1,17 @@ | ||
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>; | ||
} | ||
declare function MyComponent(props: any): JSX.Element; | ||
declare function CompoundComponent(props: any): JSX.Element; | ||
declare function Child(props: any): JSX.Element; | ||
|
||
function SubComponent({...props}: any) { | ||
return <div {...props} />; | ||
} | ||
MyComponent.CompoundComponent = CompoundComponent; | ||
|
||
export function App() { | ||
return ( | ||
<MyComponent> | ||
<MyComponent.SubComponent newProp="new value" /> | ||
<MyComponent.CompoundComponent newProp="new-value" /> | ||
Hello | ||
<Child prop="value" /> | ||
</MyComponent> | ||
); | ||
} | ||
|
||
MyComponent.SubComponent = SubComponent; |
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