@jupyterlab/filebrowser 4.5.0-alpha.0 → 4.5.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/upload.ts CHANGED
@@ -9,6 +9,8 @@ import {
9
9
  } from '@jupyterlab/translation';
10
10
  import { fileUploadIcon, ToolbarButton } from '@jupyterlab/ui-components';
11
11
  import { FileBrowserModel } from './model';
12
+ import { Contents } from '@jupyterlab/services';
13
+ import { ISignal, Signal } from '@lumino/signaling';
12
14
 
13
15
  /**
14
16
  * A widget which provides an upload button.
@@ -24,7 +26,8 @@ export class Uploader extends ToolbarButton {
24
26
  onClick: () => {
25
27
  this._input.click();
26
28
  },
27
- tooltip: Private.translateToolTip(options.translator)
29
+ tooltip: Private.translateToolTip(options.translator),
30
+ enabled: options.model.allowFileUploads
28
31
  });
29
32
  this.fileBrowserModel = options.model;
30
33
  this.translator = options.translator || nullTranslator;
@@ -34,6 +37,13 @@ export class Uploader extends ToolbarButton {
34
37
  this.addClass('jp-id-upload');
35
38
  }
36
39
 
40
+ /**
41
+ * A signal emitted with file info when a batch of upload completes.
42
+ */
43
+ get filesUploaded(): ISignal<this, Contents.IModel[]> {
44
+ return this._filesUploaded;
45
+ }
46
+
37
47
  /**
38
48
  * The underlying file browser fileBrowserModel for the widget.
39
49
  *
@@ -47,12 +57,17 @@ export class Uploader extends ToolbarButton {
47
57
  private _onInputChanged = () => {
48
58
  const files = Array.prototype.slice.call(this._input.files) as File[];
49
59
  const pending = files.map(file => this.fileBrowserModel.upload(file));
50
- void Promise.all(pending).catch(error => {
51
- void showErrorMessage(
52
- this._trans._p('showErrorMessage', 'Upload Error'),
53
- error
54
- );
55
- });
60
+ void Promise.all(pending)
61
+ .then(models => {
62
+ // emit the batch
63
+ this._filesUploaded.emit(models);
64
+ })
65
+ .catch(error => {
66
+ void showErrorMessage(
67
+ this._trans._p('showErrorMessage', 'Upload Error'),
68
+ error
69
+ );
70
+ });
56
71
  };
57
72
 
58
73
  /**
@@ -67,6 +82,7 @@ export class Uploader extends ToolbarButton {
67
82
  protected translator: ITranslator;
68
83
  private _trans: TranslationBundle;
69
84
  private _input = Private.createUploadInput();
85
+ private _filesUploaded = new Signal<this, Contents.IModel[]>(this);
70
86
  }
71
87
 
72
88
  /**
@@ -212,7 +212,7 @@ export namespace FileUploadStatus {
212
212
  this._items,
213
213
  val => val.path === uploads.newValue.path
214
214
  );
215
- }
215
+ } else return;
216
216
 
217
217
  this.stateChanged.emit(void 0);
218
218
  };