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 autogenerated breadcrumbs component #2193

Merged
merged 44 commits into from
Apr 1, 2023
Merged

Conversation

itsyme
Copy link
Contributor

@itsyme itsyme commented Mar 1, 2023

What is the purpose of this pull request?

  • Documentation update
  • Bug fix
  • Feature addition or enhancement
  • Code maintenance
  • DevOps
  • Improve developer experience
  • Others, please explain:

Overview of changes:
Resolves #2094.

Anything you'd like to highlight/discuss:

Testing instructions:

Proposed commit message: (wrap lines at 72 characters)

Add autogenerated breadcrumbs component


Checklist: ☑️

  • Updated the documentation for feature additions and enhancements
  • Added tests for bug fixes or features
  • Linked all related issues
  • No unrelated changes

@itsyme
Copy link
Contributor Author

itsyme commented Mar 13, 2023

I managed to do it looking at the site-nav DOM, however I am currently trying to iron out 2 bugs:

  1. For the sitenav sections with only a dropdown (i.e. clicking on it only expands the dropdown), the breadcrumb is returning the first link instead of the dropdown. I can fix this if I can find a way to differentiate between only dropdown sections and dropdown with page sections
  2. The breadcrumbs do not show for some pages and I cannot explain why. When I print the items array used to store the data for the breadcrumbs, it prints an empty array. I will have to look further into this to find out the root cause.

Would appreciate any feedback/suggestions!

@ong6
Copy link
Contributor

ong6 commented Mar 13, 2023

@itsyme Good work with the PR so far!

For the sitenav sections with only a dropdown (i.e. clicking on it only expands the dropdown), the breadcrumb is returning the first link instead of the dropdown. I can fix this if I can find a way to differentiate between only dropdown sections and dropdown with page sections

Maybe we can try to check this by looking if the dropdown has a link or not? if the dropdown has a link just link to it, else we just look at the first link.

The breadcrumbs do not show for some pages and I cannot explain why. When I print the items array used to store the data for the breadcrumbs, it prints an empty array. I will have to look further into this to find out the root cause.

Not sure what could be causing this issue but it might be the following?

  1. We're using the document.querySelectorAll to find the site navigation. But what if the site nav is somehow not in the ul element with the class site-nav-list-root.
  2. The site navigation structure is not consistent across all pages

@itsyme
Copy link
Contributor Author

itsyme commented Mar 14, 2023

@itsyme Good work with the PR so far!

For the sitenav sections with only a dropdown (i.e. clicking on it only expands the dropdown), the breadcrumb is returning the first link instead of the dropdown. I can fix this if I can find a way to differentiate between only dropdown sections and dropdown with page sections

Maybe we can try to check this by looking if the dropdown has a link or not? if the dropdown has a link just link to it, else we just look at the first link.

The breadcrumbs do not show for some pages and I cannot explain why. When I print the items array used to store the data for the breadcrumbs, it prints an empty array. I will have to look further into this to find out the root cause.

Not sure what could be causing this issue but it might be the following?

  1. We're using the document.querySelectorAll to find the site navigation. But what if the site nav is somehow not in the ul element with the class site-nav-list-root.
  2. The site navigation structure is not consistent across all pages

Hi @ong6! Thanks for the suggestions! I managed to fix the second issue with some breadcrumbs not appearing. It seems that for some site-navs in different pages, there seems to be two uls with site-nav-list-root, even if they are in the same tier in the site-nav.

e.g. UG -> Authoring Contents -> Reusing Contents has 1 site-nav-list-roots but UG -> Authoring Contents -> Tweaking the page structure has 2.

Similarly, UG -> Authoring Contents -> Using Components -> Navigation has 2 but UG -> Authoring Contents -> Using Components -> The Rest has 1.

Do you think this could be a potential bug in the site-nav or if it intentionally made this way?

@itsyme
Copy link
Contributor Author

itsyme commented Mar 15, 2023

The breadcrumbs works now! Just some small issues to iron out. I was wondering if we should visually distinguish between breadcrumbs that are clickable and those that are not. Currently, I do not distinguish between them as it made the breadcrumbs look messy.

Also, do we want to have a toggle for breadcrumbs in the frontmatter or just have the user add the breadcrumb component into their layout as the toggle?

@itsyme itsyme marked this pull request as ready for review March 15, 2023 01:24
@jovyntls
Copy link
Contributor

I was wondering if we should visually distinguish between breadcrumbs that are clickable and those that are not.

Ideally yes, but I agree that it may look messy. I can't think of a cleaner way to go about this besides having the usual cursor-hover behaviour on links.

Also, do we want to have a toggle for breadcrumbs in the frontmatter or just have the user add the breadcrumb component into their layout as the toggle?

I think both are viable! Adding the breadcrumbs component into their layout that could offer users more flexibility and allow them to include it in the default layout. On the other hand, 90% of the time the breadcrumbs are probably in the same place, so having it as a frontmatter toggle could be more convenient.

I'm leaning towards having it as a component to include in layouts since this aligns more with how we support other features like pageNavs, etc.

@itsyme
Copy link
Contributor Author

itsyme commented Mar 15, 2023

I was wondering if we should visually distinguish between breadcrumbs that are clickable and those that are not.

Ideally yes, but I agree that it may look messy. I can't think of a cleaner way to go about this besides having the usual cursor-hover behaviour on links.

Also, do we want to have a toggle for breadcrumbs in the frontmatter or just have the user add the breadcrumb component into their layout as the toggle?

I think both are viable! Adding the breadcrumbs component into their layout that could offer users more flexibility and allow them to include it in the default layout. On the other hand, 90% of the time the breadcrumbs are probably in the same place, so having it as a frontmatter toggle could be more convenient.

I'm leaning towards having it as a component to include in layouts since this aligns more with how we support other features like pageNavs, etc.

Thanks for the feedback! I am doing the documentation for Breadcrumbs now and am wondering if I should put it under "Navigation" or "Others". I am leaning towards "Others" as the "Navigation" section is already very long and breadcrumbs is more a peripheral component rather than a core navigation component. What do you think?

@lhw-1
Copy link
Contributor

lhw-1 commented Mar 15, 2023

I am doing the documentation for Breadcrumbs now and am wondering if I should put it under "Navigation" or "Others". I am leaning towards "Others" as the "Navigation" section is already very long and breadcrumbs is more a peripheral component rather than a core navigation component. What do you think?

Hi @itsyme, thanks for the PR! I personally think that since breadcrumbs fundamentally still has to do with navigation between pages, I think putting it under the "Navigation" section still makes more sense than "Others". (As a side note, I feel like we can afford to also rename the "Others" into "Questions and Quizzes" since there's only those components described in the "Others" section)

@damithc
Copy link
Contributor

damithc commented Mar 15, 2023

@itsyme For new features, also good to try them out on CS2103/T website as that's the heaviest MarkBind site we have now.
e.g., https://github.com/nus-cs2103-AY2223S2/website
Check how the new feature affects various pages, including the the textbook (https://nus-cs2103-ay2223s2.github.io/website/se-book-adapted/index.html), printer-friendly pages in particular.

@ong6
Copy link
Contributor

ong6 commented Mar 15, 2023

The breadcrumbs works now! Just some small issues to iron out. I was wondering if we should visually distinguish between breadcrumbs that are clickable and those that are not. Currently, I do not distinguish between them as it made the breadcrumbs look messy.

Great work so far! What do you think about leaving those unclickable links out of the breadcrumbs completely. (don't show them all together.) My reasoning for this is because breadcrumbs are used mainly for navigation and if there is no link, perhaps there is no need to show them since they can't navigate to it anyways.

Also, do we want to have a toggle for breadcrumbs in the frontmatter or just have the user add the breadcrumb component into their layout as the toggle?

I agree with Jovyn on this point. Leaving it in layouts seems right.

@tlylt
Copy link
Contributor

tlylt commented Mar 15, 2023

Can you also share what it looks like for longer-than-usual titles (hence a longer breadcrumb), to see if it handles that well?

@itsyme
Copy link
Contributor Author

itsyme commented Mar 15, 2023

Great work so far! What do you think about leaving those unclickable links out of the breadcrumbs completely. (don't show them all together.) My reasoning for this is because breadcrumbs are used mainly for navigation and if there is no link, perhaps there is no need to show them since they can't navigate to it anyways.

I think that leaving the unclickable links out might reduce the value that the breadcrumbs bring to the user.

I find the unclickable links being displayed helps the user to track which section they currently are more easily, even if the links do not direct them to a page on click.

Also, much of the sitenav dropdowns (that I have seen so far) do not contain a page. This could lead to our breadcrumb displaying only the current page majority of the time. What do you think?

@itsyme itsyme requested a review from jovyntls March 28, 2023 06:50
Copy link
Contributor

@jovyntls jovyntls left a comment

Choose a reason for hiding this comment

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

Thanks @itsyme , the component is working well!

Is it possible to add tests for generating the items array from the siteNav, since the current tests stub the items array?

I'm also wondering if we should add this to the default template 🤔 What do you think?

docs/userGuide/syntax/breadcrumbs.md Outdated Show resolved Hide resolved
@@ -0,0 +1,102 @@
<template>
<div>
<nav aria-label="breadcrumb">
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a really nice & thoughtful accessibility consideration! Same for the aria-current below 👍

packages/vue-components/src/Breadcrumb.vue Outdated Show resolved Hide resolved

// Identify the first site-nav-list-root
// In the ideal case, there is only one site-nav-list-root
// however this is not the case for all pages
Copy link
Contributor

Choose a reason for hiding this comment

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

:O just checking, would the other site-nav-list-root be a duplicate? Or is it possible to have multiple site-nav-list-root with different contents?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From my experience, the other site-nav-list-root is a subset of the current sitenav. I feel like this is unexpected behaviour as ideally there should only be one site-nav-list-root

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have found out why the bug is happening! I realised that the navigation page has an example sitenav in the page, resulting in the weird behaviour.

packages/vue-components/src/Breadcrumb.vue Outdated Show resolved Hide resolved
packages/vue-components/src/Breadcrumb.vue Show resolved Hide resolved
packages/vue-components/src/Breadcrumb.vue Outdated Show resolved Hide resolved
packages/vue-components/src/Breadcrumb.vue Outdated Show resolved Hide resolved
@jovyntls
Copy link
Contributor

Not a big issue, but I'm getting a weird jerky change of the cursor when moving to an .active class:

I'm fine with removing the class entirely since having the cursor as a caret when hovering over text seems reasonable to me, given that that's the standard cursor behaviour.

Screen.Recording.2023-03-28.at.9.43.29.PM.mov

@itsyme
Copy link
Contributor Author

itsyme commented Mar 29, 2023

Thanks @itsyme , the component is working well!

Is it possible to add tests for generating the items array from the siteNav, since the current tests stub the items array?

I'm also wondering if we should add this to the default template 🤔 What do you think?

Thanks for the review @jovyntls! I was having some issues with the tests with siteNav and might need some time to work it to get them to work. I will try to get it done ASAP! As for the default template, I think it would be a great addition! I will add it in the next commit!

@itsyme
Copy link
Contributor Author

itsyme commented Mar 30, 2023

Thanks @itsyme , the component is working well!

Is it possible to add tests for generating the items array from the siteNav, since the current tests stub the items array?

I'm also wondering if we should add this to the default template 🤔 What do you think?

HI @jovyntls! I have made the relevant changes including generating the breadcrumbs from the sitenav component. However, because it requires a short timeout, I have skipped the tests because of issue #2238 just to be sure, but I have tested them and they work as intended.

@jovyntls
Copy link
Contributor

I see, why does it require a setTimeout? Is it to wait for the breadcrumbs to be generated after mounting?

@itsyme
Copy link
Contributor Author

itsyme commented Mar 30, 2023

I see, why does it require a setTimeout? Is it to wait for the breadcrumbs to be generated after mounting?

Yup! There needs to be a very short delay for the breadcrumbs to generate the data from the sitenav, else the snapshot will return an empty breadcrumb!

@jovyntls
Copy link
Contributor

jovyntls commented Mar 30, 2023

Would the nextTick() method fix this? 🤔 Something like await nextTick() to wait for the component to mount and run the generating breadcrumbs method.

For docs, ctrl-F 'nextTick' here: https://test-utils.vuejs.org/guide/advanced/async-suspense.html#a-simple-example-updating-with-trigger

Unfortunately this won't work for the other tests in #2238 since those components implicitly use setTimeouts 😢

@itsyme
Copy link
Contributor Author

itsyme commented Mar 31, 2023

Would the nextTick() method fix this? 🤔 Something like await nextTick() to wait for the component to mount and run the generating breadcrumbs method.

For docs, ctrl-F 'nextTick' here: https://test-utils.vuejs.org/guide/advanced/async-suspense.html#a-simple-example-updating-with-trigger

Unfortunately this won't work for the other tests in #2238 since those components implicitly use setTimeouts 😢

Thanks for the suggestion! It worked well and I have implemented it in the latest commit and unskipped the tests!

Copy link
Contributor

@jovyntls jovyntls left a comment

Choose a reason for hiding this comment

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

LGTM! This would be a nice feature addition 🎉 Thanks @itsyme !

@itsyme itsyme added this to the v5.0.0 milestone Mar 31, 2023
@itsyme itsyme changed the title Add breadcrumbs Add autogenerated breadcrumbs component Apr 1, 2023
@itsyme itsyme merged commit aa1fdbb into MarkBind:master Apr 1, 2023
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.

Support auto generating breadcrumbs
6 participants