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

Emit Single 'move' Event Instead of Separate 'add' and 'remove' Events When Moving Cells in JupyterLab #16648

Open
chanhee-park opened this issue Aug 7, 2024 · 0 comments
Labels

Comments

@chanhee-park
Copy link

Description

When moving a cell in JupyterLab, the system emits separate add and remove events sequentially instead of a single move event. According to the defined specification, it should emit a move event to better track cell movements.

https://jupyterlab.readthedocs.io/en/4.2.x/api/types/observables.IObservableList.ChangeType.html

Reproduce

  1. Create and activate the JupyterLab extension using the code provided below.
  2. Open a notebook in JupyterLab.
  3. Add some cells.
  4. Move a cell to a different position within the notebook.
  5. Check the console log for emitted events and observe the add and remove events.
// Extension code:
import { JupyterFrontEnd, JupyterFrontEndPlugin } from '@jupyterlab/application';
import { INotebookTracker } from '@jupyterlab/notebook';

async function activate(_app: JupyterFrontEnd, notebookTracker: INotebookTracker): Promise<void> {
  notebookTracker.currentChanged.connect((_, notebookPanel) => {
    if (notebookPanel?.model?.cells) {
      notebookPanel.model.cells.changed.connect((cells, changed) => {
        console.log('changed.type:', changed.type);
      });
    }
  });
}

const plugin: JupyterFrontEndPlugin<any> = {
  id: 'cell-tracker',
  requires: [INotebookTracker],
  autoStart: true,
  activate: activate,
};

export default [plugin] as JupyterFrontEndPlugin<any>[];

Expected behavior

When a cell is moved, a single move event should be emitted instead of separate add and remove events. The move event should have the following structure:

{
  type: 'move',
  oldIndex: fromIndex,
  newIndex: toIndex,
  oldValues: values,
  newValues: values
}

Context

I am developing a JupyterLab extension that tracks cell changes. The extension works as expected for cell additions and modifications, but when a cell is deleted, the changed.oldValues log displays [undefined] instead of the cell's previous values.

Operating System and version: macOS Ventura 13.6.7
Browser and version: Google Chrome 127.0.6533.88
JupyterLab version: 4.2.3

Troubleshoot Output
[notice] A new release of pip is available: 24.0 -> 24.2
[notice] To update, run: pip install --upgrade pip
$PATH:
        /Users/chanheepark/.venv/mrx-link-develop/bin
        /Users/chanheepark/.nvm/versions/node/v18.13.0/bin
        /Library/Frameworks/Python.framework/Versions/3.8/bin
        /opt/homebrew/bin
        /opt/homebrew/sbin
        /Library/Frameworks/Python.framework/Versions/3.10/bin
        /Library/Frameworks/Python.framework/Versions/3.11/bin
        /usr/local/bin
        /System/Cryptexes/App/usr/bin
        /usr/bin
        /bin
        /usr/sbin
        /sbin
        /Library/Apple/usr/bin
        /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin
        /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin
        /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
        /Applications/iTerm.app/Contents/Resources/utilities
sys.path:
/Users/chanheepark/.venv/mrx-link-develop/bin
/Library/Frameworks/Python.framework/Versions/3.10/lib/python310.zip
/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10
/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/lib-dynload
/Users/chanheepark/.venv/mrx-link-develop/lib/python3.10/site-packages
/Users/chanheepark/dev/link/mrx-link-git
/Users/chanheepark/dev/link/makina-link
/Users/chanheepark/dev/link/mrx-link-core
sys.executable:

/Users/chanheepark/.venv/mrx-link-develop/bin/python3

sys.version:

3.10.11 (v3.10.11:7d4cc5aa85, Apr 4 2023, 19:05:19) [Clang 13.0.0 (clang-1300.0.29.30)]

platform.platform():

macOS-13.6.7-arm64-arm-64bit

which -a jupyter:

/Users/chanheepark/.venv/mrx-link-develop/bin/jupyter

/Library/Frameworks/Python.framework/Versions/3.8/bin/jupyter

/opt/homebrew/bin/jupyter

/Library/Frameworks/Python.framework/Versions/3.10/bin/jupyter

/Library/Frameworks/Python.framework/Versions/3.11/bin/jupyter

pip list:

Package Version Editable project location


absl-py 1.4.0

aiofiles 22.1.0

aiosqlite 0.20.0

alembic 1.11.2

amqp 5.1.1

annotated-types 0.5.0

anyio 3.7.1

appnope 0.1.3

argon2-cffi 21.3.0

argon2-cffi-bindings 21.2.0

arrow 1.3.0

astor 0.8.1

astroid 3.0.1

asttokens 2.2.1

async-lru 2.0.4

async-timeout 4.0.2

attrs 23.1.0

awacs 2.4.0

aws-sam-translator 1.80.0

Babel 2.12.1

backcall 0.2.0

beautifulsoup4 4.12.2

billiard 4.1.0

black 22.12.0

bleach 6.0.0

blinker 1.7.0

boto3 1.29.3

botocore 1.32.3

bracex 2.4

build 1.2.1

cachetools 5.3.1

celery 5.3.1

certifi 2023.7.22

cffi 1.15.1

cfgv 3.4.0

cfn-flip 1.3.0

cfn-lint 0.83.3

charset-normalizer 3.2.0

cli-exit-tools 1.2.6

click 8.1.6

click-didyoumean 0.3.0

click-plugins 1.1.1

click-repl 0.3.0

cloudpickle 2.2.1

cmaes 0.10.0

colorama 0.4.6

coloredlogs 15.0

colorlog 6.7.0

comm 0.1.4

contourpy 1.1.0

coverage 7.3.2

cryptography 41.0.5

cycler 0.11.0

Cython 3.0.10

databricks-cli 0.18.0

debugpy 1.6.7

decorator 5.1.1

defusedxml 0.7.1

Deprecated 1.2.14

deprecation 2.1.0

dill 0.3.7

distlib 0.3.7

dnspython 2.4.1

docker 6.1.3

docstring-parser 0.15

entrypoints 0.4

et-xmlfile 1.1.0

eventlet 0.33.3

exceptiongroup 1.1.2

executing 1.2.0

fastjsonschema 2.18.0

filelock 3.12.2

fire 0.5.0

flake8 6.1.0

Flask 2.3.3

fonttools 4.42.0

formic2 1.0.3

fqdn 1.5.1

git-lfs 1.6

gitdb 4.0.10

GitPython 3.1.32

google-api-core 2.10.1

google-api-python-client 1.12.11

google-auth 2.22.0

google-auth-httplib2 0.1.0

google-cloud-core 2.3.3

google-cloud-storage 2.10.0

google-crc32c 1.5.0

google-resumable-media 2.5.0

googleapis-common-protos 1.56.4

graphviz 0.20.1

greenlet 2.0.2

gunicorn 20.1.0

h11 0.14.0

httpcore 1.0.5

httplib2 0.22.0

httpx 0.27.0

humanfriendly 10.0

identify 2.5.26

idna 3.4

igittigitt 2.1.4

importlib-metadata 6.8.0

iniconfig 2.0.0

install 1.3.5

ipykernel 6.25.1

ipynbname 2021.3.2

ipython 8.14.0

ipython-genutils 0.2.0

isoduration 20.11.0

isort 5.12.0

itsdangerous 2.1.2

jedi 0.19.0

Jinja2 3.1.2

jmespath 1.0.1

joblib 1.3.1

jschema-to-python 1.2.3

json5 0.9.14

jsondiff 2.0.0

jsonpatch 1.33

jsonpickle 3.0.2

jsonpointer 2.4

jsonschema 4.19.0

jsonschema-specifications 2023.7.1

junit-xml 1.9

jupyter_client 7.4.9

jupyter_core 5.7.2

jupyter-events 0.10.0

jupyter-lsp 2.2.5

jupyter_packaging 0.12.3

jupyter_server 2.14.0

jupyter_server_fileid 0.9.2

jupyter-server-mathjax 0.2.6

jupyter_server_terminals 0.5.3

jupyter_server_ydoc 0.6.1

jupyter-ydoc 0.2.5

jupyterlab 4.2.3

jupyterlab-pygments 0.2.2

jupyterlab_server 2.27.1

kfp 1.8.22

kfp-pipeline-spec 0.1.16

kfp-server-api 1.8.5

kiwisolver 1.4.4

kombu 5.3.1

kubernetes 25.3.0

lark 1.1.8

lib-detect-testenv 2.0.8

Mako 1.2.4

Markdown 3.5.1

MarkupSafe 2.1.3

matplotlib 3.7.2

matplotlib-inline 0.1.6

mccabe 0.7.0

mistune 3.0.1

mlflow 2.4.1

moto 3.0.5

mpmath 1.3.0

mrx-link 1.5.0.dev13 /Users/chanheepark/dev/link/makina-link

mrx-link-core 1.5.0.dev6 /Users/chanheepark/dev/link/mrx-link-core

mrx-link-git 1.1.1.dev1 /Users/chanheepark/dev/link/mrx-link-git

msgpack 1.0.5

multipledispatch 0.6.0

mypy 1.8.0

mypy-extensions 1.0.0

nbclassic 0.5.6

nbclient 0.8.0

nbconvert 7.7.3

nbdime 3.1.1

nbformat 5.9.2

nest-asyncio 1.5.7

networkx 3.1

nodeenv 1.8.0

notebook 4.2.3

notebook_shim 0.2.3

numpy 1.23.5

oauthlib 3.2.2

openpyxl 3.1.2

optuna 3.3.0

overrides 7.4.0

packaging 23.1

pandas 2.0.3

pandocfilters 1.5.0

parso 0.8.3

pathspec 0.11.2

pbr 6.0.0

pexpect 4.8.0

pickleshare 0.7.5

Pillow 10.0.0

pip 24.0

pipenv 2022.1.8

platformdirs 3.10.0

plotly 5.15.0

pluggy 1.3.0

pre-commit 3.7.1

prometheus-client 0.17.1

prompt-toolkit 3.0.39

protobuf 3.20.1

psutil 5.9.5

ptyprocess 0.7.0

pure-eval 0.2.2

pyarrow 12.0.1

pyasn1 0.5.0

pyasn1-modules 0.3.0

pycodestyle 2.11.1

pycparser 2.21

pycryptodome 3.18.0

pydantic 1.10.12

pydantic_core 2.4.0

pyflakes 3.1.0

Pygments 2.16.1

pyhcl 0.4.5

PyJWT 2.8.0

pylint 3.0.2

pyOpenSSL 23.3.0

pyparsing 3.0.9

pyproject_hooks 1.0.0

pytest 7.4.3

pytest-cov 4.1.0

pytest-env 0.8.2

pytest-jupyter 0.10.1

pytest-mock 3.12.0

pytest-tornasync 0.6.0.post2

python-dateutil 2.8.2

python-dotenv 1.0.0

python-hcl2 4.3.2

python-json-logger 2.0.7

python-memcached 1.59

pytz 2023.3

PyYAML 6.0.1

pyzmq 25.1.0

querystring-parser 1.2.4

redis 4.6.0

referencing 0.30.2

regex 2023.10.3

requests 2.31.0

requests-oauthlib 1.3.1

requests-toolbelt 0.10.1

responses 0.24.1

rfc3339-validator 0.1.4

rfc3986-validator 0.1.1

rpds-py 0.9.2

rsa 4.9

runway 0.14.1

s3transfer 0.7.0

sarif-om 1.0.4

scikit-learn 1.3.0

scipy 1.11.1

Send2Trash 1.8.2

setuptools 63.4.3

six 1.16.0

smmap 5.0.0

sniffio 1.3.0

soupsieve 2.4.1

SQLAlchemy 1.4.49

sqlparse 0.4.4

stack-data 0.6.2

strip-hints 0.1.10

sympy 1.12

tabulate 0.9.0

tenacity 8.2.2

termcolor 2.3.0

terminado 0.17.1

testfixtures 7.2.2

threadpoolctl 3.2.0

tinycss2 1.2.1

tomli 2.0.1

tomlkit 0.12.1

tornado 6.3.2

tqdm 4.65.0

traitlets 5.9.0

troposphere 4.5.2

typer 0.9.0

types-python-dateutil 2.9.0.20240316

typing_extensions 4.7.1

tzdata 2023.3

uri-template 1.3.0

uritemplate 3.0.1

urllib3 1.26.16

vine 5.0.0

virtualenv 20.24.3

virtualenv-clone 0.5.7

wcmatch 8.5

wcwidth 0.2.6

webcolors 1.13

webencodings 0.5.1

websocket-client 1.8.0

websockets 12.0

Werkzeug 3.0.1

wheel 0.43.0

wrapt 1.15.0

xmltodict 0.13.0

y-py 0.6.2

yamllint 1.33.0

ypy-websocket 0.8.4

zipp 3.17.0

Command Line Output
Paste the output from your command line running `jupyter lab` here, use `--debug` if possible.
Browser Output
Paste the output from your browser Javascript console here, if applicable.
@jupyterlab-probot jupyterlab-probot bot added the status:Needs Triage Applied to new issues that need triage label Aug 7, 2024
@chanhee-park chanhee-park changed the title Emit Single Move Event Instead of Separate Add and Remove Events When Moving Cells in JupyterLab Emit Single 'move' Event Instead of Separate 'add' and Remove Events When Moving Cells in JupyterLab Aug 7, 2024
@chanhee-park chanhee-park changed the title Emit Single 'move' Event Instead of Separate 'add' and Remove Events When Moving Cells in JupyterLab Emit Single 'move' Event Instead of Separate 'add' and 'remove' Events When Moving Cells in JupyterLab Aug 7, 2024
@JasonWeill JasonWeill added enhancement bug and removed bug status:Needs Triage Applied to new issues that need triage enhancement labels Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants