Skip to content
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

Closed

Conversation

joshlarson
Copy link
Contributor

@joshlarson joshlarson commented May 17, 2024

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.

@joshlarson joshlarson requested a review from a team as a code owner May 17, 2024 20:51
@joshlarson joshlarson marked this pull request as draft May 17, 2024 20:52
Copy link

Coverage of commit c442f26

Summary coverage rate:
  lines......: 93.6% (3241 of 3464 lines)
  functions..: 73.3% (1340 of 1827 functions)
  branches...: no data found

Files changed coverage rate: n/a

Download coverage report

@@ -224,27 +224,23 @@ const VariantPicker = ({
}
}

const RoutePropertiesCard = ({
export const RoutePropertiesCardRender = ({
Copy link
Contributor Author

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

Comment on lines 317 to 344
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}
/>
)
}
Copy link
Member

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)

Suggested change
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

Copy link
Contributor Author

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!

Copy link
Contributor Author

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

Copy link

Coverage of commit cb3ceb7

Summary coverage rate:
  lines......: 93.7% (3247 of 3464 lines)
  functions..: 73.3% (1340 of 1827 functions)
  branches...: no data found

Files changed coverage rate: n/a

Download coverage report

@joshlarson joshlarson marked this pull request as ready for review May 20, 2024 14:46
Copy link

Coverage of commit eb13d97

Summary coverage rate:
  lines......: 93.6% (3241 of 3464 lines)
  functions..: 73.3% (1340 of 1827 functions)
  branches...: no data found

Files changed coverage rate: n/a

Download coverage report

Copy link

Coverage of commit d652d96

Summary coverage rate:
  lines......: 93.6% (3242 of 3465 lines)
  functions..: 73.4% (1341 of 1828 functions)
  branches...: no data found

Files changed coverage rate: n/a

Download coverage report

Copy link

Coverage of commit 9b35511

Summary coverage rate:
  lines......: 93.6% (3242 of 3465 lines)
  functions..: 73.4% (1341 of 1828 functions)
  branches...: no data found

Files changed coverage rate: n/a

Download coverage report

@joshlarson joshlarson marked this pull request as draft May 20, 2024 15:23
@joshlarson
Copy link
Contributor Author

Closed in favor of #2609

Turns out the routes are provided by a context, which makes this a lot easier to do without refactoring.

@joshlarson joshlarson closed this May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants