@@ -14,9 +14,8 @@ import { Icon } from "components/ui/Icon";
14
14
import { Modal , ModalBody , ModalFooter } from "components/ui/Modal" ;
15
15
16
16
import {
17
- BuilderAssistCreateStreamParams ,
18
17
BuilderAssistFindStreamsResponse ,
19
- BuilderAssistGlobalParams ,
18
+ BuilderAssistInputStreamParams ,
20
19
BuilderAssistManifestResponse ,
21
20
useBuilderAssistCreateStream ,
22
21
useBuilderAssistFindStreams ,
@@ -29,7 +28,7 @@ import { convertToAssistFormValuesSync } from "./Assist/assist";
29
28
import { AssistWaiting } from "./Assist/AssistWaiting" ;
30
29
import { BuilderField } from "./BuilderField" ;
31
30
import { BuilderFieldWithInputs } from "./BuilderFieldWithInputs" ;
32
- import { AssistData , BuilderStream , DEFAULT_BUILDER_STREAM_VALUES , DEFAULT_SCHEMA , useBuilderWatch } from "../types" ;
31
+ import { BuilderStream , DEFAULT_BUILDER_STREAM_VALUES , DEFAULT_SCHEMA , useBuilderWatch } from "../types" ;
33
32
34
33
interface AddStreamResponse {
35
34
streamName : string ;
@@ -172,26 +171,12 @@ const AddStreamModal = ({
172
171
streams : BuilderStream [ ] ;
173
172
initialUrlPath ?: string ;
174
173
} ) => {
175
- const baseUrl = useBuilderWatch ( "formValues.global.urlBase" ) ;
176
- const appName = useBuilderWatch ( "name" ) || "Connector" ;
177
- const assistData : AssistData = useBuilderWatch ( "formValues.assist" ) ;
178
174
const { assistEnabled } = useConnectorBuilderFormState ( ) ;
179
-
180
175
const shouldAssist = assistEnabled && ! isDuplicate ;
181
176
182
177
// TODO refactor to useMutation, as this is a bit of a hack
183
178
const [ assistFormValues , setAssistFormValues ] = useState < AddStreamFormValues | null > ( null ) ;
184
179
185
- const assistParams = useMemo (
186
- ( ) => ( {
187
- docs_url : assistData ?. docsUrl ,
188
- openapi_spec_url : assistData ?. openApiSpecUrl ,
189
- app_name : appName ,
190
- url_base : baseUrl ,
191
- } ) ,
192
- [ assistData ?. docsUrl , assistData ?. openApiSpecUrl , appName , baseUrl ]
193
- ) ;
194
-
195
180
const submitResponse = useCallback (
196
181
( values : AddStreamFormValues ) => {
197
182
const otherStreamValues = values . copyOtherStream
@@ -235,10 +220,9 @@ const AddStreamModal = ({
235
220
return null ;
236
221
}
237
222
return {
238
- ...assistParams ,
239
223
stream_name : assistFormValues . streamName ,
240
224
} ;
241
- } , [ assistParams , assistFormValues ] ) ;
225
+ } , [ assistFormValues ] ) ;
242
226
243
227
return (
244
228
< Modal
@@ -255,7 +239,6 @@ const AddStreamModal = ({
255
239
isDuplicate = { isDuplicate }
256
240
streams = { streams }
257
241
initialUrlPath = { initialUrlPath }
258
- assistParams = { assistParams }
259
242
shouldAssist = { shouldAssist }
260
243
/>
261
244
) }
@@ -276,19 +259,21 @@ const AddStreamForm = ({
276
259
isDuplicate,
277
260
streams,
278
261
initialUrlPath,
279
- assistParams,
280
262
shouldAssist,
281
263
} : {
282
264
onSubmit : ( values : AddStreamFormValues ) => void ;
283
265
onCancel : ( ) => void ;
284
266
isDuplicate : boolean ;
285
267
streams : BuilderStream [ ] ;
286
268
initialUrlPath ?: string ;
287
- assistParams : BuilderAssistGlobalParams ;
288
269
shouldAssist : boolean ;
289
270
} ) => {
290
271
const { formatMessage } = useIntl ( ) ;
291
272
273
+ const { data, isFetching } = useBuilderAssistFindStreams ( {
274
+ enabled : shouldAssist ,
275
+ } ) ;
276
+
292
277
const showCopyFromStream = ! isDuplicate && streams . length > 0 ;
293
278
const showUrlPath = ! shouldAssist ;
294
279
@@ -306,6 +291,7 @@ const AddStreamForm = ({
306
291
validator . urlPath = yup . string ( ) . required ( "form.empty.error" ) ;
307
292
}
308
293
294
+ // put the main form default values here so the API can use the context in the new form
309
295
const methods = useForm ( {
310
296
defaultValues : {
311
297
streamName : "" ,
@@ -324,7 +310,7 @@ const AddStreamForm = ({
324
310
< form onSubmit = { methods . handleSubmit ( onSubmit ) } >
325
311
< ModalBody className = { styles . body } >
326
312
{ shouldAssist ? (
327
- < AssistedStreamNameField path = "streamName" streams = { streams } assistParams = { assistParams } />
313
+ < AssistedStreamNameField path = "streamName" streams = { streams } data = { data } isFetching = { isFetching } />
328
314
) : (
329
315
< BuilderField
330
316
path = "streamName"
@@ -393,19 +379,16 @@ const AssistLoadingMessage = () => {
393
379
const AssistedStreamNameField = ( {
394
380
path,
395
381
streams,
396
- assistParams,
382
+ data,
383
+ isFetching,
397
384
} : {
398
385
path : string ;
399
386
streams : BuilderStream [ ] ;
400
- assistParams : BuilderAssistGlobalParams ;
387
+ data : BuilderAssistFindStreamsResponse | undefined ;
388
+ isFetching : boolean ;
401
389
} ) => {
402
390
const { formatMessage } = useIntl ( ) ;
403
391
404
- const { data, isFetching } = useBuilderAssistFindStreams ( {
405
- ...assistParams ,
406
- enabled : true ,
407
- } ) ;
408
-
409
392
const streamOptions = useMemo ( ( ) => {
410
393
if ( data ) {
411
394
return getStreamOptions ( streams , data ) ;
@@ -443,7 +426,7 @@ const AssistProcessing = ({
443
426
onComplete,
444
427
onSkip,
445
428
} : {
446
- input : BuilderAssistCreateStreamParams ;
429
+ input : BuilderAssistInputStreamParams ;
447
430
onComplete : ( values : AddStreamResponse ) => void ;
448
431
onSkip : ( ) => void ;
449
432
} ) => {
0 commit comments