Skip to content

Commit

Permalink
Merge branch 'main' into anubhavmishra/version-and-revision
Browse files Browse the repository at this point in the history
  • Loading branch information
anubhavmishra authored Aug 21, 2023
2 parents a4e1e10 + b6fa8c9 commit d532d68
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 38 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ Hermes can be configured to point to any PostgreSQL database, but for running lo
make docker/postgres/start
```

The database password can be configured via the Hermes config.hcl or the `HERMES_SERVER_POSTGRES_PASSWORD` environment variable.

### Run the Server

```sh
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/commands/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ func (c *Command) Run(args []string) int {
}

// Initialize database.
if val, ok := os.LookupEnv("HERMES_SERVER_POSTGRES_PASSWORD"); ok {
cfg.Postgres.Password = val
}
db, err := db.NewDB(*cfg.Postgres)
if err != nil {
c.UI.Error(fmt.Sprintf("error initializing database: %v", err))
Expand Down
2 changes: 1 addition & 1 deletion internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"runtime/debug"
)

const Version = "0.2.0"
const Version = "0.3.0"

// GetVersion returns
// the version number
Expand Down
2 changes: 1 addition & 1 deletion web/app/components/doc/tile.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="group relative">
<div class="group relative" ...attributes>
<LinkTo
@route="authenticated.document"
@model={{@docID}}
Expand Down
1 change: 1 addition & 0 deletions web/app/components/doc/tile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Component from "@glimmer/component";

interface DocTileComponentSignature {
Element: HTMLDivElement;
Args: {
avatar?: string;
docID?: string;
Expand Down
1 change: 1 addition & 0 deletions web/app/components/document/modal.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<Hds::Modal
...attributes
@onClose={{@close}}
@color={{@color}}
@isDismissDisabled={{this.taskIsRunning}}
Expand Down
1 change: 1 addition & 0 deletions web/app/components/document/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { task } from "ember-concurrency";
import { HdsModalColor } from "hds/_shared";

interface DocumentModalComponentSignature {
Element: HTMLDialogElement;
Args: {
headerText: string;
bodyText?: string;
Expand Down
66 changes: 41 additions & 25 deletions web/app/components/document/sidebar.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@
{{#if this.isOwner}}
<div class="flex items-start gap-2 px-3">
<Hds::Button
data-test-sidebar-publish-for-review-button
@text="Publish for review..."
@size="medium"
@color="primary"
Expand Down Expand Up @@ -547,6 +548,7 @@

{{#if this.requestReviewModalIsShown}}
<Document::Modal
data-test-publish-for-review-modal
@headerText="Publish for review"
@errorTitle="Error requesting review"
@close={{this.closeRequestReviewModal}}
Expand All @@ -561,7 +563,10 @@
>
<:default as |M|>
{{#if M.taskIsRunning}}
<div class="grid place-items-center pt-1 pb-12">
<div
data-test-publishing-for-review-message
class="grid place-items-center pt-1 pb-12"
>
<div class="text-center">
<FlightIcon @name="loading" @size="24" class="mb-5" />
<h2>Submitting for review...</h2>
Expand Down Expand Up @@ -668,49 +673,60 @@
{{/if}}

{{#if this.docPublishedModalIsShown}}
<Hds::Modal as |M|>
<Hds::Modal data-test-doc-published-modal as |M|>
<M.Header>
<div class="flex items-center">
<FlightIcon
@name="check-circle-fill"
class="text-color-palette-green-200 mr-2"
class="mr-2 text-color-palette-green-200"
/>
Document published!
</div>
</M.Header>
<M.Body>
<p class="text-body-300 mb-5">
<p class="text-body-300">
Your doc is now available to everyone in your workspace.
<br />
Weʼve notified your approvers and subscribers to this product/area.
</p>
<label
class="hermes-form-label mb-1"
for="recently-published-share-url"
>
Share it with others
</label>
<Hds::Form::TextInput::Base
id="recently-published-share-url"
class="text-body-300 pl-2.5 mb-1.5"
@value={{this.shareURL}}
{{select-on-focus}}
readonly
/>
{{#unless this.docNumberLookupHasFailed}}
<label
class="hermes-form-label mb-1 mt-5"
for="recently-published-share-url"
>
Share it with others
</label>
<Hds::Form::TextInput::Base
data-test-share-document-url-input
id="recently-published-share-url"
class="mb-1.5 pl-2.5 text-body-300"
@value={{this.shareURL}}
{{select-on-focus}}
readonly
/>
{{/unless}}
</M.Body>
<M.Footer>
<Hds::ButtonSet>

<CopyURLButton
@url={{this.shareURL}}
class="hds-button hds-button--size-medium hds-button--color-primary"
/>
{{#unless this.docNumberLookupHasFailed}}
<CopyURLButton
data-test-doc-published-copy-url-button
@url={{this.shareURL}}
class="hds-button hds-button--size-medium hds-button--color-primary"
/>
{{/unless}}
<Hds::Button
data-test-continue-to-document-button
{{on "click" (set this "docPublishedModalIsShown" false)}}
@text="Continue to document"
@icon="arrow-right"
@iconPosition="trailing"
@color="tertiary"
@icon={{unless this.docNumberLookupHasFailed "arrow-right"}}
@iconPosition={{unless this.docNumberLookupHasFailed "trailing"}}
@color={{if this.docNumberLookupHasFailed "primary" "tertiary"}}
data-test-color={{if
this.docNumberLookupHasFailed
"primary"
"tertiary"
}}
/>
</Hds::ButtonSet>
</M.Footer>
Expand Down
48 changes: 45 additions & 3 deletions web/app/components/document/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import Ember from "ember";
import htmlElement from "hermes/utils/html-element";
import ConfigService from "hermes/services/config";
import isValidURL from "hermes/utils/is-valid-u-r-l";
import { HermesDocumentType } from "hermes/types/document-type";

interface DocumentSidebarComponentSignature {
Args: {
profile: AuthenticatedUser;
document: HermesDocument;
docType: string;
docType: HermesDocumentType;
deleteDraft: (docId: string) => void;
isCollapsed: boolean;
toggleCollapsed: () => void;
Expand Down Expand Up @@ -76,8 +77,13 @@ export default class DocumentSidebarComponent extends Component<DocumentSidebarC
);
}

/**
* Whether the doc is a draft.
* If the draft was recently published, return false.
* Otherwise use the passed-in isDraft property.
*/
get isDraft() {
return this.args.document?.isDraft;
return this.draftWasPublished ? false : this.args.document?.isDraft;
}

get docID() {
Expand All @@ -93,6 +99,20 @@ export default class DocumentSidebarComponent extends Component<DocumentSidebarC
@tracked approvers = this.args.document.approvers || [];
@tracked product = this.args.document.product || "";

/**
* Whether a draft was published during the session.
* Set true when the user successfully requests a review.
* Used in the `isDraft` getter to immediately update the UI
* to reflect the new state of the document.
*/
@tracked private draftWasPublished: boolean | null = null;

/**
* Whether the `waitForDocNumber` task has has failed to find a docNumber.
* When true, the "doc published" modal will not show a URL or share button.
*/
@tracked protected docNumberLookupHasFailed = false;

/**
* Whether the draft's `isShareable` property is true.
* Checked on render and changed when the user toggles permissions.
Expand Down Expand Up @@ -155,7 +175,7 @@ export default class DocumentSidebarComponent extends Component<DocumentSidebarC
*/
protected get shareURL() {
// We only assign shortLinks to published documents
if (this.args.document.isDraft) {
if (this.isDraft) {
return window.location.href;
}

Expand Down Expand Up @@ -620,14 +640,36 @@ export default class DocumentSidebarComponent extends Component<DocumentSidebarC

this.refreshRoute();

await this.waitForDocNumber.perform();
this.draftWasPublished = true;
this.requestReviewModalIsShown = false;
this.docPublishedModalIsShown = true;
} catch (error: unknown) {
this.draftWasPublished = null;
this.maybeShowFlashError(error as Error, "Unable to request review");
throw error;
}
});

/**
* A task that awaits a newly published doc's docNumber assignment.
* In the unlikely case where the docNumber doesn't appear after 10 seconds,
* we remove the URL and share button from the "doc published" modal.
*/
private waitForDocNumber = task(async () => {
const numberOfTries = 10;

for (let i = 0; i < numberOfTries; i++) {
if (!this.args.document.docNumber.endsWith("?")) {
return;
} else {
await timeout(Ember.testing ? 0 : 1000);
}
}

this.docNumberLookupHasFailed = true;
});

deleteDraft = task(async () => {
try {
await this.args.deleteDraft(this.docID);
Expand Down
14 changes: 7 additions & 7 deletions web/app/services/recently-viewed-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ export default class RecentlyViewedDocsService extends Service {
let docResponses = await Promise.allSettled(
(this.index as IndexedDoc[]).map(async ({ id, isDraft }) => {
let endpoint = isDraft ? "drafts" : "documents";
let fetchResponse = await this.fetchSvc.fetch(
`/api/v1/${endpoint}/${id}`
);
return {
doc: await fetchResponse?.json(),
isDraft,
};
let doc = await this.fetchSvc
.fetch(`/api/v1/${endpoint}/${id}`)
.then((resp) => resp?.json());

doc.isDraft = isDraft;

return { doc, isDraft };
})
);
/**
Expand Down
1 change: 1 addition & 0 deletions web/app/templates/authenticated/dashboard.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<div class="tile-list">
{{#each this.recentDocs.all as |r|}}
<Doc::Tile
data-test-recently-viewed-doc
@isDraft={{r.doc.isDraft}}
@avatar={{get r.doc.ownerPhotos 0}}
@docID={{r.doc.objectID}}
Expand Down
23 changes: 23 additions & 0 deletions web/mirage/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,29 @@ export default function (mirageConfig) {
return new Response(200, {}, matches.models);
});

/**
* Used when publishing a draft for review.
* Updates the document's status and isDraft properties.
*
* TODO: Add docNumber assignment.
*/
this.post("/reviews/:document_id", (schema, request) => {
const document = schema.document.findBy({
objectID: request.params.document_id,
});

if (document) {
document.update({
status: "In Review",
isDraft: false,
});

return new Response(200, {}, document.attrs);
}

return new Response(404, {}, {});
});

/**
* Used by the AuthenticatedUserService to add and remove subscriptions.
*/
Expand Down
24 changes: 24 additions & 0 deletions web/tests/acceptance/authenticated/dashboard-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 RECENTLY_VIEWED_DOC_SELECTOR = "[data-test-recently-viewed-doc]";

interface AuthenticatedDashboardRouteTestContext extends MirageTestContext {}

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

test("recently viewed docs have the correct href", async function (this: AuthenticatedDashboardRouteTestContext, assert) {
this.server.create("recently-viewed-doc", { id: "1", isDraft: false });
this.server.create("recently-viewed-doc", { id: "2", isDraft: true });

this.server.create("document", { objectID: "1", title: "Foo" });
this.server.create("document", { objectID: "2", title: "Bar" });

await visit("/dashboard");

assert.dom(RECENTLY_VIEWED_DOC_SELECTOR).exists({ count: 2 });

assert
.dom(`${RECENTLY_VIEWED_DOC_SELECTOR} a`)
.containsText("Foo")
.hasAttribute("href", "/document/1");

assert
.dom(`${RECENTLY_VIEWED_DOC_SELECTOR}:nth-child(2) a`)
.containsText("Bar")
.hasAttribute("href", "/document/2?draft=true");
});
});
Loading

0 comments on commit d532d68

Please sign in to comment.