Skip to content

Commit

Permalink
Bugfix: Add ?draft=true to draft links (#435)
Browse files Browse the repository at this point in the history
Fix draft links
  • Loading branch information
jeffdaley authored Nov 17, 2023
1 parent 953d262 commit 263ed5d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion web/app/components/table/row.hbs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<tr>
<td class="name">
<LinkTo
data-test-document-link
@route="authenticated.document"
@model="{{@doc.objectID}}"
@query={{hash draft=(eq @doc.status "wip")}}
@query={{hash draft=this.isDraft}}
class="inner flex h-full w-full items-start gap-3.5 focus:outline-none"
>
<Doc::Thumbnail @product={{@doc.product}} @status={{@doc.status}} />
Expand Down
8 changes: 8 additions & 0 deletions web/app/components/table/row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ interface TableRowComponentSignature {
export default class TableRowComponent extends Component<TableRowComponentSignature> {
@service declare authenticatedUser: AuthenticatedUserService;

protected get isDraft() {
if (this.args.doc.isDraft) {
return true;
}

return this.args.doc.status === "WIP";
}

protected get ownerIsAuthenticatedUser() {
const docOwner = this.args.doc.owners?.[0];

Expand Down
2 changes: 1 addition & 1 deletion web/mirage/factories/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function getTestDocNumber(product: string) {
export default Factory.extend({
objectID: (i: number) => `doc-${i}`,
title: (i: number) => `Test Document ${i}`,
status: "Draft",
status: "WIP",
product: "Vault",
docType: "RFC",
modifiedTime: 1,
Expand Down
15 changes: 15 additions & 0 deletions web/tests/acceptance/authenticated/drafts-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getPageTitle } from "ember-page-title/test-support";

const TABLE_HEADER_CREATED_SELECTOR =
"[data-test-sortable-table-header][data-test-attribute=createdTime]";
const DOCUMENT_LINK = "[data-test-document-link]";

interface AuthenticatedDraftRouteTestContext extends MirageTestContext {}

Expand Down Expand Up @@ -60,4 +61,18 @@ module("Acceptance | authenticated/drafts", function (hooks) {
.dom(".product-link")
.hasAttribute("href", "/drafts?product=%5B%22Security%22%5D");
});

test("document links have the correct query params", async function (this: AuthenticatedDraftRouteTestContext, assert) {
this.server.create("document");

await visit("/drafts");

assert
.dom(DOCUMENT_LINK)
.hasAttribute(
"href",
"/document/doc-0?draft=true",
"correctly has the draft param",
);
});
});

0 comments on commit 263ed5d

Please sign in to comment.