@@ -56,6 +56,32 @@ export interface IntegrationConfigProps {
56
56
handleSelectedDataSourceChange : ( dataSourceMDSId ?: string , dataSourceMDSLabel ?: string ) => void ;
57
57
}
58
58
59
+ /**
60
+ * Interface for the parameters used in the addIntegration function
61
+ */
62
+ interface AddIntegrationParams {
63
+ /** Configuration settings for the integration setup */
64
+ config : IntegrationSetupInputs ;
65
+
66
+ /** Integration configuration details */
67
+ integration : IntegrationConfig ;
68
+
69
+ /** Callback function to set loading state */
70
+ setLoading : ( loading : boolean ) => void ;
71
+
72
+ /** Callback function to display toast notifications */
73
+ setCalloutLikeToast : ( title : string , color ?: Color , text ?: string ) => void ;
74
+
75
+ /** Optional MDS ID for the data source */
76
+ dataSourceMDSId ?: string ;
77
+
78
+ /** Optional MDS label for the data source */
79
+ dataSourceMDSLabel ?: string ;
80
+
81
+ /** Optional callback to set installation status */
82
+ setIsInstalling ?: ( isInstalling : boolean , success ?: boolean ) => void ;
83
+ }
84
+
59
85
type SetupCallout = { show : true ; title : string ; color ?: Color ; text ?: string } | { show : false } ;
60
86
61
87
const sqlService = new SQLService ( coreRefs . http ! ) ;
@@ -149,15 +175,6 @@ const prepareQuery = (query: string, config: IntegrationSetupInputs): string =>
149
175
/**
150
176
* Handles the integration setup process based on the connection type.
151
177
*
152
- * @param {Object } params - The parameters object
153
- * @param {IntegrationSetupInputs } params.config - Configuration settings for the integration setup
154
- * @param {IntegrationConfig } params.integration - Integration configuration details
155
- * @param {Function } params.setLoading - Callback function to set loading state
156
- * @param {Function } params.setCalloutLikeToast - Callback function to display toast notifications
157
- * @param {string } [params.dataSourceMDSId] - Optional MDS ID for the data source
158
- * @param {string } [params.dataSourceMDSLabel] - Optional MDS label for the data source
159
- * @param {Function } [params.setIsInstalling] - Optional callback to set installation status
160
- *
161
178
* @throws {Error } Throws an error if the connection type is invalid
162
179
* @returns {Promise<void> } A promise that resolves when the integration is added
163
180
*/
@@ -169,15 +186,7 @@ const addIntegration = async ({
169
186
dataSourceMDSId,
170
187
dataSourceMDSLabel,
171
188
setIsInstalling,
172
- } : {
173
- config : IntegrationSetupInputs ;
174
- integration : IntegrationConfig ;
175
- setLoading : ( loading : boolean ) => void ;
176
- setCalloutLikeToast : ( title : string , color ?: Color , text ?: string ) => void ;
177
- dataSourceMDSId ?: string ;
178
- dataSourceMDSLabel ?: string ;
179
- setIsInstalling ?: ( isInstalling : boolean , success ?: boolean ) => void ;
180
- } ) : Promise < void > => {
189
+ } : AddIntegrationParams ) : Promise < void > => {
181
190
setLoading ( true ) ;
182
191
183
192
if ( config . connectionType === 'index' ) {
@@ -209,24 +218,8 @@ const addIntegration = async ({
209
218
/**
210
219
* Handles the installation of an integration index by processing the configuration and making the integration request.
211
220
*
212
- * @param {Object } params - The parameters object
213
- * @param {IntegrationSetupInputs } params.config - Configuration inputs for the integration setup
214
- * @param {IntegrationConfig } params.integration - Integration configuration object
215
- * @param {Function } params.setLoading - Function to set the loading state
216
- * @param {Function } params.setCalloutLikeToast - Function to display toast notifications
217
- * @param {string } [params.dataSourceMDSId] - Optional MDS ID for the data source
218
- * @param {string } [params.dataSourceMDSLabel] - Optional MDS label for the data source
219
- * @param {Function } [params.setIsInstalling] - Optional function to set installation status
220
- *
221
221
* @returns {Promise<void> } A promise that resolves when the installation is complete
222
222
*
223
- * @example
224
- * await addNativeIntegration({
225
- * config: setupInputs,
226
- * integration: integrationConfig,
227
- * setLoading: (loading) => setLoadingState(loading),
228
- * setCalloutLikeToast: (title, color, text) => showToast(title, color, text)
229
- * });
230
223
*/
231
224
const addNativeIntegration = async ( {
232
225
config,
@@ -236,15 +229,7 @@ const addNativeIntegration = async ({
236
229
dataSourceMDSId,
237
230
dataSourceMDSLabel,
238
231
setIsInstalling,
239
- } : {
240
- config : IntegrationSetupInputs ;
241
- integration : IntegrationConfig ;
242
- setLoading : ( loading : boolean ) => void ;
243
- setCalloutLikeToast : ( title : string , color ?: Color , text ?: string ) => void ;
244
- dataSourceMDSId ?: string ;
245
- dataSourceMDSLabel ?: string ;
246
- setIsInstalling ?: ( isInstalling : boolean , success ?: boolean ) => void ;
247
- } ) : Promise < void > => {
232
+ } : AddIntegrationParams ) : Promise < void > => {
248
233
let enabledWorkflows : string [ ] | undefined ;
249
234
if ( integration . workflows ) {
250
235
enabledWorkflows = integration . workflows
@@ -279,15 +264,6 @@ const addNativeIntegration = async ({
279
264
* Handles the installation process for S3 integration by creating a database (if specified),
280
265
* processing integration assets, and executing necessary queries.
281
266
*
282
- * @param {Object } params - The parameters object
283
- * @param {IntegrationSetupInputs } params.config - Configuration settings for the integration setup
284
- * @param {IntegrationConfig } params.integration - Integration configuration details
285
- * @param {Function } params.setLoading - Callback function to set loading state
286
- * @param {Function } params.setCalloutLikeToast - Callback function to display toast notifications
287
- * @param {string } [params.dataSourceMDSId] - Optional MDS ID for the data source
288
- * @param {string } [params.dataSourceMDSLabel] - Optional MDS label for the data source
289
- * @param {Function } [params.setIsInstalling] - Optional callback to set installation status
290
- *
291
267
* @returns {Promise<void> } A promise that resolves when the installation is complete
292
268
*
293
269
* @throws Will set error toast if database creation fails or integration addition fails
@@ -300,34 +276,22 @@ const addFlintIntegration = async ({
300
276
dataSourceMDSId,
301
277
dataSourceMDSLabel,
302
278
setIsInstalling,
303
- } : {
304
- config : IntegrationSetupInputs ;
305
- integration : IntegrationConfig ;
306
- setLoading : ( loading : boolean ) => void ;
307
- setCalloutLikeToast : ( title : string , color ?: Color , text ?: string ) => void ;
308
- dataSourceMDSId ?: string ;
309
- dataSourceMDSLabel ?: string ;
310
- setIsInstalling ?: ( isInstalling : boolean , success ?: boolean ) => void ;
311
- } ) : Promise < void > => {
279
+ } : AddIntegrationParams ) : Promise < void > => {
312
280
let sessionId : string | undefined ;
313
281
314
282
// Create database if specified
315
- if ( config . databaseName ) {
316
- const createDbQuery = `CREATE DATABASE IF NOT EXISTS ${ config . databaseName } ` ;
317
- const result = await runQuery (
318
- createDbQuery ,
319
- config . connectionDataSource ,
320
- sessionId ,
321
- dataSourceMDSId
322
- ) ;
283
+ const dbResult = await createDatabase (
284
+ config ,
285
+ sessionId ,
286
+ dataSourceMDSId ,
287
+ setLoading ,
288
+ setCalloutLikeToast
289
+ ) ;
323
290
324
- if ( ! result . ok ) {
325
- setLoading ( false ) ;
326
- setCalloutLikeToast ( 'Failed to create database' , 'danger' , result . error . message ) ;
327
- return ;
328
- }
329
- sessionId = result . value . sessionId ;
291
+ if ( ! dbResult . success ) {
292
+ return ;
330
293
}
294
+ sessionId = dbResult . sessionId ;
331
295
332
296
// Process integration assets
333
297
const http = coreRefs . http ! ;
@@ -386,6 +350,53 @@ const addFlintIntegration = async ({
386
350
}
387
351
} ;
388
352
353
+ /**
354
+ * Creates a database if it doesn't already exist using the provided configuration.
355
+ *
356
+ * @param config - Configuration object containing database details
357
+ * @param config.databaseName - Name of the database to create
358
+ * @param config.connectionDataSource - Data source connection string
359
+ * @param sessionId - Current session identifier
360
+ * @param dataSourceMDSId - Data source MDS identifier
361
+ * @param setLoading - Callback function to update loading state
362
+ * @param setCalloutLikeToast - Callback function to display toast notifications
363
+ * @param setCalloutLikeToast.message - Message to display in the toast
364
+ * @param setCalloutLikeToast.type - Type of toast notification (e.g., 'danger')
365
+ * @param setCalloutLikeToast.details - Optional details for the toast message
366
+ *
367
+ * @returns Promise resolving to an object containing:
368
+ * - success: boolean indicating if the operation was successful
369
+ * - sessionId: the current or updated session identifier
370
+ *
371
+ */
372
+ const createDatabase = async (
373
+ config : { databaseName : string ; connectionDataSource : string } ,
374
+ sessionId : string ,
375
+ dataSourceMDSId : string ,
376
+ setLoading : ( loading : boolean ) => void ,
377
+ setCalloutLikeToast : ( message : string , type : string , details ?: string ) => void
378
+ ) : Promise < { success : boolean ; sessionId : string } > => {
379
+ if ( ! config . databaseName ) {
380
+ return { success : true , sessionId } ;
381
+ }
382
+
383
+ const createDbQuery = `CREATE DATABASE IF NOT EXISTS ${ config . databaseName } ` ;
384
+ const result = await runQuery (
385
+ createDbQuery ,
386
+ config . connectionDataSource ,
387
+ sessionId ,
388
+ dataSourceMDSId
389
+ ) ;
390
+
391
+ if ( ! result . ok ) {
392
+ setLoading ( false ) ;
393
+ setCalloutLikeToast ( 'Failed to create database' , 'danger' , result . error . message ) ;
394
+ return { success : false , sessionId } ;
395
+ }
396
+
397
+ return { success : true , sessionId : result . value . sessionId } ;
398
+ } ;
399
+
389
400
const isConfigValid = ( config : IntegrationSetupInputs , integration : IntegrationConfig ) : boolean => {
390
401
if ( config . displayName . length < 1 || config . connectionDataSource . length < 1 ) {
391
402
return false ;
0 commit comments