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

Reset active filters when clicking "See older documents" #642

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading