@@ -56,7 +56,7 @@ import { ISettingRegistry } from '@jupyterlab/settingregistry';
5656import { IDocumentManager } from '@jupyterlab/docmanager' ;
5757import { GCSDrive } from './gcs/gcsDrive' ;
5858import { GcsBrowserWidget } from './gcs/gcsBrowserWidget' ;
59- import { DataprocLoggingService } from './utils/loggingService' ;
59+ import { DataprocLoggingService , LOG_LEVEL } from './utils/loggingService' ;
6060import { NotebookScheduler } from './scheduler/notebookScheduler' ;
6161import pythonLogo from '../third_party/icons/python_logo.svg' ;
6262import 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' ,
0 commit comments