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(catalog): introduce usePathname hook, remove React Router dependency from the Catalog #1276

Merged
merged 2 commits into from
Nov 28, 2024

Conversation

vgeorge
Copy link
Contributor

@vgeorge vgeorge commented Nov 26, 2024

Related Ticket: Contributes to #1108

Description of Changes

  • Remove react-router dependency from the Catalog components
  • Introduce custom usePathname hook
  • Remove prop drilling of pathname from the Catalog

Notes & Questions About Changes

The pathname prop is passed down for two things:

  1. Generating a link to the dataset at
    const linkTo = getDatasetPath(dataset, pathname);
  2. Controlling scroll in the filters control at
    const { isHeaderHidden, wrapperHeight } = useSlidingStickyHeader(pathname);

I suspect that the usage on item 1 was intented to cover the use case of an instance running on a subpath (e.g. https://myinstance.org/veda), why is hard to replicate locally but this change shouldn't affect that.

Validation / Testing

Using veda-config:

  1. Visit the data catalog page
  2. Clicking on cards should open the proper URL (same as before)
  3. Visit Explorer page, clicking on cards selected them, instead of visiting an URL (same as before)

Using next-veda-ui instance:

  1. Link the source of this PR to the Next.js instance
  2. Visit the catalog page
  3. Clicking on cards should open the proper URL (same as before)
  4. Visit Explorer page, clicking on cards selected them, instead of visiting an URL (same as before)

This is ready for review.

Copy link

netlify bot commented Nov 26, 2024

Deploy Preview for veda-ui ready!

Name Link
🔨 Latest commit 2807db6
🔍 Latest deploy log https://app.netlify.com/sites/veda-ui/deploys/6745e5e9a24e4e0009eac349
😎 Deploy Preview https://deploy-preview-1276--veda-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@vgeorge
Copy link
Contributor Author

vgeorge commented Nov 26, 2024

The ts-check failure made me realized this is also used in the datasets modal in the Exploration page. I added a fix and udpated the validation steps above.

Copy link
Collaborator

@dzole0311 dzole0311 left a comment

Choose a reason for hiding this comment

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

I tested the changes in both the Veda UI and the Next.js repository as well as on the GHG Center side. Everything works as expected with no regressions.

* @returns {string} The current `pathname`. Returns an empty string during SSR
* or if the `window` object is unavailable.
*/
export const usePathname = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@dzole0311
Copy link
Collaborator

I suspect that the usage on item 1 was intented to cover the use case of an instance running on a subpath (e.g. https://myinstance.org/veda), why is hard to replicate locally but this change shouldn't affect that.

Yeah, that seems likely. For example the GHG Center instance is running under https://earth.gov/ghgcenter/ subpath and the Veda routes are appended to it.

@vgeorge
Copy link
Contributor Author

vgeorge commented Nov 28, 2024

@dzole0311 thanks for the review! Let's keep an eye on that instance once we roll out the changes.

@vgeorge vgeorge merged commit 7233df8 into main Nov 28, 2024
9 checks passed
@vgeorge vgeorge deleted the refactor/remove-use-location-dep-from-catalog branch November 28, 2024 10:49
@snmln snmln mentioned this pull request Dec 6, 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