-
Notifications
You must be signed in to change notification settings - Fork 28
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
SceneCSSGridLayout: Add support for dragging and dropping panels #993
base: main
Are you sure you want to change the base?
Conversation
parentState?: SceneCSSGridItemPlacement; | ||
} | ||
|
||
export class SceneCSSGridItem extends SceneObjectBase<SceneCSSGridItemState> { |
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 understand doing pocs here (if you need to make changes to VizPanelRenderer esp),
just be aware we have a special class in core for this CSS grid items, https://github.com/grafana/grafana/blob/main/public/app/features/dashboard-scene/scene/layout-responsive-grid/ResponsiveGridItem.tsx#L13
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.
Oh this wasn't a POC, I just factored it out from SceneCSSGridLayout
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 understand, just know we are not using it dashboards.
I think a challenge with this work is what logic needs live in scenes vs the core repo implementation (and the ResponsiveGridLayoutManager)
@torkelo The css grid demo should work now - made some fixes. |
@kaydelaney works really well! I am not sure it helps or not but might be useful to go directly from this and explore how moving a panel between layouts would work (as as an early exploratory poc/test, to understand the problem etc) . |
and by "between layouts" i mean between two separate CSS grids in this case (moving between CSS grid and the default grid is a separate problem, one we might have to solve as well) |
const styles = useStyles2(getStyles, model.state); | ||
const containerRef = useRef<HTMLDivElement>(null); | ||
const oldDropZone = useRef<DropZone>(); | ||
const { activeItem, activeLayout, dropZone } = model.dragManager.useState(); |
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.
const { activeItem, activeLayout, dropZone } = model.dragManager.useState(); | |
const { activeItem, activeLayout, dropZone } = model.dragManager?.useState() ?? {}; |
I think we need something like this for cases where the drag manager isn't set. For example if I go to the demos listing page here it crashes because it expects the drag manager to exist
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're right! Sorry, I was so focused on the demo app that I'd forgotten to check it didn't break other things. Will fix this asap
dropZone?: DropZone; | ||
} | ||
|
||
export class DragManager extends SceneObjectBase<DragManagerState> { |
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 think we should move as much as we can of the drag and drop stuff to core, (potentially the have a separate CSS grid layout here), might move it back here if there is need for this in other scene apps but think we can iterate on it faster if it's in core, and we already have a specific CSSGridItem there
Some additional context to hopefully help with reviewing: My main goal with the design was to have as much of the DOM and event-level stuff in one place as possible, so we don’t have to reimplement the logic for a whole bunch of different layouts. Right now the code for @mdvictor Let me know if any additional details would be helpful! |
In preparation for moving this code over to the main grafana repo, I've created a much smaller version of this PR that just adds the plumbing needed for when things are moved. #1028 |
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.
Looks good, but getting the following errors and warnings in demo app when dragging:
SceneObject already has a parent set that is different from the new parent.
Uncaught TypeError: Cannot read properties of undefined (reading 'right')
at DragManager.onDrag (DragManager.js:110:62) ...
const dragManager = findDragManager(this); | ||
if (dragManager) { | ||
this.dragManager = dragManager; | ||
this.dragManager.registerLayout(this); | ||
} |
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.
getting typescript errors here. Might need a type cast in findDragManager()
return
Type 'SceneObject<SceneObjectState> | SceneStatelessBehavior<any>' is not assignable to type 'DragManager | undefined'.
Grafana repo PR is up grafana/grafana#99386 |
There's a lot of code here but the gist of it is enables support for dragging and dropping panels in the responsive grid layout (when paired with the PR linked below)
Let me know if there are any questions or parts of the code that could use further explanation.
Related: grafana/grafana#97495