Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add useCategoryTree talon #1754

Merged
merged 8 commits into from
Sep 27, 2019
Merged

Add useCategoryTree talon #1754

merged 8 commits into from
Sep 27, 2019

Conversation

jimbo
Copy link
Contributor

@jimbo jimbo commented Sep 23, 2019

Description

Add a useCategoryTree mixin to Peregrine, and use it in Venia's CategoryTree component.

@jimbo jimbo added version: Patch This changeset includes backwards compatible bug fixes. pkg:peregrine labels Sep 23, 2019
}
}, [data, updateCategories]);
const mixinProps = useCategoryTree({
categories,
Copy link
Contributor

Choose a reason for hiding this comment

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

I like that you're being explicit here about what you pass to the hook.

@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented Sep 23, 2019

Fails
🚫 Missing "Verification Steps" section. Please add it back, with detail.
🚫

No linked issue found. Please link a relevant open issue by adding the text "closes #<issue_number>" or including the associated JIRA ID in your PR.

Messages
📖

Access a deployed version of this PR here. Make sure to wait for the "pwa-pull-request-deploy" job to complete.

📖 DangerCI Failures related to missing labels/description/linked issues/etc will persist until the next push or next nightly build run (assuming they are fixed).

If your PR is missing information, check against the original template here. At a minimum you must have the section headers from the template and provide some information in each section.

Generated by 🚫 dangerJS against b4a796d

const mixinProps = useCategoryTree({
categories,
categoryId,
query: MENU_QUERY,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a good choice -- provide query via argument rather than importing within hook.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think we have to let people customize the query or else these hooks will quickly lose value. That said, we'll have to find a way to set expectations for what kind of query should be passed in.

sirugh
sirugh previously approved these changes Sep 23, 2019
@@ -0,0 +1,3 @@
export { useCategoryBranch } from './useCategoryBranch';
Copy link
Contributor

Choose a reason for hiding this comment

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

Once we're done with the peregrine refactors I'd like to have one PR where we go through and create these indexes and exports. Right now we're importing with full paths in venia-ui but we can clean all that up with proper exports.

import { useCallback } from 'react';

/**
* Returns props necessary to render a CategoryBranch component.
Copy link
Contributor

Choose a reason for hiding this comment

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

I love these comments. I'm going to go through and update my existing PRs with doc comments as well.

@supernova-at supernova-at changed the title Add useCategoryTree mixin Add useCategoryTree talon Sep 24, 2019
const { onNavigate } = props;

const handleClick = useCallback(() => {
onNavigate();
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't doing anything but wrapping/renaming the function. I think we don't need this talon.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In general, a callback received as a prop shouldn't get directly applied as an event handler. I think it's important to wrap the event handler so that event doesn't get passed to onNavigate; onNavigate should be called with no arguments.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK -- in that case keep your eye out on my PRs cause I think I did not wrap these callbacks in some of my talons.

return childCategories;
}, [categories, children]);

return { childCategories };
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a big fan of not returning the pure data object of these query calls as I think I've done in some of my other talon PRs. This is good and I'll be using this going forward.

@dpatil-magento dpatil-magento merged commit 34dbb1f into develop Sep 27, 2019
@dpatil-magento dpatil-magento deleted the jimbo/mixin-categorytree branch September 27, 2019 18:32
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
pkg:peregrine pkg:venia-ui version: Patch This changeset includes backwards compatible bug fixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants