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

Merged
Changes from 20 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
527e520
pushing to browser history
RONAK-AI647 Nov 26, 2024
4a4b00a
update index.vue
RONAK-AI647 Nov 26, 2024
e8b38ca
javascript check
RONAK-AI647 Nov 26, 2024
9891727
Restoring filter state when a user navigates back
RONAK-AI647 Nov 26, 2024
4b894c8
Update vue.index
RONAK-AI647 Nov 26, 2024
6cd0f27
javascript test
RONAK-AI647 Nov 26, 2024
c279c07
event to events
RONAK-AI647 Nov 26, 2024
61a3421
revert the commit
RONAK-AI647 Nov 26, 2024
7015309
Update index.vue
RONAK-AI647 Nov 26, 2024
d7c6326
from search to filter
RONAK-AI647 Nov 28, 2024
d7ae230
The URL perfecting
RONAK-AI647 Nov 28, 2024
ab763d5
Revert "The URL perfecting"
RONAK-AI647 Nov 28, 2024
903687d
Updating watch for URL fix
RONAK-AI647 Nov 30, 2024
d1d6045
Spacing and linting
RONAK-AI647 Nov 30, 2024
6455c37
lint-test
RONAK-AI647 Dec 1, 2024
37e82d8
Removing previous handlers
RONAK-AI647 Dec 4, 2024
25597c2
Pushing filter as query
RONAK-AI647 Dec 5, 2024
bb03df0
Adding debounceUpdate
RONAK-AI647 Dec 6, 2024
31df512
Adding debounce under mounted()
RONAK-AI647 Dec 6, 2024
4217eb0
Preserving the query when the button is clicked
RONAK-AI647 Dec 11, 2024
df406a8
Lint -fix (ubuntu version)
RONAK-AI647 Dec 13, 2024
be4c1ed
Force deploy
AlexVelezLl Dec 13, 2024
e7dcf6e
Updating Navlink.vue for preserving query param
RONAK-AI647 Dec 16, 2024
b295d9e
Update DocsLibraryLink.vue
RONAK-AI647 Dec 16, 2024
bfb7973
yarn lint-fix
RONAK-AI647 Dec 16, 2024
cdc9887
Merge branch 'navigating-browser-history-issue' of https://github.com…
RONAK-AI647 Dec 16, 2024
33f9178
Removing previous handler in index.vue
RONAK-AI647 Dec 16, 2024
e1b0a16
Removing debouncedUpdateQuery
RONAK-AI647 Jan 3, 2025
4ec2073
Update index.vue
RONAK-AI647 Jan 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 55 additions & 13 deletions docs/common/DocsPageTemplate/SideNav/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
import NavSectionList from './NavSectionList';
import { termList, matches } from '~/common/DocsFilter/utils';
import tableOfContents from '~/tableOfContents.js';

import debounce from 'lodash/debounce';

export default {
name: 'SideNav',
components: {
Expand All @@ -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 :)

Copy link
Contributor Author

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 :)

ahh I saw that , yet i missed , my bad !!!!!!

};
},
computed: {
Expand Down Expand Up @@ -80,22 +82,62 @@
watch: {
filterText(newValue) {
if (window) {
window.sessionStorage.setItem('nav-filter', newValue);
//Clear the filter query when filtertext is empty
if (!newValue) {
this.$router.replace({ path: this.$route.path, query: {} });
}
},
},
mounted() {
if (window) {
const filterText = window.sessionStorage.getItem('nav-filter');
if (filterText) {
this.filterText = filterText;
else {
//else ,update the filter query param
this.$router.push({ path: this.$route.path, query: { ...this.$route.query, filter: newValue}});
}
this.debouncedUpdateQuery(newValue);
}
this.$refs.links.scrollTop = window.sessionStorage.getItem('nav-scroll');
}
// don't show the nav until the state is set
this.loaded = true;
},
methods: {
mounted() {
if (window) {
const { filter } = this.$route.query;
// Set filterText from the query parameter if it exists
if (filter) {
this.filterText = filter;
}
this.$refs.links.scrollTop = window.sessionStorage.getItem('nav-scroll');
// Restoring filter state when a user navigates back
window.addEventListener('popstate', (event) => {
if (event.state && 'filterText' in event.state) {
this.filterText = event.state.filterText;
} else {
this.filterText = ''; // Reset if no filterText is in state
}
});
// Create debounced function for updating the query
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
}

// 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 :)

this.$refs.links.querySelectorAll('a').forEach((link) => {
link.addEventListener('click', (event) => {
event.preventDefault();
const href = new URL(link.href);
this.$router.push({
path: href.pathname,
query: { ...this.$route.query } // Add existing query params to the new path
});
});
});
});
// Don't show the nav until the state is set
this.loaded = true;
},
methods: {
throttleHandleScroll: throttle(function handleScroll() {
window.sessionStorage.setItem('nav-scroll', this.$refs.links.scrollTop);
}, 100),
Expand Down
Loading