@@ -340,32 +340,33 @@ export class IntegrationWebviewProvider {
340340
341341 private getWebviewScript ( ) : string {
342342 return `
343- const vscode = acquireVsCodeApi();
344- let integrations = [];
345- let currentIntegrationId = null;
346-
347- // Handle messages from the extension
348- window.addEventListener('message', event => {
349- const message = event.data;
350- switch (message.type) {
351- case 'update':
352- integrations = message.integrations;
353- renderIntegrations();
354- break;
355- case 'showForm':
356- showConfigurationForm(message.integrationId, message.config);
357- break;
358- case 'success':
359- showMessage(message.message, 'success');
360- hideForm();
361- break;
362- case 'error':
363- showMessage(message.message, 'error');
364- break;
365- }
366- });
343+ (function() {
344+ const vscode = acquireVsCodeApi();
345+ let integrations = [];
346+ let currentIntegrationId = null;
347+
348+ // Handle messages from the extension
349+ window.addEventListener('message', event => {
350+ const message = event.data;
351+ switch (message.type) {
352+ case 'update':
353+ integrations = message.integrations;
354+ renderIntegrations();
355+ break;
356+ case 'showForm':
357+ showConfigurationForm(message.integrationId, message.config);
358+ break;
359+ case 'success':
360+ showMessage(message.message, 'success');
361+ hideForm();
362+ break;
363+ case 'error':
364+ showMessage(message.message, 'error');
365+ break;
366+ }
367+ });
367368
368- function renderIntegrations() {
369+ function renderIntegrations() {
369370 const listEl = document.getElementById('integrationList');
370371 if (!integrations || integrations.length === 0) {
371372 listEl.innerHTML = '<p>No integrations found in this project.</p>';
@@ -384,23 +385,36 @@ export class IntegrationWebviewProvider {
384385 <div class="integration-status \${statusClass}">\${statusText}</div>
385386 </div>
386387 <div class="integration-actions">
387- <button onclick ="configure(' \${integration.id}') ">\${configureText}</button>
388- \${integration.config ? '<button class="secondary" onclick="deleteConfig(\\'' +integration.id+'\\') ">Delete</button>' : ''}
388+ <button data-action ="configure" data-id=" \${integration.id}">\${configureText}</button>
389+ \${integration.config ? '<button class="secondary" data-action="delete" data-id="' +integration.id+'">Delete</button>' : ''}
389390 </div>
390391 </div>
391392 \`;
392393 }).join('');
393394 }
394395
395- function configure(integrationId) {
396- vscode.postMessage({ type: 'configure', integrationId });
397- }
398-
399- function deleteConfig(integrationId) {
400- if (confirm('Are you sure you want to delete this integration configuration?')) {
401- vscode.postMessage({ type: 'delete', integrationId });
396+ // Event delegation for button clicks
397+ document.addEventListener('click', (e) => {
398+ const target = e.target;
399+ if (target.tagName === 'BUTTON' && target.dataset.action) {
400+ const action = target.dataset.action;
401+ const integrationId = target.dataset.id;
402+
403+ if (action === 'configure') {
404+ vscode.postMessage({ type: 'configure', integrationId });
405+ } else if (action === 'delete') {
406+ if (confirm('Are you sure you want to delete this integration configuration?')) {
407+ vscode.postMessage({ type: 'delete', integrationId });
408+ }
409+ } else if (action === 'save-postgres') {
410+ savePostgresConfig();
411+ } else if (action === 'save-bigquery') {
412+ saveBigQueryConfig();
413+ } else if (action === 'cancel') {
414+ hideForm();
415+ }
402416 }
403- }
417+ });
404418
405419 function showConfigurationForm(integrationId, existingConfig) {
406420 currentIntegrationId = integrationId;
@@ -414,14 +428,19 @@ export class IntegrationWebviewProvider {
414428 <h2>Configure \${integrationId}</h2>
415429 <div class="form-group">
416430 <label>Integration Type:</label>
417- <select id="integrationType" onchange="showTypeSpecificForm()" >
431+ <select id="integrationType">
418432 <option value="">Select type...</option>
419433 <option value="postgres">PostgreSQL</option>
420434 <option value="bigquery">BigQuery</option>
421435 </select>
422436 </div>
423437 \`;
424438 formContainer.classList.add('visible');
439+
440+ // Add event listener for type selection
441+ document.getElementById('integrationType').addEventListener('change', (e) => {
442+ showTypeSpecificForm(e.target.value);
443+ });
425444 return;
426445 }
427446
@@ -460,8 +479,8 @@ export class IntegrationWebviewProvider {
460479 <input type="password" id="password" value="\${config?.password || ''}" placeholder="Enter password" required>
461480 </div>
462481 <div class="form-group">
463- <button onclick="savePostgresConfig() ">Save</button>
464- <button class="secondary" onclick="hideForm() ">Cancel</button>
482+ <button data-action="save-postgres ">Save</button>
483+ <button class="secondary" data-action="cancel ">Cancel</button>
465484 </div>
466485 \`;
467486 } else if (type === 'bigquery') {
@@ -476,8 +495,8 @@ export class IntegrationWebviewProvider {
476495 <textarea id="credentials" rows="10" placeholder="Paste service account JSON here" required>\${config?.credentials || ''}</textarea>
477496 </div>
478497 <div class="form-group">
479- <button onclick="saveBigQueryConfig() ">Save</button>
480- <button class="secondary" onclick="hideForm() ">Cancel</button>
498+ <button data-action="save-bigquery ">Save</button>
499+ <button class="secondary" data-action="cancel ">Cancel</button>
481500 </div>
482501 \`;
483502 }
@@ -535,6 +554,7 @@ export class IntegrationWebviewProvider {
535554 messageEl.classList.remove('visible');
536555 }, 5000);
537556 }
557+ })();
538558 ` ;
539559 }
540560
0 commit comments