/
Browser.jsx
143 lines (129 loc) · 3.62 KB
/
Browser.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { h } from 'preact'
import classNames from 'classnames'
import remoteFileObjToLocal from '@uppy/utils/lib/remoteFileObjToLocal'
import Filter from './Filter.jsx'
import FooterActions from './FooterActions.jsx'
import Item from './Item/index.jsx'
const VIRTUAL_SHARED_DIR = 'shared-with-me'
function Browser (props) {
const {
currentSelection,
folders,
files,
uppyFiles,
viewType,
headerComponent,
showBreadcrumbs,
isChecked,
toggleCheckbox,
recordShiftKeyPress,
handleScroll,
showTitles,
i18n,
validateRestrictions,
showFilter,
filterQuery,
filterInput,
getNextFolder,
cancel,
done,
columns,
} = props
const selected = currentSelection.length
return (
<div
className={classNames(
'uppy-ProviderBrowser',
`uppy-ProviderBrowser-viewType--${viewType}`,
)}
>
<div className="uppy-ProviderBrowser-header">
<div
className={classNames(
'uppy-ProviderBrowser-headerBar',
!showBreadcrumbs && 'uppy-ProviderBrowser-headerBar--simple',
)}
>
{headerComponent}
</div>
</div>
{showFilter && (
<Filter
i18n={i18n}
filterQuery={filterQuery}
filterInput={filterInput}
/>
)}
{(() => {
if (!folders.length && !files.length) {
return (
<div className="uppy-Provider-empty">
{i18n('noFilesFound')}
</div>
)
}
return (
<div className="uppy-ProviderBrowser-body">
<ul
className="uppy-ProviderBrowser-list"
onScroll={handleScroll}
role="listbox"
// making <ul> not focusable for firefox
tabIndex="-1"
>
{folders.map((folder) => {
return Item({
columns,
showTitles,
viewType,
i18n,
id: folder.id,
title: folder.name,
getItemIcon: () => folder.icon,
isChecked: isChecked(folder),
toggleCheckbox: (event) => toggleCheckbox(event, folder),
recordShiftKeyPress,
type: 'folder',
isDisabled: isChecked(folder)?.loading,
isCheckboxDisabled: folder.id === VIRTUAL_SHARED_DIR,
handleFolderClick: () => getNextFolder(folder),
})
})}
{files.map((file) => {
const restrictionError = validateRestrictions(
remoteFileObjToLocal(file),
[...uppyFiles, ...currentSelection],
)
return Item({
id: file.id,
title: file.name,
author: file.author,
getItemIcon: () => file.icon,
isChecked: isChecked(file),
toggleCheckbox: (event) => toggleCheckbox(event, file),
recordShiftKeyPress,
columns,
showTitles,
viewType,
i18n,
type: 'file',
isDisabled: restrictionError && !isChecked(file),
restrictionError,
})
})}
</ul>
</div>
)
})()}
{selected > 0 && (
<FooterActions
selected={selected}
done={done}
cancel={cancel}
i18n={i18n}
/>
)}
</div>
)
}
export default Browser