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

Component-ize Project documents (Doc::TileMedium) #459

Merged
merged 5 commits into from
Nov 29, 2023
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
119 changes: 119 additions & 0 deletions web/app/components/doc/tile-medium.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{{! Notes:
- The hover effect requires a parent with the `group` class.
- Non-essential links have `tabindex="-1"` so they're not focusable
with the keyboard. This allows the user to tab through documents
without having to skip through the meta links that are otherwise
accessible on the document details screen.
}}
<div class="tile">
<div class="flex justify-between gap-[18px] pl-3 pr-8 pt-5 pb-6">
{{! Avatar }}
<LinkTo
data-test-document-owner-avatar
tabindex="-1"
@route="authenticated.documents"
@query={{hash owners=(array (get @doc.owners 0))}}
>
<Person::Avatar
@size="large"
@email="{{get @doc.owners 0}}"
@imgURL={{get @doc.ownerPhotos 0}}
@isLoading={{@avatarIsLoading}}
class="relative z-10 -mt-1 shrink-0"
/>
</LinkTo>

{{! Text }}
<div class="w-full">
<div class="mt-0.5 overflow-hidden">
<LinkTo
data-test-document-link
@route="authenticated.document"
@model={{@doc.googleFileID}}
>
{{! Primary click area }}
<div
aria-hidden="true"
class="absolute top-0 left-0 -bottom-px w-full group-focus-within:bg-color-surface-faint group-hover:bg-color-surface-faint"
></div>

<h3 class="relative">
{{! Title }}
<span data-test-document-title class="mr-1.5">
{{@doc.title}}
</span>

{{! Doc Number }}
<span data-test-document-number class="shrink-0 font-regular">
<span class="whitespace-nowrap">
{{@doc.documentNumber}}
</span>
</span>
</h3>
</LinkTo>
</div>

<div class="pointer-events-none relative">
<div class="mt-1.5 flex gap-[5px] text-color-foreground-faint">
By
{{! Owner }}
<LinkTo
tabindex="-1"
data-test-document-owner-name
@route="authenticated.documents"
@query={{hash owners=(array (get @doc.owners 0))}}
class="underline underline-offset-[3px] hover:text-color-foreground-strong"
>
{{get @doc.owners 0}}
</LinkTo>
<span class="vertical-line">
|
</span>
{{! Product }}
<ProductLink
tabindex="-1"
class="underline underline-offset-[3px] hover:text-color-foreground-strong"
>
<:default>
{{@doc.product}}
</:default>
</ProductLink>
<span class="vertical-line">
|
</span>
{{! Created time }}
{{time-ago @doc.createdTime}}
</div>

{{! Summary }}
{{#if @doc.summary}}
<p data-test-document-summary class="mt-2.5 text-body-300">
{{@doc.summary}}
</p>
{{/if}}

<div class="tags mt-3.5">
{{! Status }}
<Doc::State
data-test-document-status
@state={{@doc.status}}
@hideProgress={{true}}
class="interactive"
/>
{{! Doc type }}
<Hds::Badge data-test-document-type @text={{@doc.documentType}} />
</div>
</div>
</div>

{{! Thumbnail }}
<div class="pointer-events-none relative ml-4 shrink-0">
<Doc::Thumbnail
@status={{@doc.status}}
@product={{@doc.product}}
@size="medium"
class="self-start"
/>
</div>
</div>
</div>
21 changes: 21 additions & 0 deletions web/app/components/doc/tile-medium.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Component from "@glimmer/component";
import { RelatedHermesDocument } from "../related-resources";

interface DocTileMediumComponentSignature {
Element: HTMLAnchorElement;
Args: {
doc: RelatedHermesDocument;
avatarIsLoading?: boolean;
};
Blocks: {
default: [];
};
}

export default class DocTileMediumComponent extends Component<DocTileMediumComponentSignature> {}

declare module "@glint/environment-ember-loose/registry" {
export default interface Registry {
"Doc::TileMedium": typeof DocTileMediumComponent;
}
}
1 change: 1 addition & 0 deletions web/app/components/person/avatar.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div
data-test-person-avatar
data-test-is-loading={{@isLoading}}
class="avatar overflow-hidden rounded-full
{{unless @isLoading 'bg-color-palette-alpha-100'}}
{{this.size}}
Expand Down
111 changes: 4 additions & 107 deletions web/app/components/project/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -242,113 +242,10 @@
)
}}
>
<div class="px-2 pt-5 pb-7">
<div class="flex items-start gap-4">
{{! Avatar }}
<LinkTo
data-test-document-owner-avatar
@route="authenticated.documents"
@query={{hash owners=(array (get document.owners 0))}}
>
<Person::Avatar
@email="{{get document.owners 0}}"
@imgURL={{get document.ownerPhotos 0}}
@size="large"
class="relative z-10 -mt-1 shrink-0"
/>
</LinkTo>

{{! Text }}
<div class="w-full overflow-hidden">
<LinkTo
data-test-document-link
@route="authenticated.document"
@model={{document.googleFileID}}
>
{{! Primary click area }}
<div
aria-hidden="true"
class="absolute top-0 left-0 -bottom-px w-full group-focus-within:bg-color-surface-faint group-hover:bg-color-surface-faint"
></div>

{{! Title and docNumber }}
<div class="relative z-10 overflow-hidden">
<h4
class="text-display-300 text-color-foreground-strong"
>
<span data-test-document-title class="mr-1.5">
{{document.title}}
</span>
<span
data-test-document-number
class="shrink-0 font-regular text-color-foreground-faint"
>
<span class="whitespace-nowrap">
{{document.documentNumber}}
</span>
</span>
</h4>
</div>
</LinkTo>
<div class="pointer-events-none relative z-10 mt-1.5">
By
<LinkTo
data-test-document-owner-name
@route="authenticated.documents"
@query={{hash owners=(array (get document.owners 0))}}
class="pointer-events-auto text-color-foreground-faint underline underline-offset-[3px] hover:text-color-foreground-strong"
>
{{get document.owners 0}}
</LinkTo>
</div>
<div class="pointer-events-none relative z-10">
{{#if document.summary}}
<p
data-test-document-summary
class="relative z-10 mt-2.5 text-body-200"
>
{{document.summary}}
</p>
{{/if}}

{{! Document tags }}
<div class="mt-3.5 flex items-center gap-1">
<LinkTo
data-test-document-status
@route="authenticated.documents"
@query={{hash status=(array document.status)}}
class="pointer-events-auto"
>
<Doc::State
@state={{document.status}}
@hideProgress={{true}}
class="interactive"
/>
</LinkTo>
<LinkTo
data-test-document-type
@route="authenticated.documents"
@query={{hash
docType=(array document.documentType)
}}
class="pointer-events-auto"
>
<Hds::Badge
@text={{document.documentType}}
class="hover:bg-color-palette-neutral-200"
/>
</LinkTo>
</div>
</div>
</div>
<Doc::Thumbnail
@product={{document.product}}
@status={{document.status}}
@size="medium"
class="pointer-events-none ml-6 mr-8 shrink-0"
/>
</div>
</div>
<Doc::TileMedium
@doc={{document}}
@avatarIsLoading={{this.getOwnerPhoto.isRunning}}
/>
</Project::Resource>
</li>
{{/each}}
Expand Down
25 changes: 24 additions & 1 deletion web/app/components/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { RelatedResourceSelector } from "hermes/components/related-resources";
import { inject as service } from "@ember/service";
import FetchService from "hermes/services/fetch";
import { task } from "ember-concurrency";
import { enqueueTask, task } from "ember-concurrency";
import { HermesProject, JiraIssue } from "hermes/types/project";
import {
ProjectStatus,
Expand Down Expand Up @@ -246,6 +246,8 @@ export default class ProjectIndexComponent extends Component<ProjectIndexCompone
* Adds a resource to the correct array, then saves the project.
*/
@action protected addDocument(resource: RelatedHermesDocument) {
void this.getOwnerPhoto.perform(resource.googleFileID);

const cachedDocuments = this.hermesDocuments.slice();

this.hermesDocuments.unshiftObject(resource);
Expand Down Expand Up @@ -298,6 +300,27 @@ export default class ProjectIndexComponent extends Component<ProjectIndexCompone
this.resourceToEditIndex = undefined;
}

/**
* The task to get the owner photo for a document.
*/
private getOwnerPhoto = enqueueTask(async (docID: string) => {
const doc = await this.fetchSvc
.fetch(`/api/${this.configSvc.config.api_version}/documents/${docID}`)
.then((response) => response?.json());

const ownerPhoto = doc.ownerPhotos[0];

if (ownerPhoto) {
const hermesDoc = this.hermesDocuments.find(
(doc) => doc.googleFileID === docID,
);

if (hermesDoc) {
hermesDoc.ownerPhotos = [ownerPhoto];
}
}
});

/**
* The action to save basic project attributes,
* such as title, description, and status.
Expand Down
2 changes: 2 additions & 0 deletions web/app/components/related-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export interface RelatedHermesDocument {
title: string;
documentType: string;
documentNumber: string;
createdTime: number;
modifiedTime: number;
sortOrder: number;
product: string;
status: string;
Expand Down
8 changes: 4 additions & 4 deletions web/app/styles/components/doc/thumbnail.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@
}

&.medium {
@apply w-16;
@apply w-[72px];

.status-icon {
@apply top-[6px] h-[60px] w-[60px];
@apply h-[52px] w-[52px];

&.approved {
@apply -right-2.5;
@apply -right-2 top-1;
}

&.obsolete {
@apply -left-3.5;
@apply top-[3px] -left-2.5;
}
}
}
Expand Down
20 changes: 19 additions & 1 deletion web/app/styles/components/doc/tile.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
.doc-tile-title {
@apply text-display-200 font-semibold text-color-foreground-strong overflow-hidden;
@apply overflow-hidden text-display-200 font-semibold text-color-foreground-strong;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
line-clamp: 3;
}

.tile {
.vertical-line {
@apply text-color-foreground-faint opacity-50;
}

.tags {
@apply flex shrink-0 gap-1;
}

h3 {
@apply text-display-300 text-color-foreground-strong;
}

a {
@apply pointer-events-auto;
}
}
2 changes: 1 addition & 1 deletion web/app/styles/components/project.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
}

.overflow-button-container {
@apply absolute right-1 top-1;
@apply absolute right-1 top-1 z-10 h-[calc(100%-16px)] items-start;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The overflow-button gradient was still slightly visible even after #452

@apply from-color-page-faint;
}
}
Expand Down
1 change: 1 addition & 0 deletions web/app/utils/mirage-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ConfigService from "hermes/services/config";

export const TEST_USER_NAME = "Test user";
export const TEST_USER_EMAIL = "testuser@hashicorp.com";
export const TEST_USER_PHOTO = "https://test-user-at-hashicorp.com/photo.jpg";
export const TEST_USER_GIVEN_NAME = "Test";

export const TEST_USER_2_NAME = "Foo Bar";
Expand Down
Loading