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

Add theme, router and current product, React Hooks and HOC to easily access the appropriate data #616

Merged
merged 14 commits into from
Apr 12, 2019

Conversation

devbucket
Copy link
Contributor

Description

In order to easily create custom Routes and access the product data very easily, we added three new React Hooks:

  • useTheme - Provides all theme components that are defined in the Theme API
  • useRoute - Provides all route parameters that are useful for render controlling
  • useCurrentProduct - Provides the current product context information on the Product Detail Page

Additionally all this information can be accessed with HOC:

  • withTheme
  • withRoute
  • withCurrentProduct

Type of change

Please add an "x" into the option that is relevant:

  • Bug Fix 🐛 (non-breaking change which fixes an issue)
  • Enhancement 🚀 (non-breaking change which adds functionality)
  • Breaking Change 💥 (fix or feature that would cause existing functionality to not work as expected)
  • Polish 💅 (Just some cleanups)
  • Internal 🏠 Only relates to internal processes.

@devbucket devbucket added the enhancement New feature or request label Apr 10, 2019
@devbucket devbucket self-assigned this Apr 10, 2019
@coveralls
Copy link

coveralls commented Apr 10, 2019

Pull Request Test Coverage Report for Build 2455

  • 0 of 7 (0.0%) changed or added relevant lines in 3 files are covered.
  • 5 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.05%) to 51.107%

Changes Missing Coverage Covered Lines Changed/Added Lines %
libraries/engage/core/hooks/useRoute.js 0 2 0.0%
libraries/engage/core/hooks/useTheme.js 0 2 0.0%
libraries/engage/core/hooks/useCurrentProduct.js 0 3 0.0%
Files with Coverage Reduction New Missed Lines %
libraries/common/helpers/portals/routePortals.js 5 0.0%
Totals Coverage Status
Change from base Build 2451: -0.05%
Covered Lines: 5784
Relevant Lines: 10696

💛 - Coveralls

…simple-custom-page-route-helper

# Conflicts:
#	extensions/@shopgate-product-reviews/frontend/package.json
#	themes/theme-gmd/package.json
#	themes/theme-ios11/package.json
Copy link
Collaborator

@fkloes fkloes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, this PR doesn't cover the requirement from the story yet. Using both contexts is now really simplified, but one still needs to import and use them explicitly.

What about extending the default Route component with additional props to activate the context injection without importing extra stuff? We could also provide a new component.
I got some feedback from PS, that this could definitely improve the workshops, since they don't need to explain "new" terms like "HOD" or "Hooks".

@@ -140,7 +145,7 @@ export { default as YouTube } from '@shopgate/pwa-common/collections/media-provi

// --------------- CONTEXTS --------------- //

export * from '@shopgate/pwa-common/context';
// export { RouteContext, ThemeContext } from '@shopgate/pwa-common/context';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you replace this line by commented out code? Is it just because externals are now supposed to use the hooks / HOC?
In the recently updated DevDocs we have some articles where import { Theme } from '@shopgate/engage/core'; is used within code snippets. This will not work anymore when the export is gone. So you also need to update the developer center articles with the new patterns from this PR.

@devbucket
Copy link
Contributor Author

I actually talked that through with @sznowicki from PS and we confirmed that this will be the solution to go for.

@fkloes fkloes merged commit fe4ea09 into v6.X Apr 12, 2019
@fkloes fkloes deleted the PWA-1618-Provide-simple-custom-page-route-helper branch April 12, 2019 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants