Skip to content

Commit

Permalink
Resolve "failed to load related resources" message on non-app-created…
Browse files Browse the repository at this point in the history
… docs (#623)

Adds related resource logic for non-app-created docs
  • Loading branch information
jeffdaley authored Mar 5, 2024
1 parent e7ce719 commit 8dd4e56
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions web/app/components/document/sidebar.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@
{{! Related resources }}
<div>
<Document::Sidebar::RelatedResources
@docWasCreatedOffApp={{not @document.appCreated}}
@editingIsDisabled={{this.editingIsDisabled}}
@documentIsDraft={{this.isDraft}}
@productArea={{@document.product}}
Expand Down
2 changes: 2 additions & 0 deletions web/app/components/document/sidebar/related-resources.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@title={{@headerTitle}}
@titleTooltipText={{this.titleTooltipText}}
@buttonIsHidden={{this.sectionHeaderButtonIsHidden}}
@buttonIsDisabled={{@docWasCreatedOffApp}}
@disabledButtonTooltipText="Only docs created in Hermes can add related resources"
@buttonAction={{rr.showModal}}
/>
</:header>
Expand Down
6 changes: 4 additions & 2 deletions web/app/components/document/sidebar/related-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { inject as service } from "@ember/service";
import FetchService from "hermes/services/fetch";
import ConfigService from "hermes/services/config";
import AlgoliaService from "hermes/services/algolia";
import { restartableTask, task, timeout } from "ember-concurrency";
import { restartableTask, task } from "ember-concurrency";
import { next, schedule } from "@ember/runloop";
import htmlElement from "hermes/utils/html-element";
import Ember from "ember";
import {
RelatedExternalLink,
RelatedHermesDocument,
Expand All @@ -32,6 +31,7 @@ export interface DocumentSidebarRelatedResourcesComponentArgs {
itemLimit?: number;
modalInputPlaceholder: string;
documentIsDraft?: boolean;
docWasCreatedOffApp?: boolean;
editingIsDisabled?: boolean;
scrollContainer: HTMLElement;
}
Expand Down Expand Up @@ -208,6 +208,8 @@ export default class DocumentSidebarRelatedResourcesComponent extends Component<
* On error, triggers the "retry" design.
*/
protected loadRelatedResources = task(async () => {
if (this.args.docWasCreatedOffApp) return;

try {
const resources = await this.fetchSvc
.fetch(
Expand Down
9 changes: 6 additions & 3 deletions web/tests/acceptance/authenticated/document-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ const PEOPLE_SELECT_REMOVE_BUTTON_SELECTOR =
".ember-power-select-multiple-remove-btn";

const PROJECT_LINK = "[data-test-project-link]";
const ADD_TO_PROJECT_BUTTON = "[data-test-projects-section-header] button";
const ADD_TO_PROJECT_BUTTON =
"[data-test-section-header-button-for='Projects']";
const ADD_TO_PROJECT_MODAL = "[data-test-add-to-or-create-project-modal]";
const PROJECT_OPTION = "[data-test-project-option]";

Expand Down Expand Up @@ -1121,10 +1122,12 @@ module("Acceptance | authenticated/document", function (hooks) {
assert
.dom(`${APPROVERS_SELECTOR} ${EDITABLE_FIELD_READ_VALUE}`)
.exists("read-only approvers list");

assert
.dom(ADD_RELATED_DOCUMENT_OPTION_SELECTOR)
.doesNotExist("no add related resource option");
.dom(ADD_RELATED_RESOURCE_BUTTON_SELECTOR)
.hasAttribute("aria-disabled");

assert.dom(ADD_TO_PROJECT_BUTTON).hasAttribute("aria-disabled");
assert.dom(PRODUCT_SELECT_SELECTOR).doesNotExist("no product select");
assert.dom(DRAFT_VISIBILITY_TOGGLE_SELECTOR).isDisabled();

Expand Down

0 comments on commit 8dd4e56

Please sign in to comment.