7
7
CloudArrowUpIcon ,
8
8
DocumentPlusIcon ,
9
9
TrashIcon ,
10
- XMarkIcon ,
10
+ MagnifyingGlassIcon ,
11
11
} from '@heroicons/react/24/outline'
12
12
import { Dialog , Transition } from '@headlessui/react'
13
13
import { UploadResult , UploadFile , useFiles } from '@/hooks/useFiles'
@@ -45,6 +45,8 @@ export default function Files(props: Props) {
45
45
props . workspaceId
46
46
)
47
47
48
+ const [ search , setSearch ] = useState ( '' )
49
+
48
50
const onUseInPython = useCallback (
49
51
( file : BrieferFile ) => {
50
52
if ( ! props . yDoc || ! props . executionQueue ) {
@@ -55,13 +57,13 @@ export default function Files(props: Props) {
55
57
file . mimeType === 'application/json'
56
58
? 'json'
57
59
: file . mimeType === 'text/csv'
58
- ? 'csv'
59
- : file . mimeType === 'application/vnd.ms-excel'
60
- ? 'xls'
61
- : file . mimeType ===
62
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
63
- ? 'xlsx'
64
- : ''
60
+ ? 'csv'
61
+ : file . mimeType === 'application/vnd.ms-excel'
62
+ ? 'xls'
63
+ : file . mimeType ===
64
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
65
+ ? 'xlsx'
66
+ : ''
65
67
66
68
const source =
67
69
fileExtension !== ''
98
100
}
99
101
)
100
102
} ,
101
- [ props . yDoc , props . executionQueue , environmentStartedAt ]
103
+ [ props . yDoc , props . executionQueue , props . userId , environmentStartedAt ]
102
104
)
103
105
104
106
const onUseInSQL = useCallback (
@@ -152,7 +154,7 @@ file`
152
154
}
153
155
)
154
156
} ,
155
- [ props . yDoc , props . executionQueue , environmentStartedAt ]
157
+ [ props . yDoc , props . executionQueue , props . userId , environmentStartedAt ]
156
158
)
157
159
158
160
const [
@@ -190,21 +192,27 @@ file`
190
192
191
193
const actualFiles = useMemo (
192
194
( ) =>
193
- files . filter ( ( f ) => {
195
+ files . filter ( ( file ) => {
196
+ const s = search . trim ( )
197
+ if ( s !== '' ) {
198
+ const name = file . name . trim ( )
199
+ return name . toLowerCase ( ) . includes ( s . toLowerCase ( ) )
200
+ }
201
+
194
202
if ( upload . _tag === 'idle' ) {
195
203
return true
196
204
}
197
205
198
206
if (
199
- upload . current . file . name === f . relCwdPath &&
207
+ upload . current . file . name === file . relCwdPath &&
200
208
upload . current . status === 'uploading'
201
209
) {
202
210
return false
203
211
}
204
212
205
213
return true
206
214
} ) ,
207
- [ files , upload ]
215
+ [ files , upload , search ]
208
216
)
209
217
210
218
const results = useMemo (
@@ -313,6 +321,16 @@ file`
313
321
< InformationCircleIcon className = "w-4 h-4 text-gray-300" />
314
322
</ Tooltip >
315
323
</ div >
324
+ < div className = "px-4 py-0 flex items-center border-b border-gray-200 group focus-within:border-blue-300" >
325
+ < MagnifyingGlassIcon className = "h-3.5 w-3.5 text-gray-400 group-focus-within:text-blue-500" />
326
+ < input
327
+ type = "text"
328
+ placeholder = "Search..."
329
+ className = "w-full h-8 border-0 placeholder-gray-400 text-xs text-gray-600 focus:outline-none focus:ring-0 pl-2"
330
+ onChange = { ( e ) => setSearch ( e . target . value ) }
331
+ value = { search }
332
+ />
333
+ </ div >
316
334
{ actualFiles . length > 0 ? (
317
335
< ul
318
336
role = "list"
@@ -621,7 +639,8 @@ function ReplaceDialog(props: ReplaceDialogProps) {
621
639
if ( props . fileName !== '' && props . fileName !== fileName ) {
622
640
setFileName ( props . fileName )
623
641
}
624
- } , [ props . fileName ] )
642
+ } , [ props . fileName , fileName ] )
643
+
625
644
return (
626
645
< Transition show = { props . open } >
627
646
< Dialog onClose = { props . onReplaceNo } className = "relative z-[100]" >
0 commit comments