6
6
Select ,
7
7
SelectItem ,
8
8
TextArea ,
9
+ Stack ,
9
10
} from "@carbon/react" ;
10
11
import { useTools } from "../../hooks/api/use-tools" ;
11
12
import { ToolReference } from "../../models" ;
@@ -216,8 +217,24 @@ export const ImportToolsetModal: React.FC<ImportToolsetModalProps> = ({
216
217
onSubmit,
217
218
} ) => {
218
219
const [ toolsetJson , setToolsetJson ] = useState ( "" ) ;
220
+ const [ toolsetUrl , setToolsetUrl ] = useState ( "" ) ;
219
221
220
- const handleSubmit = ( ) => {
222
+ const handleFetchToolset = async ( ) => {
223
+ if ( toolsetUrl ) {
224
+ try {
225
+ const response = await fetch ( toolsetUrl ) ;
226
+ if ( ! response . ok ) {
227
+ throw new Error ( "Failed to fetch toolset from URL" ) ;
228
+ }
229
+ const tools = await response . json ( ) ;
230
+ setToolsetJson ( JSON . stringify ( tools , null , 2 ) ) ;
231
+ } catch ( error ) {
232
+ console . error ( "Error fetching toolset from URL:" , error ) ;
233
+ }
234
+ }
235
+ } ;
236
+
237
+ const handleSubmit = async ( ) => {
221
238
try {
222
239
const tools = JSON . parse ( toolsetJson ) ;
223
240
onSubmit ( tools ) ;
@@ -235,14 +252,27 @@ export const ImportToolsetModal: React.FC<ImportToolsetModalProps> = ({
235
252
onRequestClose = { onRequestClose }
236
253
onRequestSubmit = { handleSubmit }
237
254
>
238
- < TextArea
239
- id = "toolset-json"
240
- labelText = "Toolset JSON"
241
- placeholder = "Paste your JSON array here"
242
- rows = { 10 }
243
- value = { toolsetJson }
244
- onChange = { ( e ) => setToolsetJson ( e . target . value ) }
245
- />
255
+ < Stack gap = { 7 } >
256
+ < TextInput
257
+ id = "toolset-url"
258
+ labelText = "Fetch from Toolset URL"
259
+ placeholder = "Enter the URL of the toolset JSON"
260
+ value = { toolsetUrl }
261
+ onChange = { ( e ) => setToolsetUrl ( e . target . value ) }
262
+ onBlur = { handleFetchToolset }
263
+ />
264
+ < TextArea
265
+ id = "toolset-json"
266
+ labelText = "Toolset JSON"
267
+ placeholder = "Paste your JSON array here"
268
+ rows = { 10 }
269
+ required
270
+ value = { toolsetJson }
271
+ onChange = { ( e ) => setToolsetJson ( e . target . value ) }
272
+ invalid = { ! toolsetJson }
273
+ invalidText = "This field is required"
274
+ />
275
+ </ Stack >
246
276
</ Modal >
247
277
) ;
248
278
} ;
0 commit comments