Skip to content

Commit

Permalink
Change /all to /documents (#306)
Browse files Browse the repository at this point in the history
* Set up nested /all route

* Update tests and hrefs

* Remove console logs

* Remove console.log

* Remove "all"

* Add "all" as a redirect route; update URLs

* Cleanup and revert out-of-scope change

* Fix merge errors

* Add redirect test

* Add note to All controller
  • Loading branch information
jeffdaley committed Sep 1, 2023
1 parent f9c16f5 commit 8998855
Show file tree
Hide file tree
Showing 20 changed files with 226 additions and 180 deletions.
5 changes: 2 additions & 3 deletions web/app/components/header/nav.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{{! @glint-nocheck: not typesafe yet }}
<div class="x-container">

<nav class="header-nav">
Expand All @@ -9,8 +8,8 @@
<div class="primary-links">
<LinkTo
data-test-nav-link="all"
@route="authenticated.all"
@current-when="authenticated.all"
@route="authenticated.documents"
@current-when="authenticated.documents"
@query={{this.defaultBrowseScreenQueryParams}}
>
All Docs
Expand Down
2 changes: 1 addition & 1 deletion web/app/components/header/search.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
{{else if (eq dd.value "productAreaMatch")}}
<dd.LinkTo
data-test-product-match-link
@route="authenticated.all"
@route="authenticated.documents"
@query={{hash
product=(array dd.attrs.productAreaName)
page=1
Expand Down
2 changes: 1 addition & 1 deletion web/app/components/product-badge-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class ProductBadgeLinkComponent extends Component<ProductBadgeLin
case "authenticated.my":
return currentRouteName;
default:
return "authenticated.all";
return "authenticated.documents";
}
}
}
Expand Down
51 changes: 27 additions & 24 deletions web/app/components/results/index.hbs
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
{{! @glint-nocheck: not typesafe yet }}
<section class="flex flex-col items-center flex-1 min-h-full">
<section class="flex min-h-full flex-1 flex-col items-center">
<div class="x-container">
{{#if (and this.firstPageIsShown this.queryIsProductName)}}
<div class="flex flex-col items-start w-full pb-10" data-test-results-product-link>
<Hds::Card::Container
@level="mid"
@hasBorder="true"
@overflow="hidden"
class="flex flex-col items-start space-y-3 pt-4 px-4 pb-3"
>
<Hds::Badge
@text={{this.capitalizedQuery}}
@icon={{or (get-product-id @query) "folder"}}
/>
<Hds::Link::Standalone
@text="View all {{this.capitalizedQuery}} documents"
@icon="arrow-right-circle"
@iconPosition="trailing"
@route="authenticated.all"
@query={{hash product=(array this.capitalizedQuery)}}
/>
</Hds::Card::Container>
</div>
{{/if}}
{{#if (and this.firstPageIsShown this.queryIsProductName)}}
<div
class="flex w-full flex-col items-start pb-10"
data-test-results-product-link
>
<Hds::Card::Container
@level="mid"
@hasBorder="true"
@overflow="hidden"
class="flex flex-col items-start space-y-3 px-4 pt-4 pb-3"
>
<Hds::Badge
@text={{this.capitalizedQuery}}
@icon={{or (get-product-id @query) "folder"}}
/>
<Hds::Link::Standalone
@text="View all {{this.capitalizedQuery}} documents"
@icon="arrow-right-circle"
@iconPosition="trailing"
@route="authenticated.documents"
@query={{hash product=(array this.capitalizedQuery)}}
/>
</Hds::Card::Container>
</div>
{{/if}}

<h1
class="hds-typography-display-300 hds-font-weight-semibold hds-foreground-strong"
>{{@results.nbHits}} documents matching “{{@query}}”</h1>
<div class="flex flex-col space-y-12 w-full py-10">
<div class="flex w-full flex-col space-y-12 py-10">
<div class="tile-list">
{{#each @results.hits as |doc index|}}
<Doc::Tile
Expand Down
20 changes: 5 additions & 15 deletions web/app/controllers/authenticated/all.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Controller from "@ember/controller";
import { SortByValue } from "hermes/components/header/toolbar";
import { SortDirection } from "hermes/components/table/sortable-header";
import AuthenticatedAllRoute from "hermes/routes/authenticated/all";
import { ModelFrom } from "hermes/types/route-models";

/**
* This allows queryParams to be captured and passed
* to the `/documents` route on redirect.
*/

export default class AuthenticatedAllController extends Controller {
queryParams = ["docType", "owners", "page", "product", "sortBy", "status"];
Expand All @@ -12,15 +13,4 @@ export default class AuthenticatedAllController extends Controller {
product = [];
sortBy = "dateDesc";
status = [];

declare model: ModelFrom<AuthenticatedAllRoute>;

get sortDirection() {
switch (this.model.sortedBy) {
case SortByValue.DateAsc:
return SortDirection.Asc;
default:
return SortDirection.Desc;
}
}
}
26 changes: 26 additions & 0 deletions web/app/controllers/authenticated/documents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Controller from "@ember/controller";
import { SortByValue } from "hermes/components/header/toolbar";
import { SortDirection } from "hermes/components/table/sortable-header";
import AuthenticatedDocumentsRoute from "hermes/routes/authenticated/documents";
import { ModelFrom } from "hermes/types/route-models";

export default class AuthenticatedDocumentsController extends Controller {
queryParams = ["docType", "owners", "page", "product", "sortBy", "status"];
docType = [];
owners = [];
page = 1;
product = [];
sortBy = "dateDesc";
status = [];

declare model: ModelFrom<AuthenticatedDocumentsRoute>;

get sortDirection() {
switch (this.model.sortedBy) {
case SortByValue.DateAsc:
return SortDirection.Asc;
default:
return SortDirection.Desc;
}
}
}
5 changes: 3 additions & 2 deletions web/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ export default class Router extends EmberRouter {

Router.map(function () {
this.route("authenticated", { path: "/" }, function () {
this.route("all");
this.route("dashboard");
this.route("all"); // legacy route; redirects to /documents
this.route("documents");
this.route("document", { path: "/document/:document_id" });
this.route("drafts");
this.route("my");
Expand All @@ -20,5 +21,5 @@ Router.map(function () {
});
});
this.route("authenticate");
this.route('404', { path: '/*path' })
this.route("404", { path: "/*path" });
});
50 changes: 5 additions & 45 deletions web/app/routes/authenticated/all.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,11 @@
import Route from "@ember/routing/route";
import { inject as service } from "@ember/service";
import ConfigService from "hermes/services/config";
import AlgoliaService from "hermes/services/algolia";
import { DocumentsRouteParams } from "hermes/types/document-routes";
import ActiveFiltersService from "hermes/services/active-filters";
import { SortByValue } from "hermes/components/header/toolbar";
import RouterService from "@ember/routing/router-service";

export default class AuthenticatedAllRoute extends Route {
@service("config") declare configSvc: ConfigService;
@service declare algolia: AlgoliaService;
@service declare activeFilters: ActiveFiltersService;
export default class AuthenticatedDocumentsRoute extends Route {
@service declare router: RouterService;

queryParams = {
docType: {
refreshModel: true,
},
owners: {
refreshModel: true,
},
page: {
refreshModel: true,
},
product: {
refreshModel: true,
},
sortBy: {
refreshModel: true,
},
status: {
refreshModel: true,
},
};

async model(params: DocumentsRouteParams) {
const sortedBy = (params.sortBy as SortByValue) ?? SortByValue.DateDesc;
const searchIndex =
params.sortBy === SortByValue.DateAsc
? this.configSvc.config.algolia_docs_index_name + "_createdTime_asc"
: this.configSvc.config.algolia_docs_index_name + "_createdTime_desc";

let [facets, results] = await Promise.all([
this.algolia.getFacets.perform(searchIndex, params),
this.algolia.getDocResults.perform(searchIndex, params),
]);

this.activeFilters.update(params);

return { facets, results, sortedBy };
beforeModel() {
this.router.transitionTo("authenticated.documents");
}
}
52 changes: 52 additions & 0 deletions web/app/routes/authenticated/documents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import Route from "@ember/routing/route";
import { inject as service } from "@ember/service";
import ConfigService from "hermes/services/config";
import AlgoliaService from "hermes/services/algolia";
import { DocumentsRouteParams } from "hermes/types/document-routes";
import ActiveFiltersService from "hermes/services/active-filters";
import { SortByValue } from "hermes/components/header/toolbar";

export default class AuthenticatedDocumentsRoute extends Route {
@service("config") declare configSvc: ConfigService;
@service declare algolia: AlgoliaService;
@service declare activeFilters: ActiveFiltersService;

queryParams = {
docType: {
refreshModel: true,
},
owners: {
refreshModel: true,
},
page: {
refreshModel: true,
},
product: {
refreshModel: true,
},
sortBy: {
refreshModel: true,
},
status: {
refreshModel: true,
},
};

async model(params: DocumentsRouteParams) {
const sortedBy = params.sortBy ?? SortByValue.DateDesc;

const searchIndex =
params.sortBy === "dateAsc"
? this.configSvc.config.algolia_docs_index_name + "_createdTime_asc"
: this.configSvc.config.algolia_docs_index_name + "_createdTime_desc";

let [facets, results] = await Promise.all([
this.algolia.getFacets.perform(searchIndex, params),
this.algolia.getDocResults.perform(searchIndex, params),
]);

this.activeFilters.update(params);

return { facets, results, sortedBy };
}
}
File renamed without changes.
64 changes: 5 additions & 59 deletions web/tests/acceptance/authenticated/all-test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { click, visit } from "@ember/test-helpers";
import { visit } from "@ember/test-helpers";
import { setupApplicationTest } from "ember-qunit";
import { module, test, todo } from "qunit";
import { authenticateSession } from "ember-simple-auth/test-support";
import { MirageTestContext, setupMirage } from "ember-cli-mirage/test-support";
import { getPageTitle } from "ember-page-title/test-support";

const PRODUCT_BADGE_LINK_SELECTOR = ".product-badge-link";
const TABLE_HEADER_CREATED_SELECTOR =
"[data-test-sortable-table-header][data-test-attribute=createdTime]";
import RouterService from "@ember/routing/router-service";

interface AuthenticatedAllRouteTestContext extends MirageTestContext {}

Expand All @@ -18,61 +14,11 @@ module("Acceptance | authenticated/all", function (hooks) {
hooks.beforeEach(async function () {
await authenticateSession({});
});

test("the page title is correct", async function (this: AuthenticatedAllRouteTestContext, assert) {
await visit("/all");
assert.equal(getPageTitle(), "All Docs | Hermes");
});

test("documents can be sorted by created date", async function (this: AuthenticatedAllRouteTestContext, assert) {
this.server.createList("document", 2);

test("it redirects to the documents route", async function (this: AuthenticatedAllRouteTestContext, assert) {
await visit("/all");

assert
.dom(TABLE_HEADER_CREATED_SELECTOR)
.hasClass("active")
.hasAttribute("href", "/all?sortBy=dateAsc");

assert
.dom(`${TABLE_HEADER_CREATED_SELECTOR} .flight-icon`)
.hasAttribute("data-test-icon", "arrow-down");

await click(TABLE_HEADER_CREATED_SELECTOR);
const routerService = this.owner.lookup("service:router") as RouterService;

assert
.dom(TABLE_HEADER_CREATED_SELECTOR)
.hasClass("active")
.hasAttribute("href", "/all");

assert
.dom(`${TABLE_HEADER_CREATED_SELECTOR} .flight-icon`)
.hasAttribute("data-test-icon", "arrow-up");
});

test("product badges have the correct hrefs", async function (this: AuthenticatedAllRouteTestContext, assert) {
// Note: "Vault" is the default product area in the Mirage factory.

this.server.create("document", {
product: "Labs",
});

await visit("/all");

assert
.dom(PRODUCT_BADGE_LINK_SELECTOR)
.hasAttribute("href", "/all?product=%5B%22Labs%22%5D");
assert.equal(routerService.currentRouteName, "authenticated.documents");
});

/**
* We want to test that clicking the product badge replaces filters
* rather than compound them, but we don't yet have the Mirage
* factories to support this.
*/
todo(
"product badges have the correct hrefs when other filters are active",
async function (this: AuthenticatedAllRouteTestContext, assert) {
assert.true(false);
}
);
});
Loading

0 comments on commit 8998855

Please sign in to comment.