Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create separate flags for enabling/disabling each preview feature in isolation. #196

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions dataproc_jupyter_plugin/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,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",
saranyaloganathan23 marked this conversation as resolved.
Show resolved Hide resolved
)


class SettingsHandler(APIHandler):
Expand Down
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
67 changes: 35 additions & 32 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const iconPythonLogo = new LabIcon({
svgstr: pythonLogo
});


const extension: JupyterFrontEndPlugin<void> = {
id: PLUGIN_ID,
autoStart: true,
Expand Down Expand Up @@ -147,27 +148,27 @@ const extension: JupyterFrontEndPlugin<void> = {
localStorage.removeItem('notebookValue');
});
interface SettingsResponse {
enable_metastore_integration?: boolean;
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 @@ -199,38 +200,38 @@ const extension: JupyterFrontEndPlugin<void> = {
* previewEnabled flag and hides or shows the GCS browser or DPMS explorer
* as necessary.
*/
const onPreviewEnabledChanged = () => {
previewEnabled = settings.get('previewEnabled').composite as boolean;
if (!previewEnabled) {
// Preview was disabled, tear everything down.
const onPreviewEnabledChanged = async () => {
saranyaloganathan23 marked this conversation as resolved.
Show resolved Hide resolved
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) {
}
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 @@ -239,16 +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 });
saranyaloganathan23 marked this conversation as resolved.
Show resolved Hide resolved
}
if(bqFeature.enable_metastore_integration){
app.shell.add(panelDpms, 'left', { rank: 1001 });
saranyaloganathan23 marked this conversation as resolved.
Show resolved Hide resolved
}
if(bqFeature.enable_cloud_storage_integration){
app.shell.add(panelGcs, 'left', { rank: 1002 });
saranyaloganathan23 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
};

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