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

Make ProductArea badges interactive #272

Merged
merged 9 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
8 changes: 3 additions & 5 deletions web/app/components/doc/row.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
</Hds::Table::Td>
<Hds::Table::Td class="status">
<Doc::State @state={{@status}} @hideProgress={{true}} /></Hds::Table::Td>
<Hds::Table::Td class="product"><Hds::Badge
@text={{this.productAreaName}}
@icon={{or (get-product-id @productArea) "folder"}}
title={{this.productAreaName}}
/></Hds::Table::Td>
<Hds::Table::Td class="product">
<ProductBadgeLink @productArea={{@productArea}} />
</Hds::Table::Td>
<Hds::Table::Td class="owner">
<Person @ignoreUnknown={{true}} @imgURL={{@avatar}} @email={{@owner}} />
</Hds::Table::Td>
Expand Down
10 changes: 1 addition & 9 deletions web/app/components/doc/row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,7 @@ interface DocRowComponentSignature {
};
}

export default class DocRowComponent extends Component<DocRowComponentSignature> {
get productAreaName() {
if (this.args.productArea === "Cloud Platform") {
return "HCP";
} else {
return this.args.productArea;
}
}
}
export default class DocRowComponent extends Component<DocRowComponentSignature> {}

declare module "@glint/environment-ember-loose/registry" {
export default interface Registry {
Expand Down
2 changes: 1 addition & 1 deletion web/app/components/doc/snippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Component from "@glimmer/component";
interface DocSnippetComponentSignature {
Element: HTMLParagraphElement;
Args: {
snippet: string;
snippet?: string;
};
}

Expand Down
96 changes: 54 additions & 42 deletions web/app/components/doc/tile.hbs
Original file line number Diff line number Diff line change
@@ -1,44 +1,56 @@
<LinkTo
@route="authenticated.document"
@model={{@docID}}
@query={{hash draft=@isDraft}}
class="flex flex-col items-start space-y-2 p-4 -m-4 rounded-md hover:bg-color-palette-neutral-50 active:bg-color-palette-neutral-100 overflow-hidden"
>
<div class="space-y-2">
<Doc::Thumbnail
@status={{@status}}
@product={{@productArea}}
@isLarge={{true}}
/>
<Doc::State @state={{@status}} />
</div>
<div class="relative group">
<LinkTo
@route="authenticated.document"
@model={{@docID}}
@query={{hash draft=@isDraft}}
class="pb-2 block"
>
{{!
We create a click area that extends beyond the edges of its relative container.
This makes the parent div clickable without having to wrap itself in a link,
and lets us nest interactive elements (e.g., ProductBadgeLink) in a way that improves the mouse experience without sacrificing accessibility.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

}}
<div
aria-hidden="true"
class="absolute rounded-md group-hover:bg-color-surface-faint -top-4 -left-4 -right-4 -bottom-6"
></div>

<div class="flex flex-col items-start space-y-1">
<h4 class="doc-tile-title">
{{@title}}
</h4>
{{#if (not (is-empty @docNumber))}}
<small class="text-body-100 text-color-foreground-faint">
{{@docNumber}}
</small>
{{/if}}
</div>
<div class="relative">
<div class="space-y-2.5 inline-block">
<Doc::Thumbnail
@status={{@status}}
@product={{@productArea}}
@isLarge={{true}}
/>
<Doc::State @state={{@status}} />
</div>
<div class="mt-2 space-y-1">
<h4 class="doc-tile-title">
{{@title}}
</h4>
{{#if @docNumber}}
<small class="text-body-100 text-color-foreground-faint">
{{@docNumber}}
</small>
{{/if}}
</div>
<div class="space-y-1 mt-2 max-w-full">
<Person
@ignoreUnknown={{true}}
@imgURL={{@avatar}}
@email="{{@owner}}"
/>
Comment on lines +38 to +42
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make this clickable in another PR.

{{#if @modifiedAgo}}
<p class="text-body-100 text-color-foreground-faint">
{{@modifiedAgo}}
</p>
{{/if}}
</div>
{{#if (and @isResult @snippet)}}
<Doc::Snippet @snippet={{@snippet}} class="mt-2" />
{{/if}}
</div>
</LinkTo>

<div class="flex flex-col items-start space-y-1 pb-1 max-w-full">
<Person @ignoreUnknown={{true}} @imgURL={{@avatar}} @email={{@owner}} />
{{#if (not (is-empty @modifiedAgo))}}
<p class="text-body-100 text-color-foreground-faint">
{{@modifiedAgo}}
</p>
{{/if}}
</div>

<Hds::Badge
@text={{this.productAreaName}}
@icon={{or (get-product-id this.this.args.productArea) "folder"}}
/>

{{#if (and @isResult @snippet)}}
<Doc::Snippet @snippet={{@snippet}} class="pt-2" />
{{/if}}
</LinkTo>
<ProductBadgeLink @productArea={{@productArea}} class="relative" />
</div>
14 changes: 3 additions & 11 deletions web/app/components/doc/tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ interface DocTileComponentSignature {
docNumber?: string;
isOwner?: boolean;
isResult?: boolean;
modifiedAge?: string;
isDraft?: boolean;
modifiedAgo?: string;
owner?: string;
productArea?: string;
snippet?: string;
Expand All @@ -17,16 +18,7 @@ interface DocTileComponentSignature {
};
}

export default class DocTileComponent extends Component<DocTileComponentSignature> {
protected get productAreaName(): string | undefined {
switch (this.args.productArea) {
case "Cloud Platform":
return "HCP";
default:
return this.args.productArea;
}
}
}
export default class DocTileComponent extends Component<DocTileComponentSignature> {}

declare module "@glint/environment-ember-loose/registry" {
export default interface Registry {
Expand Down
5 changes: 2 additions & 3 deletions web/app/components/document/sidebar.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,9 @@
/>
</div>
{{else}}
<Hds::Badge
<ProductBadgeLink
data-test-document-product-area-read-only
@text={{@document.product}}
@icon={{get-product-id @document.product}}
@productArea={{@document.product}}
/>
{{/if}}
</div>
Expand Down
12 changes: 12 additions & 0 deletions web/app/components/product-badge-link.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<LinkTo
@route={{this.route}}
@query={{this.query}}
class="product-badge-link"
...attributes
>
<Hds::Badge
@icon={{or (get-product-id this.this.args.productArea) "folder"}}
@text={{this.productAreaName}}
title={{this.productAreaName}}
/>
</LinkTo>
60 changes: 60 additions & 0 deletions web/app/components/product-badge-link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import RouterService from "@ember/routing/router-service";
import { inject as service } from "@ember/service";
import Component from "@glimmer/component";

interface ProductBadgeLinkComponentSignature {
Element: HTMLAnchorElement;
Args: {
productArea?: string;
};
Blocks: {
default: [];
};
}

export default class ProductBadgeLinkComponent extends Component<ProductBadgeLinkComponentSignature> {
@service declare router: RouterService;

protected get productAreaName(): string {
switch (this.args.productArea) {
case "Cloud Platform":
return "HCP";
default:
return this.args.productArea || "Unknown";
}
}

protected get query() {
if (this.args.productArea) {
return {
product: [this.args.productArea],
};
} else {
return {};
}
}

protected get route() {
const { currentRouteName } = this.router;

if (!currentRouteName) {
return "authenticated.all";
}

if (currentRouteName.includes("drafts")) {
return "authenticated.drafts";
}

if (currentRouteName.includes("my")) {
return "authenticated.my";
}

return "authenticated.all";
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't immediately tell why we needed this logic - maybe a comment would help?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I probably overcomplicated it anyway 😅

Updated


declare module "@glint/environment-ember-loose/registry" {
export default interface Registry {
ProductBadgeLink: typeof ProductBadgeLinkComponent;
}
}
1 change: 1 addition & 0 deletions web/app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
@use "components/sidebar";
@use "components/document/related-resources";
@use "components/hds-badge";
@use "components/product-badge-link";
@use "components/header/facet-dropdown";
@use "components/floating-u-i/content";
@use "components/settings/subscription-list-item";
Expand Down
5 changes: 5 additions & 0 deletions web/app/styles/components/product-badge-link.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.product-badge-link {
&:hover .hds-badge--color-neutral {
@apply bg-color-palette-neutral-200;
}
}
7 changes: 6 additions & 1 deletion web/mirage/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,17 @@ export default function (mirageConfig) {
* a list of facets and draft results.
*/
this.get("/drafts", () => {
const allDocs = this.schema.document.all().models;
const drafts = allDocs.filter((doc) => {
return doc.attrs.isDraft;
});

return new Response(
200,
{},
{
facets: [],
Hits: [],
Hits: drafts,
params: "",
page: 0,
}
Expand Down
1 change: 1 addition & 0 deletions web/mirage/factories/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default Factory.extend({
modifiedAgo: 1000000000,
modifiedTime: 1,
appCreated: true,
isDraft: true,
docNumber() {
// @ts-ignore - Mirage types are wrong
// See discussion at https://github.com/miragejs/miragejs/pull/525
Expand Down
18 changes: 17 additions & 1 deletion web/tests/acceptance/authenticated/all-test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { visit } from "@ember/test-helpers";
import { setupApplicationTest } from "ember-qunit";
import { module, test } from "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";

interface AuthenticatedAllRouteTestContext extends MirageTestContext {}

module("Acceptance | authenticated/all", function (hooks) {
Expand All @@ -19,4 +21,18 @@ module("Acceptance | authenticated/all", function (hooks) {
await visit("/all");
assert.equal(getPageTitle(), "All Docs | Hermes");
});

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");
});
});
14 changes: 13 additions & 1 deletion web/tests/acceptance/authenticated/drafts-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { visit } from "@ember/test-helpers";
import { setupApplicationTest } from "ember-qunit";
import { module, test } from "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";
Expand All @@ -19,4 +19,16 @@ module("Acceptance | authenticated/drafts", function (hooks) {
await visit("/drafts");
assert.equal(getPageTitle(), "My Drafts | Hermes");
});

test("product badges have the correct hrefs", async function (this: AuthenticatedDraftRouteTestContext, assert) {
this.server.create("document", {
product: "Security",
});

await visit("/drafts");

assert
.dom(".product-badge-link")
.hasAttribute("href", "/drafts?product=%5B%22Security%22%5D");
});
});
14 changes: 14 additions & 0 deletions web/tests/acceptance/authenticated/my-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ 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";

interface AuthenticatedMyRouteTestContext extends MirageTestContext {}

module("Acceptance | authenticated/my", function (hooks) {
Expand All @@ -19,4 +21,16 @@ module("Acceptance | authenticated/my", function (hooks) {
await visit("/my");
assert.equal(getPageTitle(), "My Docs | Hermes");
});

test("product badges have the correct hrefs", async function (this: AuthenticatedMyRouteTestContext, assert) {
this.server.create("document", {
product: "Terraform",
});

await visit("/my");

assert
.dom(PRODUCT_BADGE_LINK_SELECTOR)
.hasAttribute("href", "/my?product=%5B%22Terraform%22%5D");
});
});
10 changes: 10 additions & 0 deletions web/tests/acceptance/authenticated/results-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@ module("Acceptance | authenticated/results", function (hooks) {
await visit("/results");
assert.equal(getPageTitle(), "Search Results | Hermes");
});

test("product badges have the correct hrefs", async function (this: AuthenticatedResultsRouteTestContext, assert) {
this.server.createList("document", 10);

await visit("/results");

assert
.dom(".product-badge-link")
.hasAttribute("href", "/all?product=%5B%22Vault%22%5D");
});
});
Loading