Skip to content

Commit e29f775

Browse files
Merge pull request #196 from Shubha-accenture/vertex-gcs-disable
Create separate flags for enabling/disabling each preview feature in isolation.
2 parents 54f8def + 3541462 commit e29f775

File tree

4 files changed

+133
-79
lines changed

4 files changed

+133
-79
lines changed

dataproc_jupyter_plugin/handlers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ class DataprocPluginConfig(SingletonConfigurable):
8484
config=True,
8585
help="Enable integration with BigQuery in JupyterLab",
8686
)
87+
enable_cloud_storage_integration = Bool(
88+
False,
89+
config=True,
90+
help="Enable integration with gcs in JupyterLab",
91+
)
92+
enable_metastore_integration = Bool(
93+
False,
94+
config=True,
95+
help="Enable integration with metastore in JupyterLab",
96+
)
8797

8898

8999
class SettingsHandler(APIHandler):

schema/plugin.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121
},
2222
"type": "object",
2323
"properties": {
24-
"previewEnabled": {
25-
"type": "boolean",
26-
"title": "Enable Preview Features",
27-
"description": "Whether or not preview features such as the DPMS explorer and GCS browser are enabled.",
28-
"default": true
29-
},
3024
"bqRegion": {
3125
"type": "string",
3226
"title": "Set the BQ Region",

src/index.ts

Lines changed: 99 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import { ISettingRegistry } from '@jupyterlab/settingregistry';
5656
import { IDocumentManager } from '@jupyterlab/docmanager';
5757
import { GCSDrive } from './gcs/gcsDrive';
5858
import { GcsBrowserWidget } from './gcs/gcsBrowserWidget';
59-
import { DataprocLoggingService } from './utils/loggingService';
59+
import { DataprocLoggingService, LOG_LEVEL } from './utils/loggingService';
6060
import { NotebookScheduler } from './scheduler/notebookScheduler';
6161
import pythonLogo from '../third_party/icons/python_logo.svg';
6262
import NotebookTemplateService from './notebookTemplates/notebookTemplatesService';
@@ -151,28 +151,27 @@ const extension: JupyterFrontEndPlugin<void> = {
151151
localStorage.removeItem('notebookValue');
152152
});
153153
interface SettingsResponse {
154+
enable_metastore_integration?: boolean;
155+
enable_cloud_storage_integration?: boolean;
154156
enable_bigquery_integration?: boolean;
155157
}
156158
let bqFeature: SettingsResponse = await requestAPI('settings');
157159
// START -- Enable Preview Features.
158160
const settings = await settingRegistry.load(PLUGIN_ID);
159161

160162
// The current value of whether or not preview features are enabled.
161-
let previewEnabled = settings.get('previewEnabled').composite as boolean;
162163
let panelDpms: Panel | undefined,
163164
panelGcs: Panel | undefined,
164165
panelDatasetExplorer: Panel | undefined;
165166
let gcsDrive: GCSDrive | undefined;
166-
settings.changed.connect(() => {
167-
onPreviewEnabledChanged();
168-
});
169167

170168
// Capture the signal
171169
eventEmitter.on('dataprocConfigChange', (message: string) => {
172170
checkAllApisEnabled();
173171
if (bqFeature.enable_bigquery_integration) {
174172
loadBigQueryWidget('');
175173
}
174+
onSidePanelEnabled();
176175
});
177176

178177
const checkAllApisEnabled = async () => {
@@ -262,84 +261,121 @@ const extension: JupyterFrontEndPlugin<void> = {
262261
* Handler for when the Jupyter Lab theme changes.
263262
*/
264263
const onThemeChanged = () => {
265-
if (!panelDpms || !panelGcs) return;
264+
if (!panelDpms && !panelGcs && !panelDatasetExplorer) return;
266265
const isLightTheme = themeManager.theme
267266
? themeManager.isLight(themeManager.theme)
268267
: true;
269268
if (isLightTheme) {
270-
panelDpms.title.icon = iconDpms;
269+
if (bqFeature.enable_metastore_integration && panelDpms) {
270+
panelDpms.title.icon = iconDpms;
271+
}
271272
if (bqFeature.enable_bigquery_integration && panelDatasetExplorer) {
272273
panelDatasetExplorer.title.icon = iconDatasetExplorer;
273274
}
274-
panelGcs.title.icon = iconStorage;
275+
if (bqFeature.enable_cloud_storage_integration && panelGcs) {
276+
panelGcs.title.icon = iconStorage;
277+
}
275278
} else {
276-
panelDpms.title.icon = iconDpmsDark;
279+
if (bqFeature.enable_metastore_integration && panelDpms) {
280+
panelDpms.title.icon = iconDpmsDark;
281+
}
277282
if (bqFeature.enable_bigquery_integration && panelDatasetExplorer) {
278283
panelDatasetExplorer.title.icon = iconDatasetExplorerDark;
279284
}
280-
panelGcs.title.icon = iconStorageDark;
285+
if (bqFeature.enable_cloud_storage_integration && panelGcs) {
286+
panelGcs.title.icon = iconStorageDark;
287+
}
281288
}
282289
};
283290
themeManager.themeChanged.connect(onThemeChanged);
284291

285292
/**
286-
* Helper method for when the preview flag gets updated. This reads the
287-
* previewEnabled flag and hides or shows the GCS browser or DPMS explorer
288-
* as necessary.
293+
* Enables and disables the side panel sections DPMS, GCS and Datasset Explorer based on the flags.
289294
*/
290-
const onPreviewEnabledChanged = () => {
291-
previewEnabled = settings.get('previewEnabled').composite as boolean;
292-
if (!previewEnabled) {
293-
// Preview was disabled, tear everything down.
294-
panelDpms?.dispose();
295-
panelDatasetExplorer?.dispose();
296-
panelGcs?.dispose();
297-
gcsDrive?.dispose();
298-
panelDpms = undefined;
299-
panelDatasetExplorer = undefined;
300-
panelGcs = undefined;
301-
gcsDrive = undefined;
302-
} else {
303-
// Preview was enabled, (re)create DPMS and GCS.
304-
if (!panelDpms && !panelGcs) {
305-
panelDpms = new Panel();
306-
panelDpms.id = 'dpms-tab';
307-
panelDpms.title.caption = 'Dataset Explorer - DPMS';
308-
panelDpms.addWidget(new dpmsWidget(app as JupyterLab, themeManager));
309-
if (bqFeature.enable_bigquery_integration && !panelDatasetExplorer) {
310-
panelDatasetExplorer = new Panel();
311-
panelDatasetExplorer.id = 'dataset-explorer-tab';
312-
panelDatasetExplorer.title.caption = 'Dataset Explorer - BigQuery';
313-
panelDatasetExplorer.addWidget(
314-
new BigQueryWidget(
315-
app as JupyterLab,
316-
settingRegistry as ISettingRegistry,
317-
bqFeature.enable_bigquery_integration as boolean,
318-
themeManager
319-
)
320-
);
321-
}
322-
panelGcs = new Panel();
323-
panelGcs.id = 'GCS-bucket-tab';
324-
panelGcs.title.caption = 'Google Cloud Storage';
325-
gcsDrive = new GCSDrive();
326-
documentManager.services.contents.addDrive(gcsDrive);
327-
panelGcs.addWidget(
328-
new GcsBrowserWidget(gcsDrive, factory as IFileBrowserFactory)
329-
);
330-
// Update the icons.
331-
onThemeChanged();
332-
app.shell.add(panelGcs, 'left', { rank: 1002 });
333-
if (bqFeature.enable_bigquery_integration && panelDatasetExplorer) {
334-
app.shell.add(panelDatasetExplorer, 'left', { rank: 1000 });
335-
}
336-
app.shell.add(panelDpms, 'left', { rank: 1001 });
295+
const onSidePanelEnabled = async () => {
296+
const toBoolean = (value: any): boolean => {
297+
if (typeof value === 'boolean') return value;
298+
if (typeof value === 'string') {
299+
const lowercased = value.toLowerCase().trim();
300+
return lowercased === 'true' || lowercased === '1';
337301
}
302+
return false;
303+
};
304+
305+
// Convert configuration values to boolean
306+
const enableBigQuery = toBoolean(bqFeature.enable_bigquery_integration);
307+
const enableCloudStorage = toBoolean(
308+
bqFeature.enable_cloud_storage_integration
309+
);
310+
const enableMetastore = toBoolean(bqFeature.enable_metastore_integration);
311+
312+
// Clear any existing panels first
313+
panelDatasetExplorer?.dispose();
314+
panelDatasetExplorer = undefined;
315+
316+
panelGcs?.dispose();
317+
gcsDrive?.dispose();
318+
panelGcs = undefined;
319+
gcsDrive = undefined;
320+
321+
panelDpms?.dispose();
322+
panelDpms = undefined;
323+
324+
// Reinitialize panels based on individual flags
325+
if (enableBigQuery) {
326+
panelDatasetExplorer = new Panel();
327+
panelDatasetExplorer.id = 'dataset-explorer-tab';
328+
panelDatasetExplorer.title.caption = 'Dataset Explorer - BigQuery';
329+
panelDatasetExplorer.title.className = 'panel-icons-custom-style';
330+
panelDatasetExplorer.addWidget(
331+
new BigQueryWidget(
332+
app as JupyterLab,
333+
settingRegistry as ISettingRegistry,
334+
bqFeature.enable_bigquery_integration as boolean,
335+
themeManager
336+
)
337+
);
338+
onThemeChanged();
339+
app.shell.add(panelDatasetExplorer, 'left', { rank: 1000 });
340+
DataprocLoggingService.log(
341+
'Bigquery dataset explorer is enabled',
342+
LOG_LEVEL.INFO
343+
);
338344
}
339-
};
340345

341-
onPreviewEnabledChanged();
342-
// END -- Enable Preview Features.
346+
if (enableMetastore) {
347+
panelDpms = new Panel();
348+
panelDpms.id = 'dpms-tab';
349+
panelDpms.title.caption = 'Dataset Explorer - DPMS';
350+
panelDpms.title.className = 'panel-icons-custom-style';
351+
panelDpms.addWidget(new dpmsWidget(app as JupyterLab, themeManager));
352+
onThemeChanged();
353+
app.shell.add(panelDpms, 'left', { rank: 1001 });
354+
DataprocLoggingService.log(
355+
'Metastore is enabled',
356+
LOG_LEVEL.INFO
357+
);
358+
}
359+
360+
if (enableCloudStorage) {
361+
panelGcs = new Panel();
362+
panelGcs.id = 'GCS-bucket-tab';
363+
panelGcs.title.caption = 'Google Cloud Storage';
364+
panelGcs.title.className = 'panel-icons-custom-style';
365+
gcsDrive = new GCSDrive();
366+
documentManager.services.contents.addDrive(gcsDrive);
367+
panelGcs.addWidget(
368+
new GcsBrowserWidget(gcsDrive, factory as IFileBrowserFactory)
369+
);
370+
onThemeChanged();
371+
app.shell.add(panelGcs, 'left', { rank: 1002 });
372+
DataprocLoggingService.log(
373+
'Cloud storage is enabled',
374+
LOG_LEVEL.INFO
375+
);
376+
}
377+
};
378+
onSidePanelEnabled();
343379

344380
app.docRegistry.addWidgetExtension(
345381
'Notebook',

style/base.css

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
}
1616

1717
/*Changing Icon for category with image add python bigquery*/
18-
.favyox6 svg[data-icon='launcher:python-bigquery-logo-icon'], .f1hgkb35 svg[data-icon='launcher:python-bigquery-logo-icon'] {
18+
.favyox6 svg[data-icon='launcher:python-bigquery-logo-icon'],
19+
.f1hgkb35 svg[data-icon='launcher:python-bigquery-logo-icon'] {
1920
content-visibility: hidden;
2021
display: block;
2122
height: 32px;
@@ -25,7 +26,8 @@
2526
}
2627

2728
/*Changing Icon for category with image add runtime*/
28-
.favyox6 svg[data-icon='launcher:add-runtime-icon'], .f1hgkb35 svg[data-icon='launcher:add-runtime-icon'] {
29+
.favyox6 svg[data-icon='launcher:add-runtime-icon'],
30+
.f1hgkb35 svg[data-icon='launcher:add-runtime-icon'] {
2931
content-visibility: hidden;
3032
display: block;
3133
height: 32px;
@@ -35,7 +37,8 @@
3537
}
3638

3739
/*Changing Icon for category with image pyspark*/
38-
.favyox6 svg[data-icon='launcher:pyspark-logo-icon'], .f1hgkb35 svg[data-icon='launcher:pyspark-logo-icon'] {
40+
.favyox6 svg[data-icon='launcher:pyspark-logo-icon'],
41+
.f1hgkb35 svg[data-icon='launcher:pyspark-logo-icon'] {
3942
content-visibility: hidden;
4043
display: block;
4144
height: 32px;
@@ -45,7 +48,8 @@
4548
}
4649

4750
/*Changing Icon for category with image cluster*/
48-
.favyox6 svg[data-icon='launcher:clusters-icon'], .f1hgkb35 svg[data-icon='launcher:clusters-icon'] {
51+
.favyox6 svg[data-icon='launcher:clusters-icon'],
52+
.f1hgkb35 svg[data-icon='launcher:clusters-icon'] {
4953
content-visibility: hidden;
5054
display: block;
5155
height: 32px;
@@ -55,7 +59,8 @@
5559
}
5660

5761
/*Changing Icon for category with image python*/
58-
.favyox6 svg[data-icon='launcher:python-logo-icon'], .f1hgkb35 svg[data-icon='launcher:python-logo-icon'] {
62+
.favyox6 svg[data-icon='launcher:python-logo-icon'],
63+
.f1hgkb35 svg[data-icon='launcher:python-logo-icon'] {
5964
content-visibility: hidden;
6065
display: block;
6166
height: 32px;
@@ -65,7 +70,8 @@
6570
}
6671

6772
/*Changing Icon for category with image sparkR*/
68-
.favyox6 svg[data-icon='launcher:sparkr-logo-icon'], .f1hgkb35 svg[data-icon='launcher:sparkr-logo-icon'] {
73+
.favyox6 svg[data-icon='launcher:sparkr-logo-icon'],
74+
.f1hgkb35 svg[data-icon='launcher:sparkr-logo-icon'] {
6975
content-visibility: hidden;
7076
display: block;
7177
height: 32px;
@@ -75,7 +81,8 @@
7581
}
7682

7783
/*Changing Icon for category with image scala*/
78-
.favyox6 svg[data-icon='launcher:scala-logo-icon'], .f1hgkb35 svg[data-icon='launcher:scala-logo-icon'] {
84+
.favyox6 svg[data-icon='launcher:scala-logo-icon'],
85+
.f1hgkb35 svg[data-icon='launcher:scala-logo-icon'] {
7986
content-visibility: hidden;
8087
display: block;
8188
height: 32px;
@@ -203,13 +210,16 @@ body[data-jp-theme-name='JupyterLab Dark'] .color-icon path {
203210
body[data-jp-theme-name='JupyterLab Dark'] .filter-section-part {
204211
color: var(--jp-ui-font-color0);
205212
}
206-
body[data-jp-theme-name='JupyterLab Dark'] .schema-table th, body[data-jp-theme-name='JupyterLab Dark'] .big-query-schema-table th {
213+
body[data-jp-theme-name='JupyterLab Dark'] .schema-table th,
214+
body[data-jp-theme-name='JupyterLab Dark'] .big-query-schema-table th {
207215
background-color: var(--jp-layout-color2);
208216
}
209-
body[data-jp-theme-name='JupyterLab Dark'] .accordion-row-parent-header{
217+
body[data-jp-theme-name='JupyterLab Dark'] .accordion-row-parent-header {
210218
background: var(--jp-border-color3);
211219
}
212-
body[data-jp-theme-name='JupyterLab Dark'] .logo-alignment-style-accordion path{
220+
body[data-jp-theme-name='JupyterLab Dark']
221+
.logo-alignment-style-accordion
222+
path {
213223
fill: var(--jp-ui-font-color1);
214224
}
215225

@@ -232,3 +242,7 @@ body[data-jp-theme-name='JupyterLab Dark'] .job-cancel-button-style:hover {
232242
.css-uqjlkp-MuiFormControl-root-MuiTextField-root .MuiInputBase-root input {
233243
height: 21px;
234244
}
245+
.panel-icons-custom-style {
246+
display: flex;
247+
align-items: center;
248+
}

0 commit comments

Comments
 (0)