Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into jfreda/api-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
jfreda committed Oct 20, 2023
2 parents 14ae928 + 48f146b commit 65b376e
Show file tree
Hide file tree
Showing 29 changed files with 513 additions and 50 deletions.
18 changes: 13 additions & 5 deletions internal/api/documents_related_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ type externalLinkRelatedResourceGetResponse struct {
}

type hermesDocumentRelatedResourceGetResponse struct {
GoogleFileID string `json:"googleFileID"`
Title string `json:"title"`
DocumentType string `json:"documentType"`
DocumentNumber string `json:"documentNumber"`
SortOrder int `json:"sortOrder"`
GoogleFileID string `json:"googleFileID"`
Title string `json:"title"`
DocumentType string `json:"documentType"`
DocumentNumber string `json:"documentNumber"`
SortOrder int `json:"sortOrder"`
Status string `json:"status"`
Owners []string `json:"owners"`
OwnerPhotos []string `json:"ownerPhotos"`
Product string `json:"product"`
}

func documentsResourceRelatedResourcesHandler(
Expand Down Expand Up @@ -153,6 +157,10 @@ func documentsResourceRelatedResourcesHandler(
DocumentType: doc.DocType,
DocumentNumber: doc.DocNumber,
SortOrder: hdrr.RelatedResource.SortOrder,
Status: doc.Status,
Owners: doc.Owners,
OwnerPhotos: doc.OwnerPhotos,
Product: doc.Product,
})
}

Expand Down
10 changes: 5 additions & 5 deletions web/app/components/doc/folder-affordance.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
data-test-doc-thumbnail-folder-affordance
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox={{if @isLarge "0 0 97 145" "0 0 43 63"}}
viewBox={{if this.sizeIsLarge "0 0 97 145" "0 0 43 63"}}
class="folder-affordance"
>
<path
fill="url(#doc-thumbnail-folder-gradient)"
stroke="currentColor"
fill-rule="evenodd"
d={{if
@isLarge
this.sizeIsLarge
"M6 0a6 6 0 0 0-6 6v41.04a6 6 0 0 0 2.659 4.983l8.29 5.558v80.729a6 6 0 0 0 6 6H97V0H6Z"
"M3 0a3 3 0 0 0-3 3v18.407a3 3 0 0 0 .91 2.152l2.18 2.117v33.746a3 3 0 0 0 3 3H43V0H3Z"
}}
Expand All @@ -19,10 +19,10 @@
<defs>
<linearGradient
id="doc-thumbnail-folder-gradient"
x1={{if @isLarge "8.176" "4.746"}}
x2={{if @isLarge "8.176" "4.746"}}
x1={{if this.sizeIsLarge "8.176" "4.746"}}
x2={{if this.sizeIsLarge "8.176" "4.746"}}
y1="0"
y2={{if @isLarge "43.965" "19.018"}}
y2={{if this.sizeIsLarge "43.965" "19.018"}}
gradientUnits="userSpaceOnUse"
>
<stop stop-color="var(--token-color-palette-neutral-50)"></stop>
Expand Down
8 changes: 6 additions & 2 deletions web/app/components/doc/folder-affordance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import Component from "@glimmer/component";

interface DocFolderAffordanceSignature {
Args: {
isLarge?: boolean;
size?: "large";
};
}

export default class DocFolderAffordance extends Component<DocFolderAffordanceSignature> {}
export default class DocFolderAffordance extends Component<DocFolderAffordanceSignature> {
protected get sizeIsLarge(): boolean {
return this.args.size === "large";
}
}

declare module "@glint/environment-ember-loose/registry" {
export default interface Registry {
Expand Down
10 changes: 5 additions & 5 deletions web/app/components/doc/thumbnail.hbs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<div
data-test-doc-thumbnail
class="doc-thumbnail
{{if @isLarge 'large'}}
{{if this.sizeIsLarge 'large'}}
{{if this.isObsolete 'obsolete'}}
bg-color-palette-neutral-100 rounded"
rounded bg-color-palette-neutral-100"
...attributes
>
<img src="/images/document.png" class="w-full h-auto" />
<img src="/images/document.png" class="h-auto w-full" />

<div class="w-full h-full absolute">
<div class="absolute h-full w-full">
{{#if this.isObsolete}}
<Doc::FolderAffordance @isLarge={{@isLarge}} />
<Doc::FolderAffordance @size={{@size}} />
{{/if}}

{{#if (or this.isApproved this.isObsolete)}}
Expand Down
6 changes: 5 additions & 1 deletion web/app/components/doc/thumbnail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import getProductId from "hermes/utils/get-product-id";
interface DocThumbnailComponentSignature {
Element: HTMLDivElement;
Args: {
isLarge?: boolean;
status?: string;
product?: string;
size?: "large";
};
}

Expand All @@ -20,6 +20,10 @@ export default class DocThumbnailComponent extends Component<DocThumbnailCompone
}
}

protected get sizeIsLarge(): boolean {
return this.args.size === "large";
}

protected get productShortName(): string | null {
if (this.args.product) {
return getProductId(this.args.product);
Expand Down
2 changes: 1 addition & 1 deletion web/app/components/doc/tile.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<Doc::Thumbnail
@status={{@status}}
@product={{@productArea}}
@isLarge={{true}}
@size="large"
/>
<Doc::State @state={{@status}} />
</div>
Expand Down
12 changes: 11 additions & 1 deletion web/app/components/editable-field.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
import { next, schedule, scheduleOnce } from "@ember/runloop";
import { schedule, scheduleOnce } from "@ember/runloop";
import { assert } from "@ember/debug";
import { guidFor } from "@ember/object/internals";
import { HermesDocument, HermesUser } from "hermes/types/document";
import blinkElement from "hermes/utils/blink-element";

export const FOCUSABLE =
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
Expand Down Expand Up @@ -185,6 +186,7 @@ export default class EditableFieldComponent extends Component<EditableFieldCompo
*/
@action protected disableEditing() {
this.editingIsEnabled = false;
this.emptyValueErrorIsShown = false;
}

/**
Expand Down Expand Up @@ -255,9 +257,17 @@ export default class EditableFieldComponent extends Component<EditableFieldCompo
(newValue instanceof Array && newValue.length === 0)
) {
if (this.args.isRequired) {
if (this.emptyValueErrorIsShown) {
const error =
this.editingContainer?.querySelector(".hds-form-error");
blinkElement(error);
return;
}

this.emptyValueErrorIsShown = true;
return;
}

/**
* We don't consider an empty value to be a change
* if the initial value is undefined.
Expand Down
6 changes: 1 addition & 5 deletions web/app/components/hermes-logo.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{{! @glint-nocheck: not typesafe yet }}
<div
class="hermes-logo"
...attributes
>
<div class="hermes-logo" ...attributes>
<FlightIcon @name="hashicorp" @size="24" />
<div class="hermes-logo-divider"></div>
<div class="hermes-logo-text">
Expand Down
7 changes: 6 additions & 1 deletion web/app/components/hermes-logo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import Component from "@glimmer/component";

interface HermesLogoComponentSignature {
Element: HTMLDivElement;
Args: {};
}

export default class HermesLogoComponent extends Component<HermesLogoComponentSignature> {}

declare module "@glint/environment-ember-loose/registry" {
export default interface Registry {
HermesLogo: typeof HermesLogoComponent;
}
}
2 changes: 2 additions & 0 deletions web/app/components/inputs/product-select.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
@placement={{@placement}}
@isSaving={{@isSaving}}
@renderOut={{@renderOut}}
@offset={{@offset}}
@matchAnchorWidth={{@matchAnchorWidth}}
@secondaryFilterAttribute="abbreviation"
class="product-select-dropdown-list w-[300px]"
...attributes
Expand Down
5 changes: 4 additions & 1 deletion web/app/components/inputs/product-select.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assert } from "@ember/debug";
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import { Placement } from "@floating-ui/dom";
import { OffsetOptions, Placement } from "@floating-ui/dom";
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { task } from "ember-concurrency";
Expand All @@ -10,6 +10,7 @@ import ProductAreasService, {
ProductArea,
} from "hermes/services/product-areas";
import getProductId from "hermes/utils/get-product-id";
import { MatchAnchorWidthOptions } from "../floating-u-i/content";

interface InputsProductSelectSignature {
Element: HTMLDivElement;
Expand All @@ -20,6 +21,8 @@ interface InputsProductSelectSignature {
placement?: Placement;
isSaving?: boolean;
renderOut?: boolean;
offset?: OffsetOptions;
matchAnchorWidth?: MatchAnchorWidthOptions;
};
}

Expand Down
49 changes: 49 additions & 0 deletions web/app/components/new/project-form.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<form
data-test-project-form
{{on "submit" this.maybeSubmitForm}}
class="mx-auto mb-10 max-w-xl"
>
<div class="space-y-4">
<h1>Start a project</h1>
</div>
<div class="mt-7 grid gap-7">
<Hds::Form::Textarea::Field
{{on "keydown" this.onKeydown}}
{{auto-height-textarea}}
{{autofocus}}
data-test-title
@value={{this.title}}
name="title"
placeholder="Enter a project title"
as |F|
>
<F.Label>Title</F.Label>
{{#if this.errorIsShown}}
<F.Error data-test-title-error>
Title is required.
</F.Error>
{{/if}}
</Hds::Form::Textarea::Field>

<Hds::Form::Textarea::Field
data-test-description
{{on "keydown" this.onKeydown}}
@value={{this.description}}
rows="2"
placeholder="A short summary of your project"
name="description"
as |F|
>
<F.Label>Description</F.Label>
</Hds::Form::Textarea::Field>

{{! TODO: Add Jira integration }}

</div>
<Hds::Button
data-test-submit
@text="Create project"
@isFullWidth={{true}}
type="submit"
/>
</form>
88 changes: 88 additions & 0 deletions web/app/components/new/project-form.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { action } from "@ember/object";
import RouterService from "@ember/routing/router-service";
import { next } from "@ember/runloop";
import { inject as service } from "@ember/service";
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import FlashMessageService from "ember-cli-flash/services/flash-messages";
import { task } from "ember-concurrency";
import FetchService from "hermes/services/fetch";
import cleanString from "hermes/utils/clean-string";

interface NewProjectFormComponentSignature {
Args: {};
}

export default class NewProjectFormComponent extends Component<NewProjectFormComponentSignature> {
@service("fetch") declare fetchSvc: FetchService;
@service declare router: RouterService;
@service declare flashMessages: FlashMessageService;

@tracked protected title: string = "";
@tracked protected description: string = "";

@tracked protected formIsValid = false;
@tracked protected errorIsShown = false;

@action maybeSubmitForm(event?: SubmitEvent) {
if (event) {
event.preventDefault();
}

this.validateForm();

if (this.formIsValid) {
this.createProject.perform();
}
}

private validateForm() {
this.errorIsShown = this.title.length === 0;
this.formIsValid = this.title.length > 0;
}

@action protected onKeydown(e: KeyboardEvent) {
if (e.key === "Enter") {
// Replace newline function with submit action
e.preventDefault();
this.maybeSubmitForm();
}
if (this.errorIsShown) {
// Validate once the input value are captured
next("afterRender", () => {
this.validateForm();
});
}
}

private createProject = task(async () => {
try {
const project = await this.fetchSvc
.fetch("/api/v1/projects", {
method: "POST",
body: JSON.stringify({
title: cleanString(this.title),
description: cleanString(this.description),
}),
})
.then((response) => response?.json());
this.router.transitionTo("authenticated.projects.project", project.id);
} catch (error: unknown) {
const typedError = error as Error;

this.flashMessages.add({
title: "Error creating project",
message: typedError.message,
type: "critical",
timeout: 6000,
extendedTimeout: 1000,
});
}
});
}

declare module "@glint/environment-ember-loose/registry" {
export default interface Registry {
"New::ProjectForm": typeof NewProjectFormComponent;
}
}
4 changes: 4 additions & 0 deletions web/app/components/related-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export interface RelatedHermesDocument {
documentType: string;
documentNumber: string;
sortOrder: number;
status: string;
owners?: string[];
ownerPhotos?: string[];
product?: string;
}

export enum RelatedResourcesScope {
Expand Down
3 changes: 3 additions & 0 deletions web/app/components/related-resources/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ export default class RelatedResourcesAddComponent extends Component<RelatedResou
title: attrs.title,
documentType: attrs.docType,
documentNumber: attrs.docNumber,
owners: attrs.owners,
ownerPhotos: attrs.ownerPhotos,
product: attrs.product,
sortOrder: 1,
} as RelatedHermesDocument;

Expand Down
Loading

0 comments on commit 65b376e

Please sign in to comment.