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

Updating browser history integration with the navigation Table of Contents (ToC) filter #847

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from

Conversation

RONAK-AI647
Copy link
Contributor

@RONAK-AI647 RONAK-AI647 commented Nov 30, 2024

Description

In account of the issue#209 , an issue arose where the navigation Table of Content (ToC) was not working properly . This PR talks about this issue only. Our desired behavior in this updation was:

image

Issue addressed

#213
Addresses #PR# HERE

Before/after screenshots

The first URL

image

When button is typed in ToC

Screenshot 2024-12-01 005300

When button is pressed

Screenshot 2024-12-01 005415

FIrst back press

Screenshot 2024-12-01 005503

Second back press

image

Changelog

  • Description: Improvement of the Table of Contents filter to work properly with browsers' command.
  • Products impact: Updated API
  • Addresses: Issue#213
  • Components: no
  • Breaking: no
  • Impacts a11y: no
  • Guidance: Improves KDS.

Steps to test

  1. Open KDS on local server .
  2. The modification done in index.vue under sidenav section.
  3. .........

(optional) Implementation notes

At a high level, how did you implement this?

Does this introduce any tech-debt items?

Testing checklist

  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical and brittle code paths are covered by unit tests
  • The change is described in the changelog section above

Reviewer guidance

  • Is the code clean and well-commented?
  • Are there tests for this change?
  • Are all UI components LTR and RTL compliant (if applicable)?
  • Add other things to check for here

Comments

The watch and mount section in docs\common\DocsPageTemplate\SideNav\index.vue is modified.

@RONAK-AI647
Copy link
Contributor Author

I wonder if the maintainers could pass the linter test for me , as the linter does not fix the issues in windows .

@MisRob MisRob added the TODO: needs review Waiting for review label Dec 2, 2024
@MisRob MisRob requested a review from AlexVelezLl December 2, 2024 03:49
@MisRob
Copy link
Member

MisRob commented Dec 2, 2024

Thank you @RONAK-AI647! I will invite my colleagues for review.

@akolson
Copy link
Member

akolson commented Dec 2, 2024

Hi @RONAK-AI647 I am not sure whether this is within the scope if this task but I did pick up the issue below; Directly accessing the for example /?filter=kcard via url bar doesn't trigger the filtering of the TOC. @MisRob @AlexVelezLl any thoughts?

Screen.Recording.2024-12-02.at.15.50.56.mov

@RONAK-AI647
Copy link
Contributor Author

RONAK-AI647 commented Dec 2, 2024

@akolson I see it , but it works when you paste the extension "/kcard?filter=kcard" rather than " /?filter=kcard ". because the URL was suppposed to be this , according to the box below.

image

If you say that pasting this URL extension " /?filter=kcard " does not enter the button's name in Toc filter , yes it does not , I see that .

@akolson
Copy link
Member

akolson commented Dec 2, 2024

@RONAK-AI647 unfortunately I can also replicate this

but it works when you paste the extension "/kcard?filter=kcard" rather than " /?filter=kcard ". because the URL was suppposed to be this , according to the box below.

You can check here on your pr deployment

Screen.Recording.2024-12-02.at.18.59.36.mov

@RONAK-AI647
Copy link
Contributor Author

@akolson , this could be beyond the scope of this task , i can be wrong , if you all confirm it as an emerging issue , i will work on that as well.

@RONAK-AI647
Copy link
Contributor Author

Screen.Recording.2024-12-02.214615.mp4

I see ,this was previously with the KDS , so i guarantee my new codes did not generate this error 😅. @akolson @MisRob

@AlexVelezLl
Copy link
Member

AlexVelezLl commented Dec 3, 2024

Hi @RONAK-AI647!! Thanks for working on this issue :). Yes, this issue is in the scope of this PR. Previous to this PR we didnt had a filter query in the route, so any bug we have with this route query is because we have introduced some error with this PR.

A couple of things that can be originating this error:

  1. We need to remove the previous handlers that stored this filter value in the sessionStorage, because we are not relying in the sessionStorage anymore to handle this value, but on the route query, and we need to have a single source of truth:
  1. After we do this ⬆️ the error reported by @akolson becomes more obvious, when we reload the page we lose the filter query:
Compartir.pantalla.-.2024-12-03.07_01_56.mp4
  1. We have missed an instruction described in Improve browser history integration with the navigation Table of Contents (ToC) filter #213:

Persist trailing debounced changes (wait time ~2s) to the filter as query string changes and push them onto the browser history stack.

We need to push the filter as query debounced by 2s (we can play with the wait time if needed), and we need to read these chages so when we reload the page or go back we have this value set. After we push the query, we dont need to do any of this https://github.com/RONAK-AI647/kolibri-design-system/blob/ac409f6b908ff90f9487bba17bb784c3aa11867e/docs/common/DocsPageTemplate/SideNav/index.vue#L99-L106 because the browser history is the one that will be in charge of managing the state changes, so we dont need to listen to the pop.

Hope these instructions help. Let me know if you have any questions :).

@RONAK-AI647
Copy link
Contributor Author

Thank You @AlexVelezLl for the guidance .🥰
Thank You @akolson for reviews about the PR, I am working on it , Soon post the outcome.

@RONAK-AI647
Copy link
Contributor Author

RONAK-AI647 commented Dec 5, 2024

Screen.Recording.2024-12-05.231831.mp4

Not loosing filter query when page reloads . @AlexVelezLl

@RONAK-AI647
Copy link
Contributor Author

RONAK-AI647 commented Dec 6, 2024

Hey members , take a look please. @AlexVelezLl @akolson

  1. The filter Toc and browser's forward and backward button.
Screen.Recording.2024-12-06.232940.mp4
  1. Not loosing filter query when page reloads
Screen.Recording.2024-12-06.233013.mp4
  1. Directly accessing from the URL bar.
Screen.Recording.2024-12-06.233057.mp4

Copy link
Member

@AlexVelezLl AlexVelezLl left a comment

Choose a reason for hiding this comment

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

Thank you @RONAK-AI647!! This is looking great! We are almost there, the only thing I have noticed that is missing is that after we click on a component, we dont preserve the filter query and it gets deleted, this is the only behaviour missing from the table that was presented in the issue:

URL action
/ first URL
/?filter=button after enter 'button' into ToC filter
/kbutton?filter=button after clicking KButton entry
/?filter=button browser back
/ browser back

Its the 3rd action what is still missing. Apart from that everything looks good!

@AlexVelezLl
Copy link
Member

Also, can you please rebase your branch on top of the latest KDS develop? We recently updated the KDS nodejs version to v18 and vue to v2.7, and we need to do the rebase for the actions to run successfully :). There are also new linting rules, so after rebasing, please run yarn lint-fix again to comply with the new rules. Thanks!

@RONAK-AI647 RONAK-AI647 force-pushed the navigating-browser-history-issue branch from f9fe853 to 31df512 Compare December 11, 2024 14:11
@RONAK-AI647
Copy link
Contributor Author

RONAK-AI647 commented Dec 11, 2024

@AlexVelezLl I have considered the 3rd step and now its preserved. You can take a look .

Screen.Recording.2024-12-11.210359.mp4

@RONAK-AI647
Copy link
Contributor Author

RONAK-AI647 commented Dec 11, 2024

@MisRob @AlexVelezLl , I face a problem here , i rebased the pr , the lint fix yet shows list of errors in the terminal. Here the common cicd checks also are failing , any idea , what is wrong .

  1. I updated the node to version 18. and vue to vue 2.
Screen.Recording.2024-12-11.211223.mp4

@AlexVelezLl
Copy link
Member

Hey @RONAK-AI647! Did you run the yarn install again after rebasing?

@RONAK-AI647
Copy link
Contributor Author

RONAK-AI647 commented Dec 12, 2024

Hey @RONAK-AI647! Did you run the yarn install again after rebasing?

yes, I did yarn install. , yet the yarn lint-fix does not work I don't understand why these tests fail.
image

do i open a new PR???

@AlexVelezLl
Copy link
Member

Hey @RONAK-AI647! Its possible that the error you are facing is because of a specific setting in your computer. Can you explore the answers described in this thread: https://stackoverflow.com/questions/8965606/node-and-error-emfile-too-many-open-files. I was able to run yarn lint-fix with your branch, so its probably something to do with the OS.

I will further investigate the failing netlify actions, these shouldnt be failing.

}

// Modify navigation links to preserve the filter query
this.$nextTick(() => {
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest better update NavLink and DocsLibraryLink to pass the query params, so we have dont have to add an event listener to all links of the page :)

@RONAK-AI647
Copy link
Contributor Author

@AlexVelezLl i got the linting problem and the conflicts with rest of the checks will be dealt if i open a new PR . The points you mentioned , i will keep in mind and soon i will a new PR with everything resolved. Thank you

@AlexVelezLl
Copy link
Member

I managed to get it working @RONAK-AI647! Here is the deployed site https://deploy-preview-847--kolibri-design-system.netlify.app/. You wont need to open a different PR 👐.

@RONAK-AI647
Copy link
Contributor Author

I managed to get it working @RONAK-AI647! Here is the deployed site https://deploy-preview-847--kolibri-design-system.netlify.app/. You wont need to open a different PR 👐.

super Thank You !!!!!!

@RONAK-AI647
Copy link
Contributor Author

@AlexVelezLl I updated the navlink.vue and DocsLibraryLink.vue as you said , take a look please.

Copy link
Member

@AlexVelezLl AlexVelezLl left a comment

Choose a reason for hiding this comment

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

Hey @RONAK-AI647! This looks good to me! We are almost there, just suggested to remove the debounceUpdateQuery method as it seems is not needed anymore, since the intention of the debounce has been addressed in another way. After this, we can merge the PR. Thank you!

query: { ...this.$route.query, filter: newValue },
});
}
this.debouncedUpdateQuery(newValue);
Copy link
Member

Choose a reason for hiding this comment

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

As you took another approach with the popstate listener, lets just remove this debouncedUpdateQuery call. As there we just do the same logic of pushing the query.

Suggested change
this.debouncedUpdateQuery(newValue);

window.sessionStorage.setItem('nav-filter', newValue);
//Clear the filter query when filtertext is empty
if (!newValue) {
this.$router.replace({ path: this.$route.path, query: {} });
Copy link
Member

Choose a reason for hiding this comment

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

I think we can just push the new route, instead of replacing it.

Comment on lines 117 to 126
this.debouncedUpdateQuery = debounce(newValue => {
if (newValue) {
this.$router.push({
path: this.$route.path,
query: { ...this.$route.query, filter: newValue },
});
} else {
this.$router.push({ path: this.$route.path, query: {} });
}
}, 2000); // 2-second debounce delay
Copy link
Member

Choose a reason for hiding this comment

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

As we wont be using this debouncedUpdateQuery anymore, we can just remove these lines.

Suggested change
this.debouncedUpdateQuery = debounce(newValue => {
if (newValue) {
this.$router.push({
path: this.$route.path,
query: { ...this.$route.query, filter: newValue },
});
} else {
this.$router.push({ path: this.$route.path, query: {} });
}
}, 2000); // 2-second debounce delay

@@ -51,6 +52,7 @@
return {
filterText: '',
loaded: false,
debounceUpdateQuery: null,
Copy link
Member

Choose a reason for hiding this comment

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

And dont forget to remove this data variable too :)

Copy link
Member

Choose a reason for hiding this comment

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

Hi @RONAK-AI647! We are not using this state anymore, we can remove it too :)

@RONAK-AI647
Copy link
Contributor Author

@AlexVelezLl , made the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TODO: needs review Waiting for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants