jupyterlab / extension-examples

JupyterLab Extensions by Examples
BSD 3-Clause "New" or "Revised" License
453 stars 167 forks source link

Add an example about dialogs #252

Open jtpio opened 11 months ago

jtpio commented 11 months ago

It would be nice to have an example showing how to use dialogs and / or all the different types of dialogs available.

Some examples already use dialogs, for example:

https://github.com/jupyterlab/extension-examples/blob/36a65956d5385e2a4d87873b5eafe7336126e4da/context-menu/src/index.ts#L25-L29

But it could be useful to have a dedicated example so it's easier to find and reference elsewhere.

jtpio commented 11 months ago

Another question that is sometimes asked is how to dismiss a dialog automatically.

For JupyterLab 3 the following snippet seems to be doing the trick (for dismissing the first dialog only):

const hideFirstDialog = async (_: unknown, w: Dialog<unknown>) => {
  Dialog.tracker.widgetAdded.disconnect(hideFirstDialog);
  requestAnimationFrame(() => w.dispose());
};
Dialog.tracker.widgetAdded.connect(hideFirstDialog);

In JupyterLab 4 there is now a ready promise, which could likely be used instead of the requestAnimationFrame above:

https://github.com/jupyterlab/jupyterlab/blob/0f178d3094f07f4474dc171a9493effbf0b38e90/packages/apputils/src/dialog.tsx#L147-L152

krassowski commented 11 months ago

Alternatively, we could improve the documentation which already has a few examples: https://jupyterlab.readthedocs.io/en/latest/extension/ui_helpers.html