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 29 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 27 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
13 changes: 11 additions & 2 deletions docs/common/DocsLibraryLink.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>

<a :href="'/' + component.toLowerCase()">
<router-link :to="computedLink">
<code>{{ component }}</code>
</a>
</router-link>

</template>

Expand All @@ -17,6 +17,15 @@
required: true,
},
},
computed: {
computedLink() {
// Preserve query parameters in the link
return {
path: '/' + this.component.toLowerCase(),
query: { ...this.$route.query },
};
},
},
};

</script>
12 changes: 10 additions & 2 deletions docs/common/DocsPageTemplate/SideNav/NavLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
>
{{ page.title }}
</div>
<a
<router-link
v-else
:to="computedLink"
class="block enabled-link"
:href="page.path"
:class="{ 'current-page': currentPage, code: page.isCode }"
>
{{ page.title }}
</a>
</router-link>

</template>

Expand All @@ -39,6 +40,13 @@
currentPage() {
return this.page.path === this.$route.path;
},
computedLink() {
// Preserve query parameters in the link
return {
path: this.page.path,
query: { ...this.$route.query },
};
},
},
};

Expand Down
44 changes: 39 additions & 5 deletions docs/common/DocsPageTemplate/SideNav/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<script>

import throttle from 'lodash/throttle';
import debounce from 'lodash/debounce';
import NavSectionList from './NavSectionList';
import { termList, matches } from '~/common/DocsFilter/utils';
import tableOfContents from '~/tableOfContents.js';
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 All @@ -77,22 +79,54 @@
return toc;
},
},

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: {} });
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.

} else {
//else ,update the filter query param
this.$router.push({
path: this.$route.path,
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);

}
},
},
mounted() {
if (window) {
const filterText = window.sessionStorage.getItem('nav-filter');
if (filterText) {
this.filterText = filterText;
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
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

}
// don't show the nav until the state is set

// Don't show the nav until the state is set
this.loaded = true;
},
methods: {
Expand Down
Loading