-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Extract the render component part of RoutePropertiesCard as its own component #2601
refactor: Extract the render component part of RoutePropertiesCard as its own component #2601
Conversation
… its own component
Coverage of commit
|
@@ -224,27 +224,23 @@ const VariantPicker = ({ | |||
} | |||
} | |||
|
|||
const RoutePropertiesCard = ({ | |||
export const RoutePropertiesCardRender = ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would love to come up with a better name for this
const RoutePropertiesCard = ({ | ||
routePatterns, | ||
selectedRoutePatternId, | ||
selectRoutePattern, | ||
onClose, | ||
}: { | ||
routePatterns: ByRoutePatternId<RoutePattern> | ||
selectedRoutePatternId: RoutePatternId | ||
selectRoutePattern: (routePattern: RoutePattern) => void | ||
onClose?: () => void | ||
}) => { | ||
const selectedRoutePattern = routePatterns[selectedRoutePatternId] | ||
const route: Route | null = useRoute(selectedRoutePattern?.routeId) | ||
|
||
if (!route || selectedRoutePattern === undefined) { | ||
return <></> | ||
} | ||
|
||
return ( | ||
<RoutePropertiesCardRender | ||
routePatterns={routePatterns} | ||
route={route} | ||
selectedRoutePattern={selectedRoutePattern} | ||
selectRoutePattern={selectRoutePattern} | ||
onClose={onClose} | ||
/> | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion(non-blocking): What do you think about this? I know it'd cause a diff (:/) in the rest of the application (and the Render
suffix would need to be left off)
const RoutePropertiesCard = ({ | |
routePatterns, | |
selectedRoutePatternId, | |
selectRoutePattern, | |
onClose, | |
}: { | |
routePatterns: ByRoutePatternId<RoutePattern> | |
selectedRoutePatternId: RoutePatternId | |
selectRoutePattern: (routePattern: RoutePattern) => void | |
onClose?: () => void | |
}) => { | |
const selectedRoutePattern = routePatterns[selectedRoutePatternId] | |
const route: Route | null = useRoute(selectedRoutePattern?.routeId) | |
if (!route || selectedRoutePattern === undefined) { | |
return <></> | |
} | |
return ( | |
<RoutePropertiesCardRender | |
routePatterns={routePatterns} | |
route={route} | |
selectedRoutePattern={selectedRoutePattern} | |
selectRoutePattern={selectRoutePattern} | |
onClose={onClose} | |
/> | |
) | |
} | |
const RoutePropertiesCardFromPatternId = ({ | |
routePatterns, | |
selectedRoutePatternId, | |
selectRoutePattern, | |
onClose, | |
}: { | |
routePatterns: ByRoutePatternId<RoutePattern> | |
selectedRoutePatternId: RoutePatternId | |
selectRoutePattern: (routePattern: RoutePattern) => void | |
onClose?: () => void | |
}) => { | |
const selectedRoutePattern = routePatterns[selectedRoutePatternId] | |
const route: Route | null = useRoute(selectedRoutePattern?.routeId) | |
if (!route || selectedRoutePattern === undefined) { | |
return <></> | |
} | |
return ( | |
<RoutePropertiesCardRender | |
routePatterns={routePatterns} | |
route={route} | |
selectedRoutePattern={selectedRoutePattern} | |
selectRoutePattern={selectRoutePattern} | |
onClose={onClose} | |
/> | |
) | |
} | |
RoutePropertiesCard.FromPatternId = RoutePropertiesCardFromPatternId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@firestack just to make sure I understand your suggestion correctly...
My current naming scheme is to extract the rendery bits into <RoutePropertiesCardRender />
and keep <RoutePropertiesCard />
exactly the same.
Your suggestion is, on top of ☝️:
- Change the name of the old component to
<RoutePropertiesCardFromPatternId />
- Name the new rendery component
<RoutePropertiesCard />
And those are the only changes you're suggesting? (If so, then I like it!)
Just double-checking because Github doesn't do suggestion
diffs very well, so ☝️ looks like a huge change!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh hey - it doesn't actually cause a diff with the rest of the app, because of 👇
export default RoutePropertiesCardFromPatternId
…Card as its own component
Coverage of commit
|
…Card as its own component
Coverage of commit
|
…Card as its own component
Coverage of commit
|
…Card as its own component
Coverage of commit
|
Closed in favor of #2609 Turns out the routes are provided by a context, which makes this a lot easier to do without refactoring. |
Marked as a draft PR for now because I want to add a storybook story for this.Storybook story added!
Now it's marked as draft because this might not be the best way to accomplish this goal.