From e083ad5a076850a82ace43e8c21ba8ef6cd554a7 Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Tue, 6 Sep 2022 16:18:17 -0400 Subject: [PATCH 1/4] add helper and fix buttons --- app/helpers/has-key.ts | 7 +++++++ .../addon/components/file-browser/file-item/styles.scss | 2 +- .../addon/components/file-browser/file-item/template.hbs | 9 +++++++-- .../components/file-browser/folder-item/styles.scss | 2 +- .../components/file-browser/folder-item/template.hbs | 6 +++++- 5 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 app/helpers/has-key.ts diff --git a/app/helpers/has-key.ts b/app/helpers/has-key.ts new file mode 100644 index 00000000000..fff66fd4c67 --- /dev/null +++ b/app/helpers/has-key.ts @@ -0,0 +1,7 @@ +import { helper } from '@ember/component/helper'; + +export function hasKey([object, key]: [any, any]): any { + return (key in object); +} + +export default helper(hasKey); diff --git a/lib/osf-components/addon/components/file-browser/file-item/styles.scss b/lib/osf-components/addon/components/file-browser/file-item/styles.scss index 6d6012752f1..538af8b707d 100644 --- a/lib/osf-components/addon/components/file-browser/file-item/styles.scss +++ b/lib/osf-components/addon/components/file-browser/file-item/styles.scss @@ -68,7 +68,7 @@ .FileList__item__options { display: flex; align-items: center; - flex: 1; + padding-right: 2vw; } .FileList__item__name { diff --git a/lib/osf-components/addon/components/file-browser/file-item/template.hbs b/lib/osf-components/addon/components/file-browser/file-item/template.hbs index b0eda3c0b8c..0b51406178c 100644 --- a/lib/osf-components/addon/components/file-browser/file-item/template.hbs +++ b/lib/osf-components/addon/components/file-browser/file-item/template.hbs @@ -57,7 +57,9 @@ data-test-file-list-download-count local-class='FileList__item__download_count' > - {{t 'osf-components.file-browser.download_count' count=@item.fileModel.extra.downloads}} + {{#if (has-key @item.fileModel.extra 'downloads')}} + {{t 'osf-components.file-browser.download_count' count=@item.fileModel.extra.downloads}} + {{/if}}
{{/if}} -
+
{{#unless @manager.selectedFiles}} {{/unless}} diff --git a/lib/osf-components/addon/components/file-browser/folder-item/styles.scss b/lib/osf-components/addon/components/file-browser/folder-item/styles.scss index c88c1830489..a0b453ef02c 100644 --- a/lib/osf-components/addon/components/file-browser/folder-item/styles.scss +++ b/lib/osf-components/addon/components/file-browser/folder-item/styles.scss @@ -62,7 +62,7 @@ .FileList__item__options { display: flex; align-items: center; - flex: 1; + padding-right: 2vw; } .MobileDropdownTrigger { diff --git a/lib/osf-components/addon/components/file-browser/folder-item/template.hbs b/lib/osf-components/addon/components/file-browser/folder-item/template.hbs index 0be4bab0c05..63ec63f4d3a 100644 --- a/lib/osf-components/addon/components/file-browser/folder-item/template.hbs +++ b/lib/osf-components/addon/components/file-browser/folder-item/template.hbs @@ -40,7 +40,11 @@ {{#if this.showActionsDropdown}}
Date: Wed, 7 Sep 2022 11:26:39 -0400 Subject: [PATCH 2/4] resolve import issues? --- {app => lib/osf-components/addon}/helpers/has-key.ts | 0 lib/osf-components/app/helpers/has-key.js | 1 + 2 files changed, 1 insertion(+) rename {app => lib/osf-components/addon}/helpers/has-key.ts (100%) create mode 100644 lib/osf-components/app/helpers/has-key.js diff --git a/app/helpers/has-key.ts b/lib/osf-components/addon/helpers/has-key.ts similarity index 100% rename from app/helpers/has-key.ts rename to lib/osf-components/addon/helpers/has-key.ts diff --git a/lib/osf-components/app/helpers/has-key.js b/lib/osf-components/app/helpers/has-key.js new file mode 100644 index 00000000000..18f31874796 --- /dev/null +++ b/lib/osf-components/app/helpers/has-key.js @@ -0,0 +1 @@ +export { default } from 'osf-components/helpers/has-key'; From 29f4d9f2aed7e2d2f7623b46a82a1a4da684b3ab Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Thu, 8 Sep 2022 15:54:27 -0400 Subject: [PATCH 3/4] fix tests --- lib/osf-components/addon/helpers/has-key.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/osf-components/addon/helpers/has-key.ts b/lib/osf-components/addon/helpers/has-key.ts index fff66fd4c67..be204b7c946 100644 --- a/lib/osf-components/addon/helpers/has-key.ts +++ b/lib/osf-components/addon/helpers/has-key.ts @@ -1,7 +1,10 @@ import { helper } from '@ember/component/helper'; export function hasKey([object, key]: [any, any]): any { - return (key in object); + if (object) { + return (key in object); + } + return false; } export default helper(hasKey); From c8c3c372c955a5dfc975498afd94e7f1130f7b43 Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Fri, 9 Sep 2022 10:36:57 -0400 Subject: [PATCH 4/4] add some tests --- tests/unit/helpers/has-key-test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/unit/helpers/has-key-test.ts diff --git a/tests/unit/helpers/has-key-test.ts b/tests/unit/helpers/has-key-test.ts new file mode 100644 index 00000000000..0ac4ff63359 --- /dev/null +++ b/tests/unit/helpers/has-key-test.ts @@ -0,0 +1,19 @@ +import { hasKey } from 'osf-components/helpers/has-key'; +import { module, test } from 'qunit'; + +module('Unit | Helper | has-key', () => { + test('returns correct boolean value', assert => { + const object = { itzy: 'hey' }; + const absentKey = 'twice'; + const existingKey = 'itzy'; + assert.equal(hasKey([object, absentKey]), false); + assert.equal(hasKey([object, existingKey]), true); + }); + + test('returns false when object is null or undefined', assert => { + // eslint-disable-next-line no-undef-init + const object = undefined; + assert.equal(hasKey([null, 'a']), false); + assert.equal(hasKey([object, 'b']), false); + }); +});