@@ -39,6 +39,7 @@ import {
39
39
} from '~/store/store' ;
40
40
import { Field , FieldGroup , Label } from '../catalyst/fieldset' ;
41
41
import { Input } from '../catalyst/input' ;
42
+ import { Textarea } from '../catalyst/textarea' ;
42
43
import { GithubIcon } from './GithubIcon' ;
43
44
import { Help } from './Help' ;
44
45
import { Settings } from './Settings' ;
@@ -66,13 +67,15 @@ function MenuHolder({
66
67
67
68
export function OverlayUI ( ) {
68
69
const fileInputRef = useRef < HTMLInputElement > ( null ) ;
70
+ const loadInputRef = useRef < HTMLTextAreaElement > ( null ) ;
69
71
const [ pipeline , setPipeline ] = useAtom ( pipelineAtom ) ;
70
72
const setStatus = useSetAtom ( pipelineStatusAtom ) ;
71
73
const litlyticsConfig = useAtomValue ( litlyticsConfigStore ) ;
72
74
const webllm = useAtomValue ( webllmAtom ) ;
73
75
const { undo, redo, canUndo, canRedo } = useAtomValue ( pipelineUndoAtom ) ;
74
76
const [ isOpen , setIsOpen ] = useState ( false ) ;
75
77
const [ isSaveOpen , setIsSaveOpen ] = useState ( false ) ;
78
+ const [ isLoadOpen , setIsLoadOpen ] = useState ( false ) ;
76
79
const [ isHelpOpen , setIsHelpOpen ] = useState ( false ) ;
77
80
const [ isSettingsOpen , setIsSettingsOpen ] = useState ( false ) ;
78
81
const [ isHelpFirstTime , setHelpFirstTime ] = useAtom ( helpAtom ) ;
@@ -145,6 +148,26 @@ export function OverlayUI() {
145
148
}
146
149
} ;
147
150
151
+ const loadFromFile = ( ) => fileInputRef . current ?. click ( ) ;
152
+
153
+ const loadFromString = ( ) => {
154
+ setError ( undefined ) ;
155
+ const inputStr = loadInputRef . current ?. value ;
156
+ if ( ! inputStr ?. length ) {
157
+ setError ( new Error ( 'Input string is required!' ) ) ;
158
+ return ;
159
+ }
160
+ try {
161
+ const pipelineJson = JSON . parse ( inputStr ) ;
162
+ setPipeline ( pipelineJson ) ;
163
+ setStatus ( { status : 'init' } ) ;
164
+ loadInputRef . current ! . value = '' ;
165
+ setIsLoadOpen ( false ) ;
166
+ } catch ( err ) {
167
+ setError ( err as Error ) ;
168
+ }
169
+ } ;
170
+
148
171
const handleFileChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
149
172
const file = event . target . files ?. [ 0 ] ;
150
173
if ( file ) {
@@ -154,6 +177,7 @@ export function OverlayUI() {
154
177
const json = JSON . parse ( e . target ?. result as string ) as Pipeline ;
155
178
setPipeline ( json ) ;
156
179
setStatus ( { status : 'init' } ) ;
180
+ setIsLoadOpen ( false ) ;
157
181
} catch ( error ) {
158
182
console . error ( 'Error parsing JSON:' , error ) ;
159
183
}
@@ -193,7 +217,7 @@ export function OverlayUI() {
193
217
194
218
< DropdownDivider />
195
219
196
- < DropdownItem onClick = { ( ) => fileInputRef . current ?. click ( ) } >
220
+ < DropdownItem onClick = { ( ) => setIsLoadOpen ( true ) } >
197
221
< FolderIcon aria-hidden = "true" className = "h-5 w-5" />
198
222
< DropdownLabel > Open pipeline</ DropdownLabel >
199
223
</ DropdownItem >
@@ -268,6 +292,43 @@ export function OverlayUI() {
268
292
</ DialogActions >
269
293
</ Dialog >
270
294
295
+ { /* Pipeline open dialog */ }
296
+ < Dialog
297
+ size = "xl"
298
+ open = { isLoadOpen }
299
+ onClose = { setIsLoadOpen }
300
+ topClassName = "z-20"
301
+ >
302
+ < DialogTitle > Load pipeline</ DialogTitle >
303
+ < DialogBody className = "w-full" >
304
+ < FieldGroup >
305
+ < Field >
306
+ < Label > Pipeline JSON</ Label >
307
+ < Textarea
308
+ name = "pipeline-json"
309
+ placeholder = "Pipeline JSON"
310
+ autoFocus
311
+ ref = { loadInputRef }
312
+ />
313
+ </ Field >
314
+ </ FieldGroup >
315
+ { error && (
316
+ < div className = "flex items-center justify-between bg-red-400 dark:bg-red-700 rounded-xl py-1 px-2 my-2" >
317
+ Error loading pipeline: { error . message }
318
+ </ div >
319
+ ) }
320
+ </ DialogBody >
321
+ < DialogActions className = "flex justify-between" >
322
+ < Button plain onClick = { ( ) => setIsLoadOpen ( false ) } >
323
+ Close
324
+ </ Button >
325
+ < Button onClick = { loadFromString } > Load from string</ Button >
326
+ < Button color = "green" onClick = { loadFromFile } >
327
+ Load from file
328
+ </ Button >
329
+ </ DialogActions >
330
+ </ Dialog >
331
+
271
332
{ /* Pipeline save dialog */ }
272
333
< Dialog
273
334
size = "xl"
@@ -293,7 +354,7 @@ export function OverlayUI() {
293
354
</ FieldGroup >
294
355
{ error && (
295
356
< div className = "flex items-center justify-between bg-red-400 dark:bg-red-700 rounded-xl py-1 px-2 my-2" >
296
- Error saving pipleine : { error . message }
357
+ Error saving pipeline : { error . message }
297
358
</ div >
298
359
) }
299
360
</ DialogBody >
0 commit comments