diff --git a/package-lock.json b/package-lock.json index 0e1219f0..58491782 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@nasa-terra/components", - "version": "0.0.166", + "version": "0.0.171", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@nasa-terra/components", - "version": "0.0.166", + "version": "0.0.171", "license": "MIT", "dependencies": { "@apollo/client": "^3.13.8", diff --git a/package.json b/package.json index 0bb9d839..fbce7869 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@nasa-terra/components", "description": "A collection of NASA Earthdata components", - "version": "0.0.166", + "version": "0.0.171", "homepage": "https://github.com/nasa/terra-ui-components", "author": "NASA GES DISC ", "license": "MIT", diff --git a/packages/create-terra-ui-app/boilerplates/nextjs/framework.js b/packages/create-terra-ui-app/boilerplates/nextjs/framework.js index ff54d3f1..82dcf1f4 100644 --- a/packages/create-terra-ui-app/boilerplates/nextjs/framework.js +++ b/packages/create-terra-ui-app/boilerplates/nextjs/framework.js @@ -67,7 +67,7 @@ export async function create(nextTask, outputDir, boilerplatesDir, appName) { "import { setBasePath } from '@nasa-terra/components/dist/utilities/base-path.js'" // Create the setBasePath call with comments (with newline before it) - const setBasePathCall = `\n/**\n * Sets the base path to the Terra UI CDN\n *\n * If you'd rather host the assets locally, you should setup a build task to copy the assets locally and\n * set the base path to your local public folder\n * (see https://terra-ui.netlify.app/frameworks/react/#installation for more information)\n */\nsetBasePath('https://cdn.jsdelivr.net/npm/@nasa-terra/components@0.0.166/cdn/')` + const setBasePathCall = `\n/**\n * Sets the base path to the Terra UI CDN\n *\n * If you'd rather host the assets locally, you should setup a build task to copy the assets locally and\n * set the base path to your local public folder\n * (see https://terra-ui.netlify.app/frameworks/react/#installation for more information)\n */\nsetBasePath('https://cdn.jsdelivr.net/npm/@nasa-terra/components@0.0.171/cdn/')` // Reconstruct the file: CSS import at top, then existing content with setBasePath import and call inserted const newLines = [...lines] diff --git a/pyproject.toml b/pyproject.toml index 7d20ebf0..38147ea2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "hatchling.build" [project] name = "terra_ui_components" dependencies = ["anywidget>=0.9"] -version = "0.0.166" +version = "0.0.171" readme = "README.md" description = "NASA Terra UI Components Library" requires-python = ">=3.8" diff --git a/src/components/data-subsetter/notebooks/subsetter-notebook.ts b/src/components/data-subsetter/notebooks/subsetter-notebook.ts index 39cd1671..9a9c7350 100644 --- a/src/components/data-subsetter/notebooks/subsetter-notebook.ts +++ b/src/components/data-subsetter/notebooks/subsetter-notebook.ts @@ -21,7 +21,7 @@ export function getNotebook(host: TerraDataSubsetter) { { id: '2733501b-0de4-4067-8aff-864e1b4c76cb', cell_type: 'code', - source: '%pip install -q "terra_ui_components==0.0.166" "anywidget==0.9.15"', + source: '%pip install -q "terra_ui_components==0.0.171" "anywidget==0.9.15"', metadata: { trusted: true, }, diff --git a/src/components/plot-toolbar/notebooks/time-averaged-map-notebook.ts b/src/components/plot-toolbar/notebooks/time-averaged-map-notebook.ts index 8473f5db..1c6f48ee 100644 --- a/src/components/plot-toolbar/notebooks/time-averaged-map-notebook.ts +++ b/src/components/plot-toolbar/notebooks/time-averaged-map-notebook.ts @@ -21,7 +21,7 @@ export function getTimeAveragedMapNotebook(host: TerraPlotToolbar) { { id: '2733501b-0de4-4067-8aff-864e1b4c76cb', cell_type: 'code', - source: '%pip install -q "terra_ui_components==0.0.166" "anywidget==0.9.15" "pandas" "rasterio" "matplotlib"', + source: '%pip install -q "terra_ui_components==0.0.171" "anywidget==0.9.15" "pandas" "rasterio" "matplotlib"', metadata: { trusted: true, }, diff --git a/src/components/plot-toolbar/notebooks/time-series-notebook.ts b/src/components/plot-toolbar/notebooks/time-series-notebook.ts index 1a6520fb..d7d714a0 100644 --- a/src/components/plot-toolbar/notebooks/time-series-notebook.ts +++ b/src/components/plot-toolbar/notebooks/time-series-notebook.ts @@ -21,7 +21,7 @@ export function getTimeSeriesNotebook(host: TerraPlotToolbar) { { id: '2733501b-0de4-4067-8aff-864e1b4c76cb', cell_type: 'code', - source: '%pip install -q "terra_ui_components==0.0.166" "anywidget==0.9.15" "pandas"', + source: '%pip install -q "terra_ui_components==0.0.171" "anywidget==0.9.15" "pandas"', metadata: { trusted: true, }, diff --git a/src/components/plot-toolbar/plot-toolbar.component.ts b/src/components/plot-toolbar/plot-toolbar.component.ts index f775de7d..5a834a52 100644 --- a/src/components/plot-toolbar/plot-toolbar.component.ts +++ b/src/components/plot-toolbar/plot-toolbar.component.ts @@ -68,6 +68,11 @@ export default class TerraPlotToolbar extends TerraElement { @property({ type: Number }) opacity = 1 @property({ type: Boolean, attribute: 'show-citation' }) showCitation: boolean = false + /** + * Option hides the Jupyter notebook button in the plot toolbar. Option is set by parent component (time series, time average-map) if Jupyter notebook environemnt is detected. + */ + @property({ type: Boolean, attribute: 'show-jupyter' }) showJupyter: boolean = + true /** * if you include an application citation, it will be displayed in the citation panel alongside the dataset citation @@ -331,30 +336,32 @@ export default class TerraPlotToolbar extends TerraElement { font-size="1em" > + ${this.showJupyter + ? html` + + Open in Jupyter Notebook for + ${this.catalogVariable.dataFieldLongName} - - Open in Jupyter Notebook for - ${this.catalogVariable.dataFieldLongName} - - - - + + + ` + : nothing} ${this.dataType == 'geotiff' ? html` { const { status, code, message, context } = event.detail @@ -1194,6 +1218,7 @@ export default class TerraTimeAverageMap extends TerraElement { @show-opacity-value=${this.#handleOpacityChange} @show-color-map=${this.#handleColorMapChange} @show-check-box-toggle=${this.#handleCheckBoxToggle} + .showJupyter=${this.showJupyter} .pixelValue=${this.pixelValue} .pixelCoordinates=${this.pixelCoordinates} show-date-range diff --git a/src/components/time-series/time-series.component.ts b/src/components/time-series/time-series.component.ts index 157dd6f6..9faf2fe5 100644 --- a/src/components/time-series/time-series.component.ts +++ b/src/components/time-series/time-series.component.ts @@ -172,6 +172,11 @@ export default class TerraTimeSeries extends TerraElement { _fetchVariableTask = getFetchVariableTask(this) + /** + * Show or hide the Jupyter notebook button in the plot toolbar. + */ + showJupyter?: boolean; + connectedCallback(): void { super.connectedCallback() @@ -180,6 +185,10 @@ export default class TerraTimeSeries extends TerraElement { this.#handleQuotaError as EventListener ) + //* Detect if time series component is running in a Jupyter notebook. + if (this.showJupyter === undefined) { + this.showJupyter = !this.#isNotebookEnv(); + } //* instantiate the time series contoller maybe with a token this.#timeSeriesController = new TimeSeriesController(this) } @@ -223,6 +232,19 @@ export default class TerraTimeSeries extends TerraElement { ) } + #isNotebookEnv(): boolean { + const w = window as any; + + return ( + typeof w.Jupyter !== "undefined" || + typeof w.IPython !== "undefined" || + typeof w.google?.colab !== "undefined" || + typeof w.__jupyterlab !== "undefined" || + document.querySelector(".jp-Notebook") !== null || + document.querySelector(".jupyter-widgets") !== null + ); + } + #handleQuotaError = (event: CustomEvent) => { const { status, code, message, context } = event.detail @@ -307,6 +329,7 @@ export default class TerraTimeSeries extends TerraElement { .cacheKey=${this.#timeSeriesController.getCacheKey()} .variableEntryId=${this.variableEntryId} .showCitation=${this.showCitation} + .showJupyter=${this.showJupyter} .mobileView=${this.mobileView} .productLabel=${this.productLabel} > @@ -369,7 +392,6 @@ export default class TerraTimeSeries extends TerraElement { ` : ''} -