-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1610 from hanelka/my-jira-tickets
Add My Jira tickets homepage component
- Loading branch information
Showing
16 changed files
with
680 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@roadiehq/backstage-plugin-jira': minor | ||
--- | ||
|
||
Add My Jira Tickets Home Page component |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
plugins/frontend/backstage-plugin-jira/src/components/DraggableCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import React, { ReactNode, useRef } from 'react'; | ||
import { useDrag, useDrop, DragSourceMonitor } from 'react-dnd'; | ||
|
||
const ItemType = 'CARD'; | ||
|
||
interface DraggableCardProps { | ||
id: string; | ||
index: number; | ||
moveCard: (dragIndex: number, hoverIndex: number) => void; | ||
children: ReactNode; | ||
} | ||
|
||
interface DragItem { | ||
id: string; | ||
index: number; | ||
} | ||
|
||
const DraggableCard = ({ | ||
id, | ||
index, | ||
moveCard, | ||
children, | ||
}: DraggableCardProps) => { | ||
const ref = useRef<HTMLDivElement>(null); | ||
|
||
const [, drop] = useDrop<DragItem>({ | ||
accept: ItemType, | ||
hover(item, monitor) { | ||
if (!ref.current) { | ||
return; | ||
} | ||
const dragIndex = item.index; | ||
const hoverIndex = index; | ||
|
||
if (dragIndex === hoverIndex) { | ||
return; | ||
} | ||
|
||
const hoverBoundingRect = ref.current?.getBoundingClientRect(); | ||
const hoverMiddleY = | ||
(hoverBoundingRect.bottom - hoverBoundingRect.top) / 2; | ||
const clientOffset = monitor.getClientOffset(); | ||
const hoverClientY = clientOffset!.y - hoverBoundingRect.top; | ||
|
||
if (dragIndex < hoverIndex && hoverClientY < hoverMiddleY) { | ||
return; | ||
} | ||
|
||
if (dragIndex > hoverIndex && hoverClientY > hoverMiddleY) { | ||
return; | ||
} | ||
|
||
moveCard(dragIndex, hoverIndex); | ||
item.index = hoverIndex; | ||
}, | ||
}); | ||
|
||
const [{ isDragging }, drag] = useDrag({ | ||
type: ItemType, | ||
item: { id, index }, | ||
collect: (monitor: DragSourceMonitor) => ({ | ||
isDragging: monitor.isDragging(), | ||
}), | ||
}); | ||
|
||
drag(drop(ref)); | ||
|
||
return ( | ||
<div ref={ref} style={{ opacity: isDragging ? 0.5 : 1 }}> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
export default DraggableCard; |
Oops, something went wrong.