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

Implement Search in Peregrine #1078

Merged
merged 2 commits into from
May 6, 2019
Merged

Implement Search in Peregrine #1078

merged 2 commits into from
May 6, 2019

Conversation

jimbo
Copy link
Contributor

@jimbo jimbo commented Mar 27, 2019

Description

Primary changes

  • Rewrite SearchBar and its subcomponents to use hooks
  • Extract some functionality into custom hooks
  • Add custom hooks to peregrine (listed below)

Other changes

  • Upgrade informed from 1.10.12 to 2.1.13
  • Fix components and tests after upgrading informed
  • Upgrade react-apollo from 2.4.1 to 2.5.3
  • List react-apollo as a peer dependency of peregrine
  • Upgrade react-test-renderer from 16.8.3 to 16.8.6
  • List react-test-renderer as a dev dependency of peregrine
  • Create a utility to wrap TestRenderer.create() with act()
  • Export mergeClasses from classify
  • Fix Jest config for CI

New custom hooks

Hook Role
useApolloContext Get Apollo client from context
useDocumentListener Add an event listener on mount; remove it on unmount
useDropdown Manage dropdown component state
useQuery Get a callback to perform an Apollo query and its results
useQueryResult Manage Apollo query result state
useValueFromSearchParams Call a callback (e.g., setValue) with the value of a search param

File overview

Type Count
component 9
custom hook 6
utility 5
index/adapter 3
style 6
test 16
mock 2
snapshot 7
package 3
config 1

Related Issue

Closes #1062.

Motivation and Context

We're starting to move some Venia components to Peregrine, and in the process we'll be extracting as much of their functionality as possible into hooks. Peregrine currently doesn't share a lot of dependencies with Venia, but it's going to have to pick some of them up as a result of this work.

Here's the big question: given a Venia component, should we extract all of its functionality (i.e., everything before the return statement) into a custom hook and move that hook into Peregrine? If we do, end users can use the hook to render fully custom structure, similar to render props. Just like render props, though, the API of such a hook (what inputs it expects, and what output it returns) would be unique, so you'd have to consult documentation or source code to use it. Also, naming such a hook can be challenging.

@vercel
Copy link

vercel bot commented Mar 27, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

@vercel vercel bot temporarily deployed to staging April 3, 2019 22:35 Inactive
@jimbo jimbo force-pushed the jimbo/searchbar branch from dca6255 to 857b0e0 Compare April 3, 2019 23:03
@jimbo jimbo removed the in progress label Apr 16, 2019
@jimbo jimbo changed the title [WIP] Implement Search in Peregrine Implement Search in Peregrine Apr 16, 2019
@jimbo jimbo force-pushed the jimbo/searchbar branch from 22b7e93 to e600c7c Compare April 16, 2019 22:28
Copy link
Contributor

@supernova-at supernova-at left a comment

Choose a reason for hiding this comment

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

Looked over the recent changes, I think it looks great.

I resolved all of my conversations that warranted it, so there's only a few outstanding questions / issues that folks had.

Feel free to resolve conversations, if I had a question on whether something had been resolved or not I left it open to be safe.

Copy link
Contributor

@zetlen zetlen left a comment

Choose a reason for hiding this comment

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

Thanks for the clarifications. I understand your listener hooks better now. The only reason I'm not approving this is followups on two comments for small renames/reorgs. Everything else looks great.

useEffect(() => {
setValue(value);
}, [setValue, value]);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

@jimbo What do you think of changing this hook's name?

});

return instance;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

@jimbo Is it safe to delete this utility since it's in Peregrine now?

@jimbo
Copy link
Contributor Author

jimbo commented May 2, 2019

Regarding the name of useValueFromSearchParams(): yes, we can rename it. What should we call it, given that it accepts a param (key), retrieves the corresponding value from search params, and calls a callback, setValue(), with that value?

Regarding createTestInstance(): yes, we can change the Venia tests to use the version from Peregrine.

@zetlen
Copy link
Contributor

zetlen commented May 3, 2019

@jimbo How about useUrlSearchParameters?

@jimbo jimbo merged commit d3c0964 into develop May 6, 2019
@supernova-at supernova-at mentioned this pull request May 6, 2019
5 tasks
@sirugh sirugh added the version: Major This changeset includes incompatible API changes and its release necessitates a Major version bump. label May 24, 2019
@jimbo jimbo deleted the jimbo/searchbar branch July 25, 2019 21:27
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
version: Major This changeset includes incompatible API changes and its release necessitates a Major version bump.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Peregrine: Search Bar Component
6 participants