Skip to content

Commit

Permalink
Make sure project docs are excluded from search results (#536)
Browse files Browse the repository at this point in the history
* Make sure project docs are excluded from search

* Include external links in duplicate detection
  • Loading branch information
jeffdaley authored Jan 17, 2024
1 parent 18c94e6 commit 126de25
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
1 change: 1 addition & 0 deletions web/app/components/project/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@

{{! Plus button }}
<RelatedResources
@items={{this.relatedResources}}
@modalHeaderTitle="Add project resource"
@modalInputPlaceholder="Search docs or paste a URL..."
@addResource={{this.addResource}}
Expand Down
8 changes: 8 additions & 0 deletions web/app/components/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ export default class ProjectIndexComponent extends Component<ProjectIndexCompone
return this.status === ProjectStatus.Active;
}

/**
* A single array of all resources. Used by the "Add..." modal
* to prevent duplicate resources from being added.
*/
protected get relatedResources() {
return [...this.hermesDocuments, ...this.externalLinks];
}

/**
* Whether the JiraWidget should be shown.
* True if the project is active, or if the project has a Jira issue
Expand Down
4 changes: 3 additions & 1 deletion web/app/components/related-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ export default class RelatedResourcesComponent extends Component<RelatedResource

filterString = filterString.slice(0, -1) + " ";

filterString += `AND NOT objectID:"${relatedDocIDs.join(
const maybeAnd = this.args.documentObjectID ? "AND " : "(";

filterString += `${maybeAnd}NOT objectID:"${relatedDocIDs.join(
'" AND NOT objectID:"',
)}")`;
}
Expand Down
62 changes: 62 additions & 0 deletions web/tests/integration/components/related-resources-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface RelatedResourcesComponentTestContext extends MirageTestContext {
isLoading?: boolean;
loadingHasFailed?: boolean;
scope: `${RelatedResourcesScope}`;
documentObjectID?: string;
}

module("Integration | Component | related-resources", function (hooks) {
Expand Down Expand Up @@ -350,6 +351,67 @@ module("Integration | Component | related-resources", function (hooks) {
.doesNotExist("the error message is removed when the URL changes");
});

test('it excludes documents that are already related to the "parent" resource', async function (this: RelatedResourcesComponentTestContext, assert) {
this.server.createList("document", 5);
this.server.createList("related-hermes-document", 5);

const firstDocument =
this.server.schema.relatedHermesDocument.find("doc-0").attrs;
const secondDocument =
this.server.schema.relatedHermesDocument.find("doc-1").attrs;
const thirdDocument =
this.server.schema.relatedHermesDocument.find("doc-2").attrs;

this.set("documentObjectID", null);

await render<RelatedResourcesComponentTestContext>(hbs`
<RelatedResources
@items={{this.items}}
@scope="documents"
@modalHeaderTitle={{this.modalHeaderTitle}}
@modalInputPlaceholder={{this.modalInputPlaceholder}}
@addResource={{this.addResource}}
@documentObjectID={{this.documentObjectID}}
>
<:header as |rr|>
<button {{on "click" rr.showModal}}>Add</button>
</:header>
</RelatedResources>
<div class="click-away"/>
`);

const openModal = async () => {
await click("button");
await waitFor(ADD_RESOURCE_MODAL_SELECTOR);
};

await openModal();

assert
.dom(RELATED_DOCUMENT_OPTION_SELECTOR)
.exists({ count: 5 }, "all docs are shown");

await click(".click-away");

this.set("documentObjectID", firstDocument.id);

await openModal();

assert
.dom(RELATED_DOCUMENT_OPTION_SELECTOR)
.exists({ count: 4 }, "the parent doc is excluded");

await click(".click-away");

this.set("items", [secondDocument, thirdDocument]);

await openModal();

assert
.dom(RELATED_DOCUMENT_OPTION_SELECTOR)
.exists({ count: 2 }, "the related docs are excluded");
});

test("you can scope the component to document resource", async function (this: RelatedResourcesComponentTestContext, assert) {
this.server.createList("document", 3);

Expand Down

0 comments on commit 126de25

Please sign in to comment.