@@ -2,7 +2,7 @@ import { NotebookPanel } from '@jupyterlab/notebook';
22
33import { CodeCell , MarkdownCell , Cell } from '@jupyterlab/cells' ;
44
5- import { filter , map , toArray , ArrayExt } from '@lumino/algorithm' ;
5+ import { map , toArray , each } from '@lumino/algorithm' ;
66
77import * as React from 'react' ;
88
@@ -29,9 +29,15 @@ import { DashboardLayout } from './layout';
2929
3030import { DashboardWidget } from './widget' ;
3131
32- import { Widgetstore } from './widgetstore' ;
32+ import { WidgetPosition , Widgetstore } from './widgetstore' ;
3333
34- import { addCellId , addNotebookId , getNotebookById , getCellId , updateMetadata } from './utils' ;
34+ import {
35+ addCellId ,
36+ addNotebookId ,
37+ getNotebookById ,
38+ getCellId ,
39+ updateMetadata ,
40+ } from './utils' ;
3541
3642import {
3743 DocumentWidget ,
@@ -46,17 +52,19 @@ import { CommandIDs } from './commands';
4652
4753import { HTMLSelect } from '@jupyterlab/ui-components' ;
4854
55+ import { UUID } from '@lumino/coreutils' ;
56+
4957// HTML element classes
5058
51- const DASHBOARD_CLASS = 'pr-JupyterDashboard' ;
59+ export const DASHBOARD_CLASS = 'pr-JupyterDashboard' ;
5260
53- const DROP_TARGET_CLASS = 'pr-DropTarget' ;
61+ export const DROP_TARGET_CLASS = 'pr-DropTarget' ;
5462
55- const TOOLBAR_MODE_SWITCHER_CLASS = 'pr-ToolbarModeSwitcher' ;
63+ export const TOOLBAR_MODE_SWITCHER_CLASS = 'pr-ToolbarModeSwitcher' ;
5664
57- const TOOLBAR_SELECT_CLASS = 'pr-ToolbarSelector' ;
65+ export const TOOLBAR_SELECT_CLASS = 'pr-ToolbarSelector' ;
5866
59- const TOOLBAR_CLASS = 'pr-DashboardToolbar' ;
67+ export const TOOLBAR_CLASS = 'pr-DashboardToolbar' ;
6068
6169export const IDashboardTracker = new Token < IDashboardTracker > (
6270 'jupyterlab-interactive-dashboard-editor'
@@ -73,6 +81,8 @@ export class Dashboard extends Widget {
7381 constructor ( options : Dashboard . IOptions ) {
7482 super ( options ) ;
7583
84+ this . id = UUID . uuid4 ( ) ;
85+
7686 const { outputTracker, model } = options ;
7787 this . _model = model ;
7888 if ( options . context !== undefined ) {
@@ -243,7 +253,7 @@ export class Dashboard extends Widget {
243253
244254 private _evtScroll ( _event : Event ) : void {
245255 const model = this . model ;
246-
256+
247257 if ( model . scrollMode !== 'infinite' ) {
248258 return ;
249259 }
@@ -354,51 +364,39 @@ export class Dashboard extends Widget {
354364 return ( this . layout as DashboardLayout ) . createWidget ( info , fit ) ;
355365 }
356366
357- saveToNotebookMetadata ( ) {
367+ saveToNotebookMetadata ( ) : void {
358368 // Get a list of all notebookIds used in the dashboard.
359- const widgets = toArray (
360- filter (
361- this . model . widgetstore . getWidgets ( ) ,
362- ( widget ) => widget . widgetId && ! widget . removed
363- )
364- ) ;
369+ const widgets = toArray ( this . model . widgetstore . getWidgets ( ) ) ;
365370
366- const notebookIds = toArray (
367- map (
368- widgets ,
369- ( record ) => record . notebookId
370- )
371- ) ;
371+ const notebookIds = toArray ( map ( widgets , ( record ) => record . notebookId ) ) ;
372372
373373 if ( ! notebookIds . every ( ( v ) => v === notebookIds [ 0 ] ) ) {
374- console . log ( notebookIds ) ;
375- throw new Error ( 'Only single notebook dashboards can be saved to metadata.' ) ;
374+ throw new Error (
375+ 'Only single notebook dashboards can be saved to metadata.'
376+ ) ;
376377 }
377378
378379 const notebookId = notebookIds [ 0 ] ;
379380 const notebookTracker = this . model . notebookTracker ;
380381 const notebook = getNotebookById ( notebookId , notebookTracker ) ;
382+
381383 updateMetadata ( notebook , { hasDashboard : true } ) ;
382384
383385 const cells = notebook . content . widgets ;
384386
385- for ( let widget of widgets ) {
386- let { pos, cellId } = widget ;
387-
388- let cell = ArrayExt . findFirstValue (
389- cells ,
390- ( cell ) => getCellId ( cell ) === cellId
391- ) ;
392-
393- // let output = find(
394- // this.layout,
395- // (widget) => widget.id === widgetId
396- // );
387+ const widgetMap = new Map < string , WidgetPosition > (
388+ widgets . map ( ( widget ) => [ widget . cellId , widget . pos ] )
389+ ) ;
397390
398- if ( cell !== undefined ) {
399- updateMetadata ( cell , { pos } ) ;
391+ each ( cells , ( cell ) => {
392+ const cellId = getCellId ( cell ) ;
393+ const pos = widgetMap . get ( cellId ) ;
394+ if ( pos != null ) {
395+ updateMetadata ( cell , { pos, hidden : false } ) ;
396+ } else {
397+ updateMetadata ( cell , { hidden : true } ) ;
400398 }
401- }
399+ } ) ;
402400
403401 notebook . context . save ( ) ;
404402 }
@@ -452,18 +450,6 @@ export namespace Dashboard {
452450 }
453451}
454452
455- // export class SingleNotebookDashboard extends MainAreaWidget {
456- // constructor(options: SingleNotebookDashboard.IOptions) {
457-
458- // }
459- // }
460-
461- // export namespace SingleNotebookDashboard {
462- // export interface IOptions {
463-
464- // }
465- // }
466-
467453export class DashboardDocument extends DocumentWidget < Dashboard > {
468454 constructor ( options : DashboardDocument . IOptions ) {
469455 let { content, reveal } = options ;
@@ -483,7 +469,7 @@ export class DashboardDocument extends DocumentWidget<Dashboard> {
483469 this . toolbar . addClass ( TOOLBAR_CLASS ) ;
484470
485471 const commands = commandRegistry ;
486- const { save, undo, redo, cut, copy, paste, runOutput } = CommandIDs ;
472+ const { save, undo, redo, cut, copy, paste } = CommandIDs ;
487473
488474 const args = { toolbar : true , dashboardId : content . id } ;
489475
@@ -505,15 +491,13 @@ export class DashboardDocument extends DocumentWidget<Dashboard> {
505491 paste ,
506492 'Paste outputs from the clipboard'
507493 ) ;
508- const runButton = makeToolbarButton ( runOutput , 'Run the selected outputs' ) ;
509494
510495 this . toolbar . addItem ( save , saveButton ) ;
511496 this . toolbar . addItem ( undo , undoButton ) ;
512497 this . toolbar . addItem ( redo , redoButton ) ;
513498 this . toolbar . addItem ( cut , cutButton ) ;
514499 this . toolbar . addItem ( copy , copyButton ) ;
515500 this . toolbar . addItem ( paste , pasteButton ) ;
516- this . toolbar . addItem ( runOutput , runButton ) ;
517501 this . toolbar . addItem ( 'spacer' , Toolbar . createSpacerItem ( ) ) ;
518502 this . toolbar . addItem (
519503 'switchMode' ,
@@ -589,9 +573,9 @@ export namespace DashboardDocument {
589573 value = { value }
590574 aria-label = { 'Mode' }
591575 >
592- < option value = ' present' > Present</ option >
576+ < option value = " present" > Present</ option >
593577 { /* <option value="free-edit">Free Layout</option> */ }
594- < option value = ' grid-edit' > Edit</ option >
578+ < option value = " grid-edit" > Edit</ option >
595579 </ HTMLSelect >
596580 ) ;
597581 }
0 commit comments