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

DOCSP-5888: Make active tab on navbar dynamic #94

Merged
merged 6 commits into from
Jul 24, 2019
Merged

Conversation

@rayangler rayangler requested a review from sophstad July 10, 2019 18:30
@rayangler rayangler force-pushed the DOCSP-5888 branch 4 times, most recently from 9dc4981 to 03b658f Compare July 11, 2019 21:40
Copy link
Member

@sophstad sophstad left a comment

Choose a reason for hiding this comment

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

Nice work on a tricky problem!

Also, I know we discussed the failing test before and said you could leave it since I will be addressing soon, but I think you should do this instead:

  1. Comment out the test so that all tests are passing
  2. Add a TODO comment there that mentions my ticket number (DOCSP-6123) so we know why it's commented out in the interim

src/constants.js Outdated
guides: ['guides'],
};

export const URL_BASES = {
Copy link
Member

Choose a reason for hiding this comment

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

Calling this URL_SUBDOMAINS would probably clarify what these strings represent.


// Uses location to check which link should be active
checkForLink = location => {
if (location.hostname === 'docs.mongodb.com' || location.hostname === 'docs-mongodbcom-staging.corp.mongodb.com') {
Copy link
Member

Choose a reason for hiding this comment

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

Let's save these URLs as constants outside of the component.

if (location.hostname === 'docs.mongodb.com' || location.hostname === 'docs-mongodbcom-staging.corp.mongodb.com') {
return this.validateActiveLink(location.pathname, '/', URL_SLUGS);
}
if (location.hostname.includes('localhost')) {
Copy link
Member

Choose a reason for hiding this comment

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

A developer may be running the site from the aliased http://localhost:8000/, but they can also do so from http://0.0.0.0:8000/ or http://127.0.0.1:8000. We want to account for all of these potential development URLs.

const slugs = name.split(token);
let slug;
if (slugs[1] === undefined || slugs[1] === '') {
slug = process.env.GATSBY_SITE;
Copy link
Member

Choose a reason for hiding this comment

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

What case is this accounting for? I spent a little time looking into it but never encountered this conditional.

};

// Matches the slug with keys of URL_BASES or URL_SLUGS to return the index it is found
checkKeys = (slug, keys, urlItems) => {
Copy link
Member

Choose a reason for hiding this comment

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

Working with array indexes can get a bit tricky to read and understand down the road. I think this function could be improved by returning the matching slug if found, and null if not. We could simplify the syntax as well:

checkKeys = (slug, urlItems) => {
  const urlMapping = Object.entries(urlItems).find(([, value]) => value.includes(slug));
  return urlMapping ? urlMapping[0] : null;
};

(Unless there was a reason for using indexes from the beginning!)

};

// Static navprops by default
this.navprops = `{"links": [
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity, does everything fail if the object is passed in as an actual object rather than as a string?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If I remember correctly, docs-tools parses data.navprops as a string and throws an error otherwise.

this.navprops = this.modifyActiveLink();

return (
<div>
Copy link
Member

@sophstad sophstad Jul 24, 2019

Choose a reason for hiding this comment

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

Forgot to add this comment yesterday—we probably don't need these surrounding <div>s! If you run into a problem removing them, a Fragment would be a better option.

@rayangler rayangler merged commit 67fe8d0 into master Jul 24, 2019
@rayangler rayangler deleted the DOCSP-5888 branch August 14, 2019 15:23
graysonhicks pushed a commit that referenced this pull request Jan 20, 2023
* DOCSP-5888: Make active tab on navbar dynamic

* Change navbar function logic

* Skip landing page test

* Fix navbar staging bug

* Add Navbar test
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