Skip to content

Commit

Permalink
More pin reordering improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tlrobinson committed Jun 19, 2018
1 parent 6db3202 commit 0d99193
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion frontend/src/metabase/components/CollectionLanding.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ class DefaultLanding extends React.Component {
pinIndex={
pinned[pinned.length - 1].collection_position + 1
}
noDrop
marginLeft={8}
marginRight={8}
noBorder
>
<Grid>
{pinned.map((item, index) => (
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/metabase/containers/dnd/DropArea.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { normal } from "metabase/lib/colors";
const DropTargetBackgroundAndBorder = ({
highlighted,
hovered,
noBorder = false,
noDrop = false,
margin = 0,
marginLeft = margin,
marginRight = margin,
Expand All @@ -25,7 +25,7 @@ const DropTargetBackgroundAndBorder = ({
zIndex: -1,
boxSizing: "border-box",
border: "2px solid transparent",
borderColor: hovered & !noBorder ? normal.blue : "transparent",
borderColor: hovered & !noDrop ? normal.blue : "transparent",
}}
/>
);
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/metabase/containers/dnd/PinDropTarget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const PinDropTarget = DropTarget(
PinnableDragTypes,
{
drop(props, monitor, component) {
return { pinIndex: props.pinIndex };
if (!props.noDrop) {
return { pinIndex: props.pinIndex };
}
},
canDrop(props, monitor) {
const { item } = monitor.getItem();
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/metabase/containers/dnd/PinPositionDropTarget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ const PIN_DROP_TARGET_INDICATOR_WIDTH = 3;
PinnableDragTypes,
{
drop(props, monitor, component) {
const { item } = monitor.getItem();
// no need to move to the same position
if (item.collection_position == props.pinIndex) {
return;
}
// no already pinned, so add it at the dropped position
if (item.collection_position == null) {
return { pinIndex: props.pinIndex };
}
// being moved to a later position, which will cause everything to be shifted down, so subtract one
if (item.collection_position < props.pinIndex) {
return { pinIndex: props.pinIndex - 1 };
}
// being moved to an earlier position, no need to account for shift
return { pinIndex: props.pinIndex };
},
},
Expand Down

0 comments on commit 0d99193

Please sign in to comment.