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

Pin button in gridstack items #116

Merged
merged 12 commits into from
Aug 4, 2021
Merged

Pin button in gridstack items #116

merged 12 commits into from
Aug 4, 2021

Conversation

hbcarlos
Copy link
Member

@hbcarlos hbcarlos commented Mar 26, 2021

Solves #110

Seams that the locked option is not working perfectly. When an item is pinned we can't move/resize it either.

pinned

Questions:

  • How should we indicate the item is pinned or not? 🤔
  • Should we modify the metadata format to save this property on disk?

@hbcarlos hbcarlos marked this pull request as draft March 26, 2021 21:39
@hbcarlos
Copy link
Member Author

Metadata format changes with this PR, notebooks without attribute locked in metadata will be reset if they are open with the editor. This is also the reason why the test fails.

I'm not sure if this is the right way of attaching the toolbar:

The latest changes look like this:
locked

@fcollonval
Copy link
Contributor

Nice work!

I'm not sure if this is the right way of attaching the toolbar

I would suggest taking a approach similar to the file browser using a create function.

https://github.com/jupyterlab/jupyterlab/blob/98ccafa1e1b188e852fabb581d5d3f6aad38020e/packages/filebrowser/src/listing.ts#L216

https://github.com/jupyterlab/jupyterlab/blob/98ccafa1e1b188e852fabb581d5d3f6aad38020e/packages/filebrowser/src/listing.ts#L1761

It can be nice to set the grid item content as Panel rather than HTML node and add two children: the toolbar and the cell.

You can add a SingletonLayout on GridStackItem and add to it the panel.

@hbcarlos
Copy link
Member Author

hbcarlos commented May 4, 2021

Thanks for the advice!

I'm not sure how to implement the layout.

@hbcarlos
Copy link
Member Author

hbcarlos commented May 5, 2021

On my last PR, I created a model for items and added signals to communicate changes to the grid.

The idea would be to do a refactor to improve the items and reduce the number of signals for items in GridStackModel, creating a single signal to track changes on items changing the cellRemoved signal for something like this:

this._cellRemoved = new Signal<this, string>(this);

enum ItemState {
  CLOSED,
  LOCKED,
  UNLOCKED
}

interface ItemChange {
   item: GridStackItemModel;
   change: ItemState;
}
this._itemStateChanged = new Signal<this, ItemChange>(this);

What are your thoughts? Feedback is welcome!

Copy link
Contributor

@fcollonval fcollonval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pushing on this one @hbcarlos

It looks almost good. I have a small concern about the item model life cycle and its connection to the toolbar rendering.

Comment on lines 336 to 338
const model = new GridStackItemModel(options);
model.stateChanged.connect(this._itemChanged);
return new GridStackItemWidget(item, model);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can result in memory leak because you do not control the model life cycle.

It may be better to create the model within the widget and to trigger the model destruction when the widget is destroyed (and the signals need to be disconnected).

render(): JSX.Element {
const close = () => {
this._model.close();
this.update();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be more robust, I would trigger the update if the model state changes. So in case in the future the model changes outside of the toolbar, the toolbar will react.

Copy link
Contributor

@fcollonval fcollonval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went through the latest changes @hbcarlos
I have minor comments that should be easy to tackle.

<>
{this._model.isLocked ? (
<div className="pin" onClick={() => this._model.unlock()}>
<unPinIcon.react height="16px" width="16px" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should avoid hard coding styles (bad practice). Instead you should add a common class to all buttons and set the svg size using that class and CSS rules.

return (
<>
{this._model.isLocked ? (
<div className="pin" onClick={() => this._model.unlock()}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use meaningful html tag; in this case button instead of div.

@hbcarlos
Copy link
Member Author

Hey, thanks for the review! I'll change today.

@hbcarlos hbcarlos marked this pull request as ready for review July 29, 2021 15:37
Copy link
Contributor

@fcollonval fcollonval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @hbcarlos LGTM

@hbcarlos hbcarlos merged commit 7356b28 into master Aug 4, 2021
@hbcarlos hbcarlos deleted the pin_button branch August 4, 2021 14:35
@hbcarlos hbcarlos added enhancement New feature or request jupyterlab-extension The Voila Gridstack extension for JupyterLab labels Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request jupyterlab-extension The Voila Gridstack extension for JupyterLab
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants