88 createInput ,
99 createSelect ,
1010 createToast ,
11+ initToastHistoryListeners ,
1112 syntaxHighlight
1213} from "../shared.js" ;
1314import { dataSourcePropertiesMap } from "../configuration-data.js" ;
@@ -79,27 +80,23 @@ async function testExistingConnection(connectionName, button) {
7980 } ) ;
8081
8182 const result = await response . json ( ) ;
82- // Limit to 100 characters, show ellipsis if truncated
83- const resultDetails = result . details ? ` - ${ truncateString ( result . details , 100 ) } ` : "" ;
8483 if ( result . success ) {
8584 createToast (
8685 `Test: ${ connectionName } ` ,
87- `${ result . message } ${ resultDetails } ` ,
86+ `${ result . message } ${ result . details } ` ,
8887 "success"
8988 ) ;
9089 } else {
9190 createToast (
9291 `Test: ${ connectionName } ` ,
93- `${ result . message } ${ resultDetails } ` ,
92+ `${ result . message } ${ result . details } ` ,
9493 "fail"
9594 ) ;
9695 }
9796 } catch ( err ) {
98- // Limit to 100 characters, show ellipsis if truncated
99- const resultDetails = err . message ? ` - ${ truncateString ( err . message , 100 ) } ` : "" ;
10097 createToast (
10198 `Test: ${ connectionName } ` ,
102- `Connection test failed: ${ resultDetails } ` ,
99+ `Connection test failed: ${ err . message } ` ,
103100 "fail"
104101 ) ;
105102 } finally {
@@ -108,10 +105,6 @@ async function testExistingConnection(connectionName, button) {
108105 }
109106}
110107
111- function truncateString ( str , maxLength ) {
112- return str . length > maxLength ? str . substring ( 0 , maxLength ) + "..." : str ;
113- }
114-
115108/**
116109 * Build a connection object from a data source container element
117110 * @param {HTMLElement } container - The data source container element
@@ -148,6 +141,7 @@ let numDataSources = 1;
148141let numExistingConnections = 0 ;
149142
150143dataSourceConfigRow . append ( createDataSourceElement ( numDataSources ) ) ;
144+ initToastHistoryListeners ( ) ;
151145addDataSourceButton . addEventListener ( "click" , function ( ) {
152146 numDataSources += 1 ;
153147 let divider = document . createElement ( "hr" ) ;
@@ -261,19 +255,9 @@ async function getExistingConnections() {
261255 createToast ( `${ connection . name } ` , `Cannot delete default connection. Modify application.conf or environment variables to remove.` , "fail" ) ;
262256 return ;
263257 }
264-
265- try {
266- const response = await apiFetch ( `/connection/${ connection . name } ` , { method : "DELETE" } ) ;
267- if ( response . ok ) {
268- accordionConnections . removeChild ( accordionItem ) ;
269- createToast ( `${ connection . name } ` , `Connection ${ connection . name } deleted!` , "success" ) ;
270- } else {
271- const errorText = await response . text ( ) ;
272- createToast ( `${ connection . name } ` , `Failed to delete connection: ${ errorText } ` , "fail" ) ;
273- }
274- } catch ( err ) {
275- createToast ( `${ connection . name } ` , `Failed to delete connection: ${ err . message } ` , "fail" ) ;
276- }
258+
259+ // Show confirmation modal
260+ showDeleteConfirmation ( connection . name , accordionItem ) ;
277261 } ) ;
278262
279263 let buttonGroup = createButtonGroup ( testButton , deleteButton ) ;
@@ -376,3 +360,48 @@ function createOptGroup(label) {
376360 metadataSourceGroup . setAttribute ( "label" , label ) ;
377361 return metadataSourceGroup ;
378362}
363+
364+ // Delete confirmation modal handling
365+ let pendingDeleteConnection = null ;
366+ let pendingDeleteAccordionItem = null ;
367+
368+ function showDeleteConfirmation ( connectionName , accordionItem ) {
369+ pendingDeleteConnection = connectionName ;
370+ pendingDeleteAccordionItem = accordionItem ;
371+
372+ const nameElement = document . getElementById ( "delete-connection-name" ) ;
373+ if ( nameElement ) {
374+ nameElement . textContent = connectionName ;
375+ }
376+
377+ const modal = new bootstrap . Modal ( document . getElementById ( "delete-confirm-modal" ) ) ;
378+ modal . show ( ) ;
379+ }
380+
381+ // Set up the confirm delete button handler
382+ document . getElementById ( "confirm-delete-btn" ) ?. addEventListener ( "click" , async function ( ) {
383+ if ( ! pendingDeleteConnection ) return ;
384+
385+ const connectionName = pendingDeleteConnection ;
386+ const accordionItem = pendingDeleteAccordionItem ;
387+
388+ // Close the modal
389+ const modal = bootstrap . Modal . getInstance ( document . getElementById ( "delete-confirm-modal" ) ) ;
390+ modal . hide ( ) ;
391+
392+ try {
393+ const response = await apiFetch ( `/connection/${ connectionName } ` , { method : "DELETE" } ) ;
394+ if ( response . ok ) {
395+ accordionConnections . removeChild ( accordionItem ) ;
396+ createToast ( `${ connectionName } ` , `Connection ${ connectionName } deleted!` , "success" ) ;
397+ } else {
398+ const errorText = await response . text ( ) ;
399+ createToast ( `${ connectionName } ` , `Failed to delete connection: ${ errorText } ` , "fail" ) ;
400+ }
401+ } catch ( err ) {
402+ createToast ( `${ connectionName } ` , `Failed to delete connection: ${ err . message } ` , "fail" ) ;
403+ } finally {
404+ pendingDeleteConnection = null ;
405+ pendingDeleteAccordionItem = null ;
406+ }
407+ } ) ;
0 commit comments