Skip to content

Commit c927d96

Browse files
authored
Fixing React RPC and table designer typings. (#17958)
* Adding types to webview reducers * moving table designer interfaces to a shared file * Adding types to vscode connection provider as well
1 parent 7ae2ffd commit c927d96

25 files changed

+706
-1174
lines changed

src/connectionconfig/connectionDialogWebViewController.ts

+69-74
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
import * as vscode from 'vscode';
77
import { ReactWebViewPanelController } from "../controllers/reactWebviewController";
8-
import { ApiStatus, AuthenticationType, ConnectionDialogWebviewState, FormComponent, FormComponentActionButton, FormComponentOptions, FormComponentType, FormEvent, FormTabs, IConnectionDialogProfile } from '../sharedInterfaces/connectionDialog';
8+
import { ApiStatus, AuthenticationType, ConnectionDialogReducers, ConnectionDialogWebviewState, FormComponent, FormComponentActionButton, FormComponentOptions, FormComponentType, FormTabs, IConnectionDialogProfile } from '../sharedInterfaces/connectionDialog';
99
import { IConnectionInfo } from 'vscode-mssql';
1010
import MainController from '../controllers/mainController';
1111
import { getConnectionDisplayName } from '../models/connectionInfo';
1212
import { AzureController } from '../azure/azureController';
1313
import { ObjectExplorerProvider } from '../objectExplorer/objectExplorerProvider';
1414

15-
export class ConnectionDialogWebViewController extends ReactWebViewPanelController<ConnectionDialogWebviewState> {
15+
export class ConnectionDialogWebViewController extends ReactWebViewPanelController<ConnectionDialogWebviewState, ConnectionDialogReducers> {
1616
private _connectionToEditCopy: IConnectionDialogProfile | undefined;
1717
constructor(
1818
context: vscode.ExtensionContext,
@@ -476,88 +476,83 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
476476
}
477477

478478
private registerRpcHandlers() {
479-
this.registerReducers({
480-
'setFormTab': async (state, payload: {
481-
tab: FormTabs
482-
}) => {
483-
this.state.selectedFormTab = payload.tab;
484-
await this.updateItemVisibility();
485-
return state;
486-
},
487-
'formAction': async (state, payload: {
488-
event: FormEvent
489-
}) => {
490-
if (payload.event.isAction) {
491-
const component = this.getFormComponent(payload.event.propertyName);
492-
if (component && component.actionButtons) {
493-
const actionButton = component.actionButtons.find(b => b.id === payload.event.value);
494-
if (actionButton?.callback) {
495-
await actionButton.callback();
496-
}
479+
this.registerReducer('setFormTab', async (state, payload) => {
480+
this.state.selectedFormTab = payload.tab;
481+
await this.updateItemVisibility();
482+
return state;
483+
});
484+
485+
this.registerReducer('formAction', async (state, payload) => {
486+
if (payload.event.isAction) {
487+
const component = this.getFormComponent(payload.event.propertyName);
488+
if (component && component.actionButtons) {
489+
const actionButton = component.actionButtons.find(b => b.id === payload.event.value);
490+
if (actionButton?.callback) {
491+
await actionButton.callback();
497492
}
498-
} else {
499-
(this.state.connectionProfile[payload.event.propertyName] as any) = payload.event.value;
500-
await this.validateFormComponents(payload.event.propertyName);
501-
await this.handleAzureMFAEdits(payload.event.propertyName);
502493
}
503-
await this.updateItemVisibility();
504-
return state;
505-
},
506-
'loadConnection': async (state, payload: {
507-
connection: IConnectionDialogProfile
508-
}) => {
509-
this._connectionToEditCopy = structuredClone(payload.connection);
510-
this.clearFormError();
511-
this.state.connectionProfile = payload.connection;
512-
await this.updateItemVisibility();
513-
await this.handleAzureMFAEdits('azureAuthType');
514-
await this.handleAzureMFAEdits('accountId');
494+
} else {
495+
(this.state.connectionProfile[payload.event.propertyName] as any) = payload.event.value;
496+
await this.validateFormComponents(payload.event.propertyName);
497+
await this.handleAzureMFAEdits(payload.event.propertyName);
498+
}
499+
await this.updateItemVisibility();
500+
return state;
501+
});
502+
503+
this.registerReducer('loadConnection', async (state, payload) => {
504+
this._connectionToEditCopy = structuredClone(payload.connection);
505+
this.clearFormError();
506+
this.state.connectionProfile = payload.connection;
507+
await this.updateItemVisibility();
508+
await this.handleAzureMFAEdits('azureAuthType');
509+
await this.handleAzureMFAEdits('accountId');
510+
return state;
511+
});
512+
513+
this.registerReducer('connect', async (state) => {
514+
this.clearFormError();
515+
this.state.connectionStatus = ApiStatus.Loading;
516+
this.state.formError = '';
517+
this.state = this.state;
518+
const notHiddenComponents = this.state.formComponents.filter(c => !c.hidden).map(c => c.propertyName);
519+
// Set all other fields to undefined
520+
Object.keys(this.state.connectionProfile).forEach(key => {
521+
if (!notHiddenComponents.includes(key as keyof IConnectionDialogProfile)) {
522+
(this.state.connectionProfile[key as keyof IConnectionDialogProfile] as any) = undefined;
523+
}
524+
});
525+
const errorCount = await this.validateFormComponents();
526+
if (errorCount > 0) {
527+
this.state.connectionStatus = ApiStatus.Error;
515528
return state;
516-
},
517-
'connect': async (state) => {
518-
this.clearFormError();
519-
this.state.connectionStatus = ApiStatus.Loading;
520-
this.state.formError = '';
521-
this.state = this.state;
522-
const notHiddenComponents = this.state.formComponents.filter(c => !c.hidden).map(c => c.propertyName);
523-
// Set all other fields to undefined
524-
Object.keys(this.state.connectionProfile).forEach(key => {
525-
if (!notHiddenComponents.includes(key as keyof IConnectionDialogProfile)) {
526-
(this.state.connectionProfile[key as keyof IConnectionDialogProfile] as any) = undefined;
527-
}
528-
});
529-
const errorCount = await this.validateFormComponents();
530-
if (errorCount > 0) {
529+
}
530+
531+
try {
532+
const result = await this._mainController.connectionManager.connectionUI.validateAndSaveProfileFromDialog(this.state.connectionProfile as any);
533+
if (result?.errorMessage) {
534+
this.state.formError = result.errorMessage;
531535
this.state.connectionStatus = ApiStatus.Error;
532536
return state;
533537
}
534-
535-
try {
536-
const result = await this._mainController.connectionManager.connectionUI.validateAndSaveProfileFromDialog(this.state.connectionProfile as any);
537-
if (result?.errorMessage) {
538-
this.state.formError = result.errorMessage;
539-
this.state.connectionStatus = ApiStatus.Error;
540-
return state;
541-
}
542-
if (this._connectionToEditCopy) {
543-
await this._mainController.connectionManager.getUriForConnection(this._connectionToEditCopy);
544-
await this._objectExplorerProvider.removeConnectionNodes([this._connectionToEditCopy]);
545-
await this._mainController.connectionManager.connectionStore.removeProfile(this._connectionToEditCopy as any);
546-
await this._objectExplorerProvider.refresh(undefined);
547-
}
548-
await this._mainController.connectionManager.connectionUI.saveProfile(this.state.connectionProfile as any);
549-
const node = await this._mainController.createObjectExplorerSessionFromDialog(this.state.connectionProfile);
538+
if (this._connectionToEditCopy) {
539+
await this._mainController.connectionManager.getUriForConnection(this._connectionToEditCopy);
540+
await this._objectExplorerProvider.removeConnectionNodes([this._connectionToEditCopy]);
541+
await this._mainController.connectionManager.connectionStore.removeProfile(this._connectionToEditCopy as any);
550542
await this._objectExplorerProvider.refresh(undefined);
551-
await this.loadRecentConnections();
552-
this.state.connectionStatus = ApiStatus.Loaded;
553-
await this._mainController.objectExplorerTree.reveal(node, { focus: true, select: true, expand: true });
554-
await this.panel.dispose();
555-
} catch (error) {
556-
this.state.connectionStatus = ApiStatus.Error;
557-
return state;
558543
}
544+
await this._mainController.connectionManager.connectionUI.saveProfile(this.state.connectionProfile as any);
545+
const node = await this._mainController.createObjectExplorerSessionFromDialog(this.state.connectionProfile);
546+
await this._objectExplorerProvider.refresh(undefined);
547+
await this.loadRecentConnections();
548+
this.state.connectionStatus = ApiStatus.Loaded;
549+
await this._mainController.objectExplorerTree.reveal(node, { focus: true, select: true, expand: true });
550+
await this.panel.dispose();
551+
} catch (error) {
552+
this.state.connectionStatus = ApiStatus.Error;
559553
return state;
560554
}
555+
return state;
561556
});
562557
}
563558
}

0 commit comments

Comments
 (0)