Skip to content

Commit

Permalink
Reset active filters when clicking "See older documents" (#642)
Browse files Browse the repository at this point in the history
Fix "see older documents" link
  • Loading branch information
jeffdaley authored Mar 8, 2024
1 parent f2f41f5 commit f3017e0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion web/app/components/dashboard/latest-docs.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@iconPosition="trailing"
@isFullWidth={{true}}
@route="authenticated.documents"
@query={{hash page=2}}
@query={{this.query}}
class="py-3"
/>
</div>
Expand Down
12 changes: 12 additions & 0 deletions web/app/components/dashboard/latest-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Component from "@glimmer/component";
import LatestDocsService from "hermes/services/latest-docs";
import { HermesDocument } from "hermes/types/document";
import { inject as service } from "@ember/service";
import { DEFAULT_FILTERS } from "hermes/services/active-filters";

interface DashboardLatestDocsComponentSignature {}

Expand All @@ -19,6 +20,17 @@ export default class DashboardLatestDocsComponent extends Component<DashboardLat
protected get docs(): HermesDocument[] | null {
return this.latestDocs.index;
}

/**
* The query of the "See older docs" link.
* Resets any active filters and sets the page to 2.
*/
protected get query() {
return {
...DEFAULT_FILTERS,
page: 2,
};
}
}

declare module "@glint/environment-ember-loose/registry" {
Expand Down
17 changes: 16 additions & 1 deletion web/tests/integration/components/dashboard/latest-docs-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { MirageTestContext, setupMirage } from "ember-cli-mirage/test-support";
import { render, waitFor } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars";
import LatestDocsService from "hermes/services/latest-docs";
import ActiveFiltersService from "hermes/services/active-filters";

const NO_DOCS_PUBLISHED = "[data-test-no-docs-published]";
const LATEST_DOC = "[data-test-latest-doc]";
Expand Down Expand Up @@ -45,6 +46,14 @@ module("Integration | Component | dashboard/latest-docs", function (hooks) {
test("it shows a link to the next page of docs if there are more than one page", async function (this: Context, assert) {
this.server.createList("document", 10);

const activeFilters = this.owner.lookup(
"service:active-filters",
) as ActiveFiltersService;

activeFilters.update({
product: ["Labs"],
});

const latestDocs = this.owner.lookup(
"service:latest-docs",
) as LatestDocsService;
Expand All @@ -56,7 +65,13 @@ module("Integration | Component | dashboard/latest-docs", function (hooks) {
<Dashboard::LatestDocs />
`);

assert.dom(ALL_DOCS_LINK).exists();
assert
.dom(ALL_DOCS_LINK)
.hasAttribute(
"href",
"/documents?page=2",
"it links to a filter-less second page of docs",
);
});

test("it shows an icon when the fetch task is running", async function (this: Context, assert) {
Expand Down

0 comments on commit f3017e0

Please sign in to comment.