@@ -7,18 +7,21 @@ import {
7
7
Card ,
8
8
CardContent ,
9
9
CircularProgress ,
10
- Link ,
10
+ IconButton ,
11
11
Stack ,
12
12
Tooltip ,
13
13
Typography ,
14
14
} from "@mui/material" ;
15
15
16
16
import {
17
+ Download as DownloadIcon ,
17
18
FolderOpen as FolderOpenIcon ,
18
19
InsertDriveFile as FileIcon ,
19
- Info as InfoIcon ,
20
+ Visibility as VisibilityIcon ,
20
21
} from "@mui/icons-material" ;
21
22
import Panel from "./Panel" ;
23
+ import Preview from "./Preview" ;
24
+ import { guessContentType } from "../utils" ;
22
25
23
26
function removePrefixFromPath ( prefix , path ) {
24
27
return path . slice ( prefix . length ) ;
@@ -27,7 +30,7 @@ function removePrefixFromPath(prefix, path) {
27
30
function formatContentType ( contentType ) {
28
31
if ( contentType ) {
29
32
return (
30
- < Typography variant = "body2" color = "gray" sx = { { lineHeight : "24px" } } >
33
+ < Typography variant = "body2" color = "gray" sx = { { lineHeight : "24px" } } noWrap >
31
34
{ contentType }
32
35
</ Typography >
33
36
) ;
@@ -38,24 +41,28 @@ function formatContentType(contentType) {
38
41
39
42
function formatFileSize ( size ) {
40
43
if ( size ) {
41
- if ( size < 1024 ) {
42
- return (
43
- < Typography variant = "body2" color = "gray" sx = { { lineHeight : "24px" } } >
44
- { size } bytes
45
- </ Typography >
46
- ) ;
47
- } else {
48
- return (
49
- < Typography variant = "body2" color = "gray" sx = { { lineHeight : "24px" } } >
50
- { ( size / 1024 ) . toFixed ( 1 ) } KiB
51
- </ Typography >
52
- ) ;
44
+ let text = `${ size } bytes` ;
45
+ if ( size >= 1024 ) {
46
+ text = `${ ( size / 1024 ) . toFixed ( 1 ) } KiB` ;
53
47
}
48
+ return (
49
+ < Typography variant = "body2" color = "gray" sx = { { lineHeight : "24px" } } noWrap >
50
+ { text }
51
+ </ Typography >
52
+ ) ;
54
53
} else {
55
54
return "" ;
56
55
}
57
56
}
58
57
58
+ function getContentType ( contentType , url ) {
59
+ if ( contentType ) {
60
+ return contentType ;
61
+ } else {
62
+ return guessContentType ( url ) ;
63
+ }
64
+ }
65
+
59
66
function CopyButtons ( props ) {
60
67
const submit = useSubmit ( ) ;
61
68
const [ copying , setCopying ] = useState ( false ) ;
@@ -108,6 +115,14 @@ function CopyButtons(props) {
108
115
}
109
116
110
117
function FilesPanel ( props ) {
118
+ const [ previewTarget , setPreviewTarget ] = useState ( "" ) ;
119
+ const [ previewDialogOpen , setPreviewDialogOpen ] = useState ( false ) ;
120
+
121
+ const handleOpenPreview = ( target ) => {
122
+ setPreviewTarget ( target ) ;
123
+ setPreviewDialogOpen ( true ) ;
124
+ } ;
125
+
111
126
if ( props . dataset ) {
112
127
return (
113
128
< Panel
@@ -118,20 +133,35 @@ function FilesPanel(props) {
118
133
< Typography variant = "body2" sx = { { paddingTop : 2 , paddingBottom : 1 } } >
119
134
{ props . dataset . repository }
120
135
</ Typography >
121
- < Stack direction = "row" spacing = { 1 } >
136
+ < Stack direction = "row" spacing = { 1 } sx = { { flexWrap : "wrap" , gap : 1 } } >
122
137
{ props . dataset . files . map ( ( file ) => (
123
138
< Card key = { file . path } sx = { { paddingTop : 1 , backgroundColor : "#f8f8f8" } } >
124
- < CardContent sx = { { minHeight : "40px" } } >
125
- < Stack direction = "row" spacing = { 1 } >
139
+ < CardContent >
140
+ < Stack direction = "row" spacing = { 1 } sx = { { alignItems : "center" } } >
126
141
< FileIcon color = "disabled" />
127
- < Link href = { file . url } target = "_blank" >
128
- { removePrefixFromPath ( `/${ props . collab } ` , file . path ) }
129
- </ Link >
130
- { formatContentType ( file . content_type ) }
131
- { formatFileSize ( file . size ) }
142
+
132
143
< Tooltip title = { `digest: ${ file . hash } ` } >
133
- < InfoIcon color = "info" />
144
+ < Typography variant = "body2" color = "primary" noWrap >
145
+ { removePrefixFromPath ( `/${ props . collab } ` , file . path ) }
146
+ </ Typography >
134
147
</ Tooltip >
148
+
149
+ { formatFileSize ( file . size ) }
150
+
151
+ < Tooltip title = "Download" >
152
+ < IconButton href = { file . url } target = "_blank" >
153
+ < DownloadIcon />
154
+ </ IconButton >
155
+ </ Tooltip >
156
+ { getContentType ( file . content_type , file . url ) ? (
157
+ < Tooltip title = "Preview" >
158
+ < IconButton onClick = { ( ) => handleOpenPreview ( file ) } >
159
+ < VisibilityIcon />
160
+ </ IconButton >
161
+ </ Tooltip >
162
+ ) : (
163
+ ""
164
+ ) }
135
165
</ Stack >
136
166
</ CardContent >
137
167
</ Card >
@@ -142,6 +172,13 @@ function FilesPanel(props) {
142
172
collab = { props . collab }
143
173
jobId = { props . jobId }
144
174
/>
175
+ < Preview
176
+ url = { previewTarget . url }
177
+ size = { previewTarget . size }
178
+ contentType = { previewTarget . content_type }
179
+ open = { previewDialogOpen }
180
+ onClose = { ( ) => setPreviewDialogOpen ( false ) }
181
+ />
145
182
</ Panel >
146
183
) ;
147
184
} else {
0 commit comments