Skip to content

Commit deaa5af

Browse files
committed
tighten typing of select box webview messages
1 parent a7868ab commit deaa5af

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

src/notebooks/deepnote/selectInputSettingsWebview.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { inject, injectable } from 'inversify';
1717
import { IExtensionContext } from '../../platform/common/types';
1818
import { LocalizedMessages } from '../../messageTypes';
1919
import * as localize from '../../platform/common/utils/localize';
20-
import { SelectInputSettings } from '../../platform/notebooks/deepnote/types';
20+
import { SelectInputSettings, SelectInputWebviewMessage } from '../../platform/notebooks/deepnote/types';
2121

2222
/**
2323
* Manages the webview panel for select input settings
@@ -145,10 +145,10 @@ export class SelectInputSettingsWebviewProvider {
145145
});
146146
}
147147

148-
private async handleMessage(message: { type: string; settings?: SelectInputSettings }): Promise<void> {
148+
private async handleMessage(message: SelectInputWebviewMessage): Promise<void> {
149149
switch (message.type) {
150150
case 'save':
151-
if (message.settings && this.currentCell) {
151+
if (this.currentCell) {
152152
try {
153153
await this.saveSettings(message.settings);
154154
if (this.resolvePromise) {
@@ -174,6 +174,11 @@ export class SelectInputSettingsWebviewProvider {
174174
}
175175
this.currentPanel?.dispose();
176176
break;
177+
178+
case 'init':
179+
case 'locInit':
180+
// These messages are sent from extension to webview, not handled here
181+
break;
177182
}
178183
}
179184

src/platform/notebooks/deepnote/types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ export interface SelectInputSettings {
1717
/**
1818
* Message types for select input settings webview
1919
*/
20-
export interface SelectInputWebviewMessage {
21-
type: 'init' | 'save' | 'locInit' | 'cancel';
22-
settings?: SelectInputSettings;
23-
locStrings?: Record<string, string>;
24-
}
20+
export type SelectInputWebviewMessage =
21+
| { type: 'init'; settings: SelectInputSettings }
22+
| { type: 'save'; settings: SelectInputSettings }
23+
| { type: 'locInit'; locStrings: Record<string, string> }
24+
| { type: 'cancel' };
2525

2626
export const IIntegrationStorage = Symbol('IIntegrationStorage');
2727
export interface IIntegrationStorage extends IDisposable {

src/webviews/webview-side/selectInputSettings/SelectInputSettingsPanel.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ export const SelectInputSettingsPanel: React.FC<ISelectInputSettingsPanelProps>
2828

2929
switch (message.type) {
3030
case 'init':
31-
if (message.settings) {
32-
setSettings(message.settings);
33-
}
31+
setSettings(message.settings);
3432
break;
3533

3634
case 'locInit':
37-
if (message.locStrings) {
38-
storeLocStrings(message.locStrings);
39-
}
35+
storeLocStrings(message.locStrings);
36+
break;
37+
38+
case 'save':
39+
case 'cancel':
40+
// These messages are sent from webview to extension, not handled here
4041
break;
4142
}
4243
};

0 commit comments

Comments
 (0)