Skip to content

Commit 8296452

Browse files
committed
refactor use unified iface for quick pick items
1 parent 844ee6d commit 8296452

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

src/notebooks/deepnote/sqlCellStatusBarProvider.ts

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ import { IIntegrationStorage } from './integrations/types';
2323
import { Commands } from '../../platform/common/constants';
2424
import { DATAFRAME_SQL_INTEGRATION_ID, IntegrationType } from '../../platform/notebooks/deepnote/integrationTypes';
2525

26+
/**
27+
* QuickPick item with an integration ID
28+
*/
29+
interface LocalQuickPickItem extends QuickPickItem {
30+
id: string;
31+
}
32+
2633
/**
2734
* Provides status bar items for SQL cells showing the integration name and variable name
2835
*/
@@ -253,7 +260,7 @@ export class SqlCellStatusBarProvider implements NotebookCellStatusBarItemProvid
253260
const allIntegrations = await this.integrationStorage.getAll();
254261

255262
// Build quick pick items
256-
const items: QuickPickItem[] = [];
263+
const items: (QuickPickItem | LocalQuickPickItem)[] = [];
257264

258265
// Check if current integration is unknown (not in the list)
259266
const isCurrentIntegrationUnknown =
@@ -263,46 +270,51 @@ export class SqlCellStatusBarProvider implements NotebookCellStatusBarItemProvid
263270

264271
// Add current unknown integration first if it exists
265272
if (isCurrentIntegrationUnknown && currentIntegrationId) {
266-
items.push({
273+
const item: LocalQuickPickItem = {
267274
label: l10n.t('Unknown integration (configure)'),
268275
description: currentIntegrationId,
269276
detail: l10n.t('Currently selected'),
270277
id: currentIntegrationId
271-
} as QuickPickItem & { id: string });
278+
};
279+
items.push(item);
272280
}
273281

274282
// Add all configured integrations
275283
for (const integration of allIntegrations) {
276284
const typeLabel = this.getIntegrationTypeLabel(integration.type);
277-
items.push({
285+
const item: LocalQuickPickItem = {
278286
label: integration.name || integration.id,
279287
description: typeLabel,
280288
detail: integration.id === currentIntegrationId ? l10n.t('Currently selected') : undefined,
281289
// Store the integration ID in a custom property
282290
id: integration.id
283-
} as QuickPickItem & { id: string });
291+
};
292+
items.push(item);
284293
}
285294

286295
// Add DuckDB integration
287-
items.push({
296+
const duckDbItem: LocalQuickPickItem = {
288297
label: l10n.t('DataFrame SQL (DuckDB)'),
289298
description: l10n.t('DuckDB'),
290299
detail: currentIntegrationId === DATAFRAME_SQL_INTEGRATION_ID ? l10n.t('Currently selected') : undefined,
291300
id: DATAFRAME_SQL_INTEGRATION_ID
292-
} as QuickPickItem & { id: string });
301+
};
302+
items.push(duckDbItem);
293303

294304
// Add "Configure current integration" option (with separator)
295305
if (currentIntegrationId && currentIntegrationId !== DATAFRAME_SQL_INTEGRATION_ID) {
296306
// Add separator
297-
items.push({
307+
const separator: QuickPickItem = {
298308
label: '',
299309
kind: QuickPickItemKind.Separator
300-
});
310+
};
311+
items.push(separator);
301312

302-
items.push({
313+
const configureItem: LocalQuickPickItem = {
303314
label: l10n.t('Configure current integration'),
304315
id: '__configure__'
305-
} as QuickPickItem & { id: string });
316+
};
317+
items.push(configureItem);
306318
}
307319

308320
const selected = await window.showQuickPick(items, {
@@ -314,7 +326,13 @@ export class SqlCellStatusBarProvider implements NotebookCellStatusBarItemProvid
314326
return;
315327
}
316328

317-
const selectedId = (selected as QuickPickItem & { id: string }).id;
329+
// Type guard to check if selected item has an id property
330+
if (!('id' in selected)) {
331+
return;
332+
}
333+
334+
const selectedItem = selected as LocalQuickPickItem;
335+
const selectedId = selectedItem.id;
318336

319337
// Handle "Configure current integration" option
320338
if (selectedId === '__configure__' && currentIntegrationId) {

0 commit comments

Comments
 (0)