Skip to content

Commit

Permalink
adding flags for left side panels
Browse files Browse the repository at this point in the history
  • Loading branch information
saranyaloganathan23 committed Dec 5, 2024
1 parent d93b3f9 commit 70b0dbd
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 122 deletions.
6 changes: 0 additions & 6 deletions dataproc_jupyter_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
from traitlets import Bool
from jupyter_server.serverapp import ServerApp

from dataproc_jupyter_plugin.commons.vertexPlatform import _parse_vertexai_flag


from .handlers import DataprocPluginConfig, configure_gateway_client_url, setup_handlers

Expand Down Expand Up @@ -89,10 +87,6 @@ def _load_jupyter_server_extension(server_app):
server_app: jupyterlab.labapp.LabApp
JupyterLab application instance
"""
flag_status = _parse_vertexai_flag()

# Log the verterai flag
server_app.log.info(f"Vertexai flag: {flag_status}")

setup_handlers(server_app.web_app)
name = "dataproc_jupyter_plugin"
Expand Down
22 changes: 0 additions & 22 deletions dataproc_jupyter_plugin/commons/vertexPlatform.py

This file was deleted.

28 changes: 0 additions & 28 deletions dataproc_jupyter_plugin/controllers/vertexPlatform.py

This file was deleted.

13 changes: 11 additions & 2 deletions dataproc_jupyter_plugin/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
composer,
dataproc,
executor,
vertexPlatform,
)

_region_not_set_error = """GCP region not set in gcloud.
Expand Down Expand Up @@ -85,6 +84,16 @@ class DataprocPluginConfig(SingletonConfigurable):
config=True,
help="Enable integration with BigQuery in JupyterLab",
)
enable_cloud_storage_integration = Bool(
False,
config=True,
help="Enable integration with gcs in JupyterLab",
)
enable_metastore_integration = Bool(
False,
config=True,
help="Enable integration with gcs in JupyterLab",
)


class SettingsHandler(APIHandler):
Expand All @@ -101,6 +110,7 @@ def get(self):
#
# We explicitly filter out the `config`, `parent`, and `log` attributes
# that are inherited from the `SingletonConfigurable` class.
print("aaaaa", t, v)
if t not in dataproc_plugin_config and t not in ["config", "parent", "log"]:
if v.default_value is not Undefined:
dataproc_plugin_config[t] = v.default_value
Expand Down Expand Up @@ -210,7 +220,6 @@ def full_path(name):
"bigQueryPreview": bigquery.PreviewController,
"bigQueryProjectsList": bigquery.ProjectsController,
"bigQuerySearch": bigquery.SearchController,
"api/vertexPlatform": vertexPlatform.VertexPlatformController,
}
handlers = [(full_path(name), handler) for name, handler in handlersMap.items()]
web_app.add_handlers(host_pattern, handlers)
6 changes: 0 additions & 6 deletions schema/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@
},
"type": "object",
"properties": {
"previewEnabled": {
"type": "boolean",
"title": "Enable Preview Features",
"description": "Whether or not preview features such as the DPMS explorer and GCS browser are enabled.",
"default": true
},
"bqRegion": {
"type": "string",
"title": "Set the BQ Region",
Expand Down
91 changes: 33 additions & 58 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ const iconPythonLogo = new LabIcon({
svgstr: pythonLogo
});

interface VertexResponse {
enabled: boolean;
error?: string; // Optional error property for error cases
}

const extension: JupyterFrontEndPlugin<void> = {
id: PLUGIN_ID,
autoStart: true,
Expand Down Expand Up @@ -151,27 +148,27 @@ const extension: JupyterFrontEndPlugin<void> = {
localStorage.removeItem('notebookValue');
});
interface SettingsResponse {
enable_metastore_integration: any;
enable_cloud_storage_integration?: boolean;
enable_bigquery_integration?: boolean;
}
let bqFeature: SettingsResponse = await requestAPI('settings');
// START -- Enable Preview Features.
const settings = await settingRegistry.load(PLUGIN_ID);

// The current value of whether or not preview features are enabled.
let previewEnabled = settings.get('previewEnabled').composite as boolean;
let panelDpms: Panel | undefined,
panelGcs: Panel | undefined,
panelDatasetExplorer: Panel | undefined;
let gcsDrive: GCSDrive | undefined;
settings.changed.connect(() => {
onPreviewEnabledChanged();
});


// Capture the signal
eventEmitter.on('dataprocConfigChange', (message: string) => {
if (bqFeature.enable_bigquery_integration) {
loadBigQueryWidget('');
}
onPreviewEnabledChanged()
});

/**
Expand Down Expand Up @@ -204,39 +201,37 @@ const extension: JupyterFrontEndPlugin<void> = {
* as necessary.
*/
const onPreviewEnabledChanged = async () => {
previewEnabled = settings.get('previewEnabled').composite as boolean;
if (!previewEnabled) {
// Preview was disabled, tear everything down.
if (!bqFeature.enable_metastore_integration) {
// Preview was disabled, tear everything down.
panelDpms?.dispose();
panelDatasetExplorer?.dispose();
panelDpms = undefined;
}
if (!bqFeature.enable_cloud_storage_integration){
panelGcs?.dispose();
gcsDrive?.dispose();
panelDpms = undefined;
panelDatasetExplorer = undefined;
panelGcs = undefined;
gcsDrive = undefined;
} else {
// Preview was enabled, (re)create DPMS and GCS.
if (!panelDpms && !panelGcs) {
const vertexai: VertexResponse = await requestAPI('api/vertexPlatform')
if(!vertexai.enabled){
}
if(!bqFeature.enable_bigquery_integration){
panelDatasetExplorer?.dispose();
panelDatasetExplorer = undefined;
}
if(bqFeature.enable_bigquery_integration || bqFeature.enable_cloud_storage_integration || bqFeature.enable_metastore_integration){
panelDpms = new Panel();
panelDpms.id = 'dpms-tab';
panelDpms.title.caption = 'Dataset Explorer - DPMS';
panelDpms.addWidget(new dpmsWidget(app as JupyterLab, themeManager));
if (bqFeature.enable_bigquery_integration && !panelDatasetExplorer) {
panelDatasetExplorer = new Panel();
panelDatasetExplorer.id = 'dataset-explorer-tab';
panelDatasetExplorer.title.caption = 'Dataset Explorer - BigQuery';
panelDatasetExplorer.addWidget(
new BigQueryWidget(
app as JupyterLab,
settingRegistry as ISettingRegistry,
bqFeature.enable_bigquery_integration as boolean,
themeManager
)
);
}
panelDatasetExplorer = new Panel();
panelDatasetExplorer.id = 'dataset-explorer-tab';
panelDatasetExplorer.title.caption = 'Dataset Explorer - BigQuery';
panelDatasetExplorer.addWidget(
new BigQueryWidget(
app as JupyterLab,
settingRegistry as ISettingRegistry,
bqFeature.enable_bigquery_integration as boolean,
themeManager
)
);
panelGcs = new Panel();
panelGcs.id = 'GCS-bucket-tab';
panelGcs.title.caption = 'Google Cloud Storage';
Expand All @@ -245,38 +240,18 @@ const extension: JupyterFrontEndPlugin<void> = {
panelGcs.addWidget(
new GcsBrowserWidget(gcsDrive, factory as IFileBrowserFactory)
);
// Update the icons.
onThemeChanged();
app.shell.add(panelGcs, 'left', { rank: 1002 });
if (bqFeature.enable_bigquery_integration && panelDatasetExplorer) {
app.shell.add(panelDatasetExplorer, 'left', { rank: 1000 });
if(bqFeature.enable_bigquery_integration){
app.shell.add(panelDatasetExplorer, 'left', { rank: 1000 });
}
if(bqFeature.enable_metastore_integration){
app.shell.add(panelDpms, 'left', { rank: 1001 });
}
else{
panelDpms = new Panel();
panelDpms.id = 'dpms-tab';
panelDpms.title.caption = 'Dataset Explorer - DPMS';
panelDpms.addWidget(new dpmsWidget(app as JupyterLab, themeManager));
if (bqFeature.enable_bigquery_integration && !panelDatasetExplorer) {
panelDatasetExplorer = new Panel();
panelDatasetExplorer.id = 'dataset-explorer-tab';
panelDatasetExplorer.title.caption = 'Dataset Explorer - BigQuery';
panelDatasetExplorer.addWidget(
new BigQueryWidget(
app as JupyterLab,
settingRegistry as ISettingRegistry,
bqFeature.enable_bigquery_integration as boolean,
themeManager
)
);
}
onThemeChanged();
app.shell.add(panelDpms, 'left', { rank: 1001 });
}
if(bqFeature.enable_cloud_storage_integration){
app.shell.add(panelGcs, 'left', { rank: 1002 });
}
}
}
};

onPreviewEnabledChanged();
// END -- Enable Preview Features.
Expand Down

0 comments on commit 70b0dbd

Please sign in to comment.