@@ -76,6 +76,7 @@ export function OverlayUI() {
76
76
const [ isHelpOpen , setIsHelpOpen ] = useState ( false ) ;
77
77
const [ isSettingsOpen , setIsSettingsOpen ] = useState ( false ) ;
78
78
const [ isHelpFirstTime , setHelpFirstTime ] = useAtom ( helpAtom ) ;
79
+ const [ error , setError ] = useState < Error > ( ) ;
79
80
80
81
useEffect ( ( ) => {
81
82
if ( isHelpFirstTime ) {
@@ -103,13 +104,19 @@ export function OverlayUI() {
103
104
setIsOpen ( false ) ;
104
105
} ;
105
106
106
- const savePipeline = ( ) => {
107
+ const pipelineToJSON = ( ) => {
107
108
const pipelineToSave = structuredClone ( pipeline ) ;
108
109
// set model and provider
109
110
pipelineToSave . provider = litlyticsConfig . provider ;
110
111
pipelineToSave . model = litlyticsConfig . model ;
111
112
// Convert the object to a JSON string
112
113
const jsonString = JSON . stringify ( pipeline , null , 2 ) ;
114
+ return jsonString ;
115
+ } ;
116
+
117
+ const savePipeline = ( ) => {
118
+ setError ( undefined ) ;
119
+ const jsonString = pipelineToJSON ( ) ;
113
120
// Create a Blob from the JSON string
114
121
const blob = new Blob ( [ jsonString ] , { type : 'application/json' } ) ;
115
122
// Create a temporary URL for the Blob
@@ -126,6 +133,18 @@ export function OverlayUI() {
126
133
setIsSaveOpen ( false ) ;
127
134
} ;
128
135
136
+ const savePipelineToClipboard = async ( ) => {
137
+ setError ( undefined ) ;
138
+ try {
139
+ const jsonString = pipelineToJSON ( ) ;
140
+ await navigator . clipboard . writeText ( jsonString ) ;
141
+ // close modal
142
+ setIsSaveOpen ( false ) ;
143
+ } catch ( err ) {
144
+ setError ( err as Error ) ;
145
+ }
146
+ } ;
147
+
129
148
const handleFileChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
130
149
const file = event . target . files ?. [ 0 ] ;
131
150
if ( file ) {
@@ -272,13 +291,19 @@ export function OverlayUI() {
272
291
/>
273
292
</ Field >
274
293
</ FieldGroup >
294
+ { error && (
295
+ < 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 }
297
+ </ div >
298
+ ) }
275
299
</ DialogBody >
276
300
< DialogActions className = "flex justify-between" >
277
301
< Button plain onClick = { ( ) => setIsSaveOpen ( false ) } >
278
302
Close
279
303
</ Button >
304
+ < Button onClick = { savePipelineToClipboard } > Copy to clipboard</ Button >
280
305
< Button color = "green" onClick = { savePipeline } >
281
- Save
306
+ Save to file
282
307
</ Button >
283
308
</ DialogActions >
284
309
</ Dialog >
0 commit comments