Skip to content

Commit

Permalink
Merge branch 'main' into jeffdaley/author-link-query-param
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffdaley committed Mar 5, 2024
2 parents 749016d + aeb4e9e commit e29d49a
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion web/app/components/dashboard/recently-viewed/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default class DashboardRecentlyViewedItemComponent extends Component<Dash
/**
* The modified time of the item, whether it's a document or a project.
*/
protected get modifiedTime(): number {
protected get modifiedTime(): number | undefined {
if (this.itemIsDoc) {
return this.doc.modifiedTime || this.doc.createdTime;
} else {
Expand Down
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
2 changes: 1 addition & 1 deletion web/app/components/related-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface RelatedHermesDocument {
title: string;
documentType: string;
documentNumber: string;
createdTime: number;
createdTime?: number;
modifiedTime: number;
sortOrder: number;
product: string;
Expand Down
2 changes: 1 addition & 1 deletion web/app/helpers/time-ago.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import timeAgo from "hermes/utils/time-ago";

export interface TimeAgoHelperSignature {
Args: {
Positional: [time: number];
Positional: [time?: number];
Named: {
limitTo24Hours?: boolean;
};
Expand Down
2 changes: 1 addition & 1 deletion web/app/styles/routes/my.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.my {
.hds-table {
td {
@apply h-12 py-0 pr-10;
@apply py-0 pr-10;

> .inner {
@apply overflow-hidden;
Expand Down
3 changes: 2 additions & 1 deletion web/app/types/document.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export interface HermesDocument {

/**
* A timestamp in seconds. Used for sorting.
* Undefined when the doc was created off-app.
*/
createdTime: number;
createdTime?: number;

/**
* A timestamp in seconds. Used Translated by the `time-ago` helper
Expand Down
4 changes: 3 additions & 1 deletion web/app/utils/time-ago.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import parseDate from "./parse-date";
* Used throughout the app to format document metadata.
*/
export default function timeAgo(
timeInSeconds: number,
timeInSeconds?: number,
options?: {
limitTo24Hours?: boolean;
},
) {
if (!timeInSeconds) return "Unknown date";

const now = Date.now();
const before = new Date(timeInSeconds * 1000).getTime();
const elapsed = now - before;
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
1 change: 1 addition & 0 deletions web/tests/unit/utils/time-ago-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module("Unit | Utility | time-ago", function () {
assert.equal("1 minute ago", timeAgo(now - 60));
assert.equal("5 minutes ago", timeAgo(now - 300));
assert.equal("6 hours ago", timeAgo(now - 21600));
assert.equal("Unknown date", timeAgo(undefined));

assert.equal("2 months ago", timeAgo(now - 5184000));

Expand Down

0 comments on commit e29d49a

Please sign in to comment.