Skip to content

Commit 6ba4e28

Browse files
committed
fix: persist integration state in webview provider to prevent stale data
1 parent 120e88a commit 6ba4e28

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

src/notebooks/deepnote/integrations/integrationWebview.ts

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export class IntegrationWebviewProvider implements IIntegrationWebviewProvider {
1515

1616
private readonly disposables: Disposable[] = [];
1717

18+
private integrations: Map<string, IntegrationWithStatus> = new Map();
19+
1820
constructor(
1921
@inject(IExtensionContext) private readonly extensionContext: IExtensionContext,
2022
@inject(IIntegrationStorage) private readonly integrationStorage: IIntegrationStorage
@@ -24,12 +26,15 @@ export class IntegrationWebviewProvider implements IIntegrationWebviewProvider {
2426
* Show the integration management webview
2527
*/
2628
public async show(integrations: Map<string, IntegrationWithStatus>): Promise<void> {
29+
// Update the stored integrations with the latest data
30+
this.integrations = integrations;
31+
2732
const column = window.activeTextEditor ? window.activeTextEditor.viewColumn : ViewColumn.One;
2833

2934
// If we already have a panel, show it
3035
if (this.currentPanel) {
3136
this.currentPanel.reveal(column);
32-
await this.updateWebview(integrations);
37+
await this.updateWebview();
3338
return;
3439
}
3540

@@ -46,12 +51,12 @@ export class IntegrationWebviewProvider implements IIntegrationWebviewProvider {
4651
);
4752

4853
// Set the webview's initial html content
49-
this.currentPanel.webview.html = this.getWebviewContent(integrations);
54+
this.currentPanel.webview.html = this.getWebviewContent();
5055

5156
// Handle messages from the webview
5257
this.currentPanel.webview.onDidReceiveMessage(
5358
async (message) => {
54-
await this.handleMessage(message, integrations);
59+
await this.handleMessage(message);
5560
},
5661
null,
5762
this.disposables
@@ -61,25 +66,26 @@ export class IntegrationWebviewProvider implements IIntegrationWebviewProvider {
6166
this.currentPanel.onDidDispose(
6267
() => {
6368
this.currentPanel = undefined;
69+
this.integrations = new Map();
6470
this.disposables.forEach((d) => d.dispose());
6571
this.disposables.length = 0;
6672
},
6773
null,
6874
this.disposables
6975
);
7076

71-
await this.updateWebview(integrations);
77+
await this.updateWebview();
7278
}
7379

7480
/**
7581
* Update the webview with current integration data
7682
*/
77-
private async updateWebview(integrations: Map<string, IntegrationWithStatus>): Promise<void> {
83+
private async updateWebview(): Promise<void> {
7884
if (!this.currentPanel) {
7985
return;
8086
}
8187

82-
const integrationsData = Array.from(integrations.entries()).map(([id, integration]) => ({
88+
const integrationsData = Array.from(this.integrations.entries()).map(([id, integration]) => ({
8389
config: integration.config,
8490
id,
8591
status: integration.status
@@ -94,28 +100,29 @@ export class IntegrationWebviewProvider implements IIntegrationWebviewProvider {
94100
/**
95101
* Handle messages from the webview
96102
*/
97-
private async handleMessage(
98-
message: { type: string; integrationId?: string; config?: IntegrationConfig },
99-
integrations: Map<string, IntegrationWithStatus>
100-
): Promise<void> {
103+
private async handleMessage(message: {
104+
type: string;
105+
integrationId?: string;
106+
config?: IntegrationConfig;
107+
}): Promise<void> {
101108
logger.debug(`IntegrationWebview: Received message: ${message.type}`);
102109

103110
switch (message.type) {
104111
case 'configure':
105112
if (message.integrationId) {
106-
await this.showConfigurationForm(message.integrationId, integrations);
113+
await this.showConfigurationForm(message.integrationId);
107114
}
108115
break;
109116

110117
case 'save':
111118
if (message.config) {
112-
await this.saveConfiguration(message.config, integrations);
119+
await this.saveConfiguration(message.config);
113120
}
114121
break;
115122

116123
case 'delete':
117124
if (message.integrationId) {
118-
await this.deleteConfiguration(message.integrationId, integrations);
125+
await this.deleteConfiguration(message.integrationId);
119126
}
120127
break;
121128

@@ -127,11 +134,8 @@ export class IntegrationWebviewProvider implements IIntegrationWebviewProvider {
127134
/**
128135
* Show configuration form for an integration
129136
*/
130-
private async showConfigurationForm(
131-
integrationId: string,
132-
integrations: Map<string, IntegrationWithStatus>
133-
): Promise<void> {
134-
const integration = integrations.get(integrationId);
137+
private async showConfigurationForm(integrationId: string): Promise<void> {
138+
const integration = this.integrations.get(integrationId);
135139
const existingConfig = integration?.config;
136140

137141
await this.currentPanel?.webview.postMessage({
@@ -144,20 +148,17 @@ export class IntegrationWebviewProvider implements IIntegrationWebviewProvider {
144148
/**
145149
* Save integration configuration
146150
*/
147-
private async saveConfiguration(
148-
config: IntegrationConfig,
149-
integrations: Map<string, IntegrationWithStatus>
150-
): Promise<void> {
151+
private async saveConfiguration(config: IntegrationConfig): Promise<void> {
151152
try {
152153
await this.integrationStorage.save(config);
153154

154-
// Update the integrations map
155-
integrations.set(config.id, {
155+
// Update the integrations map with the latest state
156+
this.integrations.set(config.id, {
156157
config,
157158
status: IntegrationStatus.Connected
158159
});
159160

160-
await this.updateWebview(integrations);
161+
await this.updateWebview();
161162

162163
await this.currentPanel?.webview.postMessage({
163164
message: 'Configuration saved successfully',
@@ -175,23 +176,20 @@ export class IntegrationWebviewProvider implements IIntegrationWebviewProvider {
175176
/**
176177
* Delete integration configuration
177178
*/
178-
private async deleteConfiguration(
179-
integrationId: string,
180-
integrations: Map<string, IntegrationWithStatus>
181-
): Promise<void> {
179+
private async deleteConfiguration(integrationId: string): Promise<void> {
182180
try {
183181
await this.integrationStorage.delete(integrationId);
184182

185-
// Update the integrations map
186-
const integration = integrations.get(integrationId);
183+
// Update the integrations map with the latest state
184+
const integration = this.integrations.get(integrationId);
187185
if (integration) {
188-
integrations.set(integrationId, {
186+
this.integrations.set(integrationId, {
189187
config: null,
190188
status: IntegrationStatus.Disconnected
191189
});
192190
}
193191

194-
await this.updateWebview(integrations);
192+
await this.updateWebview();
195193

196194
await this.currentPanel?.webview.postMessage({
197195
message: 'Configuration deleted successfully',
@@ -209,7 +207,7 @@ export class IntegrationWebviewProvider implements IIntegrationWebviewProvider {
209207
/**
210208
* Get the HTML content for the webview
211209
*/
212-
private getWebviewContent(_integrations: Map<string, IntegrationWithStatus>): string {
210+
private getWebviewContent(): string {
213211
const nonce = this.getNonce();
214212

215213
return `<!DOCTYPE html>

0 commit comments

Comments
 (0)