Skip to content

Commit 7cdfe50

Browse files
committed
Drag-and-drop cancel button
Before, the content being dragged was cut off by the edges of the scrolling box so that if you dragged the card or tree node up to the breadcrumbs the preview would vanish. This change uses `position: "fixed"` and z-index to ensure that the content being dragged is always rendered above everything else. However, by making the card/tree node position-fixed, it is removed from the flow of the page and the adjacent content moves up to take its place. This makes it harder to cancel the move operation as it is no longer possible to simply move the item back to where it came from. As such, this change adds an explicit cancel button: a floating-action button that appears whenever the drag-and-drop operation is in progress.
1 parent 8ab1f98 commit 7cdfe50

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

src/main/webapp/ui/src/eln/gallery/components/MainPanel.js

+46-2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,49 @@ import Link from "@mui/material/Link";
7070
import { Link as ReactRouterLink } from "react-router-dom";
7171
import useOneDimensionalRovingTabIndex from "../../../components/useOneDimensionalRovingTabIndex";
7272
import Box from "@mui/material/Box";
73+
import Fab from "@mui/material/Fab";
74+
75+
const DragCancelFab = () => {
76+
const dndContext = useDndContext();
77+
const dndInProgress = Boolean(dndContext.active);
78+
const { setNodeRef: setDropRef, isOver } = useDroppable({
79+
id: "cancel",
80+
disabled: false,
81+
data: null,
82+
});
83+
const dropStyle: { [string]: string | number } = isOver
84+
? {
85+
border: SELECTED_OR_FOCUS_BORDER,
86+
}
87+
: {
88+
border: "2px solid white",
89+
animation: "drop 2s linear infinite",
90+
};
91+
return (
92+
<>
93+
{dndInProgress && (
94+
<div
95+
style={{
96+
position: "fixed",
97+
right: "16px",
98+
bottom: "16px",
99+
}}
100+
>
101+
<Fab
102+
variant="extended"
103+
color="primary"
104+
ref={(node) => {
105+
setDropRef(node);
106+
}}
107+
style={dropStyle}
108+
>
109+
Cancel
110+
</Fab>
111+
</div>
112+
)}
113+
</>
114+
);
115+
};
73116

74117
const BreadcrumbLink = React.forwardRef<
75118
ElementConfig<typeof Link>,
@@ -668,8 +711,8 @@ const FileCard = styled(
668711
const dragStyle: { [string]: string | number } = transform
669712
? {
670713
transform: `translate3d(${transform.x}px, ${transform.y}px, 0) scale(1.1)`,
671-
zIndex: 1, // just needs to be rendered above Nodes later in the DOM
672-
position: "relative",
714+
zIndex: 1400, // Above the sidebar
715+
position: "fixed",
673716
boxShadow: `hsl(${COLOR.main.hue}deg 66% 10% / 20%) 0px 2px 16px 8px`,
674717
}
675718
: {};
@@ -1248,6 +1291,7 @@ function GalleryMainPanel({
12481291
refreshListing={refreshListing}
12491292
/>
12501293
</Slide>
1294+
<DragCancelFab />
12511295
</DndContext>
12521296
</DialogContent>
12531297
);

src/main/webapp/ui/src/eln/gallery/components/TreeView.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
import React, { type Node, type ComponentType } from "react";
44
import Fade from "@mui/material/Fade";
5-
import { COLOR, SELECTED_OR_FOCUS_BORDER, type GallerySection } from "../common";
5+
import {
6+
COLOR,
7+
SELECTED_OR_FOCUS_BORDER,
8+
type GallerySection,
9+
} from "../common";
610
import { styled } from "@mui/material/styles";
711
import Avatar from "@mui/material/Avatar";
812
import FileIcon from "@mui/icons-material/InsertDriveFile";
@@ -194,8 +198,8 @@ const CustomTreeItem = observer(
194198
const dragStyle: { [string]: string | number } = transform
195199
? {
196200
transform: `translate3d(${transform.x}px, ${transform.y}px, 0) scale(1.1)`,
197-
zIndex: 1, // just needs to be rendered above Nodes later in the DOM
198-
position: "relative",
201+
zIndex: 1400, // Above the sidebar
202+
position: "fixed",
199203
boxShadow: `hsl(${COLOR.main.hue}deg 66% 10% / 20%) 0px 2px 16px 8px`,
200204
maxWidth: "max-content",
201205
}
@@ -366,6 +370,7 @@ const TreeView = ({
366370
);
367371
return (
368372
<SimpleTreeView
373+
sx={{ maxWidth: `calc(100% - 200px)` }}
369374
expandedItems={expandedItems}
370375
onExpandedItemsChange={(_event, nodeIds) => {
371376
setExpandedItems(nodeIds);

0 commit comments

Comments
 (0)