Skip to content

Commit 905a40a

Browse files
authored
Add helper and fix button styling (#1651)
## Purpose Fix the problem where file kebab button have inconsistent spacing for folder items and file items. Hide file download count for external providers.
1 parent 324dbbf commit 905a40a

File tree

7 files changed

+44
-5
lines changed

7 files changed

+44
-5
lines changed

lib/osf-components/addon/components/file-browser/file-item/styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
.FileList__item__options {
6969
display: flex;
7070
align-items: center;
71-
flex: 1;
71+
padding-right: 2vw;
7272
}
7373

7474
.FileList__item__name {

lib/osf-components/addon/components/file-browser/file-item/template.hbs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@
5757
data-test-file-list-download-count
5858
local-class='FileList__item__download_count'
5959
>
60-
{{t 'osf-components.file-browser.download_count' count=@item.fileModel.extra.downloads}}
60+
{{#if (has-key @item.fileModel.extra 'downloads')}}
61+
{{t 'osf-components.file-browser.download_count' count=@item.fileModel.extra.downloads}}
62+
{{/if}}
6163
</div>
6264
<div
6365
data-test-file-list-size
@@ -78,7 +80,10 @@
7880
{{/if}}
7981
</div>
8082
{{/if}}
81-
<div data-test-file-list-options local-class='FileList__item__options'>
83+
<div
84+
data-test-file-list-options
85+
local-class='FileList__item__options'
86+
>
8287
{{#unless @manager.selectedFiles}}
8388
<FileActionsMenu @item={{@item}} @onDelete={{@manager.reload}} @manager={{@manager}} @allowRename={{true}} />
8489
{{/unless}}

lib/osf-components/addon/components/file-browser/folder-item/styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
.FileList__item__options {
6363
display: flex;
6464
align-items: center;
65-
flex: 1;
65+
padding-right: 2vw;
6666
}
6767

6868
.MobileDropdownTrigger {

lib/osf-components/addon/components/file-browser/folder-item/template.hbs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
{{#if this.showActionsDropdown}}
4141
<div
4242
data-test-file-list-date
43-
local-class='FileList__item__options NoShrink {{if (or this.media.isTablet this.media.isMobile) 'MobileDropdownTrigger'}}'
43+
local-class='
44+
FileList__item__options
45+
NoShrink
46+
{{if (or this.media.isTablet this.media.isMobile) 'MobileDropdownTrigger'}}
47+
'
4448
>
4549
<ResponsiveDropdown
4650
local-class='DownloadShareDropdown'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { helper } from '@ember/component/helper';
2+
3+
export function hasKey([object, key]: [any, any]): any {
4+
if (object) {
5+
return (key in object);
6+
}
7+
return false;
8+
}
9+
10+
export default helper(hasKey);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from 'osf-components/helpers/has-key';

tests/unit/helpers/has-key-test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { hasKey } from 'osf-components/helpers/has-key';
2+
import { module, test } from 'qunit';
3+
4+
module('Unit | Helper | has-key', () => {
5+
test('returns correct boolean value', assert => {
6+
const object = { itzy: 'hey' };
7+
const absentKey = 'twice';
8+
const existingKey = 'itzy';
9+
assert.equal(hasKey([object, absentKey]), false);
10+
assert.equal(hasKey([object, existingKey]), true);
11+
});
12+
13+
test('returns false when object is null or undefined', assert => {
14+
// eslint-disable-next-line no-undef-init
15+
const object = undefined;
16+
assert.equal(hasKey([null, 'a']), false);
17+
assert.equal(hasKey([object, 'b']), false);
18+
});
19+
});

0 commit comments

Comments
 (0)