-
Notifications
You must be signed in to change notification settings - Fork 49
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
Conversation
Metadata format changes with this PR, notebooks without attribute I'm not sure if this is the right way of attaching the toolbar:
|
Nice work!
I would suggest taking a approach similar to the file browser using a It can be nice to set the grid item content as You can add a |
Thanks for the advice! I'm not sure how to implement the layout. |
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
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! |
There was a problem hiding this 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.
const model = new GridStackItemModel(options); | ||
model.stateChanged.connect(this._itemChanged); | ||
return new GridStackItemWidget(item, model); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this 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" /> |
There was a problem hiding this comment.
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()}> |
There was a problem hiding this comment.
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
.
Hey, thanks for the review! I'll change today. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @hbcarlos LGTM
Solves #110
Seams that the
locked
option is not working perfectly. When an item is pinned we can't move/resize it either.Questions: