From 1637b68d16b7e23c267d73d468b8a48243370d40 Mon Sep 17 00:00:00 2001 From: Jeff Daley Date: Wed, 6 Sep 2023 10:33:06 -0400 Subject: [PATCH 1/7] Remove console.logs --- web/app/routes/authenticated/document.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/web/app/routes/authenticated/document.ts b/web/app/routes/authenticated/document.ts index eb8ea0dc8..a7771e65d 100644 --- a/web/app/routes/authenticated/document.ts +++ b/web/app/routes/authenticated/document.ts @@ -63,7 +63,6 @@ export default class DocumentRoute extends Route { let doc = {}; let draftFetched = false; - console.log("params.draft", params.draft); // Get doc data from the app backend. if (params.draft) { try { @@ -106,7 +105,6 @@ export default class DocumentRoute extends Route { .then((r) => r?.json()); (doc as HermesDocument).isDraft = false; - console.log("isDraft?", (doc as HermesDocument).isDraft); } catch (err) { const typedError = err as Error; this.showErrorMessage(typedError); @@ -121,8 +119,6 @@ export default class DocumentRoute extends Route { // make a background call to update the front-end index. void this.recentDocs.fetchAll.perform(); - console.log("Document fetched: ", doc); - let typedDoc = doc as HermesDocument; // Record analytics. @@ -165,8 +161,6 @@ export default class DocumentRoute extends Route { } } - console.log("typedDoc", typedDoc); - let docTypes = await this.fetchSvc .fetch("/api/v1/document-types") .then((r) => r?.json()); From adb2db109b85a28a1401dcaf967f7063c654e005 Mon Sep 17 00:00:00 2001 From: Jeff Daley Date: Wed, 6 Sep 2023 10:35:02 -0400 Subject: [PATCH 2/7] Update document.ts --- web/app/routes/authenticated/document.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/web/app/routes/authenticated/document.ts b/web/app/routes/authenticated/document.ts index a7771e65d..8ef126942 100644 --- a/web/app/routes/authenticated/document.ts +++ b/web/app/routes/authenticated/document.ts @@ -28,6 +28,11 @@ interface DocumentRouteParams { draft: boolean; } +interface DocumentRouteModel { + doc: HermesDocument; + docType: HermesDocumentType; +} + export default class DocumentRoute extends Route { @service("config") declare configSvcL: ConfigService; @service("fetch") declare fetchSvc: FetchService; @@ -182,7 +187,7 @@ export default class DocumentRoute extends Route { * `modelIsChanging` property to remove and rerender the sidebar, * resetting its local state to reflect the new model data. */ - afterModel(model: any, transition: any) { + afterModel(_model: DocumentRouteModel, transition: any) { if (transition.from) { if (transition.from.name === transition.to.name) { if ( From ed43ee74762a321bfa08a7588392d8d76a323ace Mon Sep 17 00:00:00 2001 From: Jeff Daley Date: Mon, 11 Sep 2023 10:58:49 -0400 Subject: [PATCH 3/7] Improve loading states --- web/app/components/custom-editable-field.hbs | 4 +- web/app/components/custom-editable-field.ts | 2 +- web/app/components/document/index.hbs | 10 +- web/app/components/document/index.ts | 16 +++- web/app/components/document/sidebar.hbs | 22 +++-- web/app/components/document/sidebar.ts | 63 ++++++++++++- .../components/document/sidebar/header.hbs | 2 +- web/app/components/document/sidebar/header.ts | 1 + web/app/components/editable-field.hbs | 26 +++-- web/app/components/editable-field.ts | 7 +- .../inputs/product-select/index.hbs | 4 +- web/app/routes/authenticated/document.ts | 94 +++---------------- web/app/styles/components/editable-field.scss | 6 -- web/app/templates/authenticated/document.hbs | 8 +- .../components/editable-field-test.ts | 2 +- 15 files changed, 140 insertions(+), 127 deletions(-) diff --git a/web/app/components/custom-editable-field.hbs b/web/app/components/custom-editable-field.hbs index be7c5f777..914d62e69 100644 --- a/web/app/components/custom-editable-field.hbs +++ b/web/app/components/custom-editable-field.hbs @@ -3,7 +3,7 @@ data-test-custom-string-field @value={{get @document @field}} @onChange={{@onChange}} - @loading={{@loading}} + @isSaving={{@isSaving}} @disabled={{@disabled}} > <:default as |F|> @@ -31,7 +31,7 @@ data-test-custom-people-field @value={{get @attributes "value"}} @onChange={{@onChange}} - @loading={{@loading}} + @isSaving={{@isSaving}} @disabled={{@disabled}} > <:default> diff --git a/web/app/components/custom-editable-field.ts b/web/app/components/custom-editable-field.ts index 1d7e9fc79..83d0e4412 100644 --- a/web/app/components/custom-editable-field.ts +++ b/web/app/components/custom-editable-field.ts @@ -13,7 +13,7 @@ interface CustomEditableFieldComponentSignature { field: string; attributes: CustomEditableField; onChange: (value: any) => void; - loading?: boolean; + isSaving?: boolean; disabled?: boolean; }; } diff --git a/web/app/components/document/index.hbs b/web/app/components/document/index.hbs index 9a63b6b88..65e4008a0 100644 --- a/web/app/components/document/index.hbs +++ b/web/app/components/document/index.hbs @@ -1,4 +1,7 @@ -
+
-
+
{{#unless @modelIsChanging}} {{! diff --git a/web/app/components/document/index.ts b/web/app/components/document/index.ts index 0095d517d..09301b0e9 100644 --- a/web/app/components/document/index.ts +++ b/web/app/components/document/index.ts @@ -12,7 +12,6 @@ import { action } from "@ember/object"; interface DocumentIndexComponentSignature { document: HermesDocument; - docType: string; modelIsChanging: boolean; } @@ -30,6 +29,21 @@ export default class DocumentIndexComponent extends Component { try { let fetchResponse = await this.fetchSvc.fetch("/api/v1/drafts/" + docID, { diff --git a/web/app/components/document/sidebar.hbs b/web/app/components/document/sidebar.hbs index 4a78708b4..7a1456106 100644 --- a/web/app/components/document/sidebar.hbs +++ b/web/app/components/document/sidebar.hbs @@ -1,4 +1,5 @@ @@ -146,7 +147,7 @@ data-test-editable={{this.isOwner}} @value={{this.summary}} @onChange={{perform this.updateSummary}} - @loading={{this.save.isRunning}} + @isSaving={{this.save.isRunning}} @disabled={{not this.isOwner}} > <:default as |F|> @@ -213,7 +214,8 @@ data-test-editable={{this.isOwner}} @value={{this.contributors}} @onChange={{perform this.save "contributors"}} - @loading={{this.save.isRunning}} + @isLoading={{this.serializeContributorsAndApprovers.isRunning}} + @isSaving={{this.save.isRunning}} @disabled={{not this.isOwner}} > <:default> @@ -251,7 +253,8 @@ data-test-editable={{this.isOwner}} @value={{this.approvers}} @onChange={{perform this.save "approvers"}} - @loading={{this.save.isRunning}} + @isLoading={{this.serializeContributorsAndApprovers.isRunning}} + @isSaving={{this.save.isRunning}} @disabled={{this.editingIsDisabled}} > <:default> @@ -321,7 +324,7 @@ @field={{field}} @attributes={{attributes}} @onChange={{perform this.save field}} - @loading={{this.save.isRunning}} + @isSaving={{this.save.isRunning}} @disabled={{not this.isOwner}} />
@@ -378,7 +381,7 @@ @size="medium" @color="primary" class="w-full" - {{on "click" (fn (set this "requestReviewModalIsShown" true))}} + {{on "click" (set this "requestReviewModalIsShown" true)}} /> <:default as |M|> {{#if M.taskIsRunning}} @@ -575,9 +579,9 @@ Approvers - {{#if @docType.checks.length}} + {{#if this.docType.checks}} {{! For now, we only support one check }} - {{#each (take 1 @docType.checks) as |check|}} + {{#each (take 1 this.docType.checks) as |check|}}
{ + return people.map((p) => ({ + email: p.emailAddresses[0]?.value as string, + imgURL: p.photos?.[0]?.url, + })); +}; + interface DocumentSidebarComponentSignature { Args: { profile: AuthenticatedUser; document: HermesDocument; - docType: HermesDocumentType; deleteDraft: (docId: string) => void; isCollapsed: boolean; toggleCollapsed: () => void; @@ -69,6 +76,8 @@ export default class DocumentSidebarComponent extends Component { + const docTypes = (await this.fetchSvc + .fetch("/api/v1/document-types") + .then((r) => r?.json())) as HermesDocumentType[]; + + assert("docTypes must exist", docTypes); + + const docType = docTypes.find( + (dt) => dt.name === this.args.document.docType + ); + + assert("docType must exist", docType); + this.docType = docType; + }); + @action refreshRoute() { // We force refresh due to a bug with `refreshModel: true` // See: https://github.com/emberjs/ember.js/issues/19260 @@ -506,6 +530,43 @@ export default class DocumentSidebarComponent extends Component { + let maybePromises = []; + + const contributorsPromise = this.fetchSvc + .fetch(`/api/v1/people?emails=${this.contributors.join(",")}`) + .then((r) => r?.json()); + + const approversPromise = this.fetchSvc + .fetch(`/api/v1/people?emails=${this.approvers.join(",")}`) + .then((r) => r?.json()); + + maybePromises.push(this.contributors.length ? contributorsPromise : []); + maybePromises.push(this.approvers.length ? approversPromise : []); + + if (!maybePromises.length) { + return; + } + + const [contributors, approvers] = await Promise.all(maybePromises); + + console.log("contributors", contributors); + console.log("approvers", approvers); + + if (contributors.length) { + this.contributors = serializePeople(contributors); + } + + if (approvers.length) { + this.approvers = serializePeople(approvers); + } + }); + /** * A task that waits for a short time and then resolves. * Used to trigger the "link created" state of the share button. diff --git a/web/app/components/document/sidebar/header.hbs b/web/app/components/document/sidebar/header.hbs index 38095958c..03f11338c 100644 --- a/web/app/components/document/sidebar/header.hbs +++ b/web/app/components/document/sidebar/header.hbs @@ -1,4 +1,4 @@ -