FIX: Reset 'filter' query parameter when clicking on a nav-item (#10299)

Usually, this would have been implemented using resetController, but
because we do not use link-to component for linking, that method is not
called.
This commit is contained in:
Bianca Nenciu 2020-07-29 15:38:15 +03:00 committed by GitHub
parent fd02856f80
commit 27d853e2ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 0 deletions

View File

@ -79,6 +79,7 @@ export default Component.extend(FilterModeMixin, {
return NavItem.buildList(category, {
filterType,
noSubcategories,
currentRouteQueryParams,
persistedQueryParams: params,
siteSettings: this.siteSettings
});

View File

@ -59,6 +59,17 @@ export default Component.extend(FilterModeMixin, {
});
}
// To reset the "filter" sticky param, at least one query param is needed.
// If no query param is present, add an empty one to ensure a ? is
// appended to the URL.
if (content.currentRouteQueryParams) {
if (content.currentRouteQueryParams.filter) {
if (queryParams.length === 0) {
queryParams.push("");
}
}
}
if (queryParams.length) {
href += `?${queryParams.join("&")}`;
}

View File

@ -172,6 +172,9 @@ NavItem.reopenClass({
if (opts.tagId) {
args.tagId = opts.tagId;
}
if (opts.currentRouteQueryParams) {
args.currentRouteQueryParams = opts.currentRouteQueryParams;
}
if (opts.persistedQueryParams) {
args.persistedQueryParams = opts.persistedQueryParams;
}

View File

@ -8,6 +8,10 @@ import { scrollTop } from "discourse/mixins/scroll-top";
import User from "discourse/models/user";
export default DiscourseRoute.extend(OpenComposer, {
queryParams: {
filter: { refreshModel: true }
},
redirect() {
return this.redirectIfLoginRequired();
},