- Fixed the bug where dragging a item in a 1 item lane in vertical mode and not releasing it in a valid position or the same position, would cause the card the vanish until the lane was refreshed. (One of the three big ones)

- Adjusted Small / Medium / Large as per allan

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-07-15 13:44:26 -04:00
parent eb1b2aef55
commit 668366e886
3 changed files with 52 additions and 69 deletions

View File

@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useState } from "react"; import React, { useCallback, useEffect, useRef, useState } from "react";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { DragDropContext } from "../dnd/lib"; import { DragDropContext } from "../dnd/lib";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
@@ -8,22 +8,20 @@ import { PopoverWrapper } from "react-popopo";
import * as actions from "../../../../redux/trello/trello.actions.js"; import * as actions from "../../../../redux/trello/trello.actions.js";
import { BoardWrapper } from "../styles/Base.js"; import { BoardWrapper } from "../styles/Base.js";
/** const useDragMap = () => {
* BoardContainer is a React component that represents a Trello-like board. const dragMapRef = useRef(new Map());
* It uses Redux for state management and provides a variety of props to customize its behavior.
* const setDragTime = (laneId) => {
* @component dragMapRef.current.set(laneId, Date.now());
* @param {Object} props - Component props };
* @param {Object} props.data - The initial data for the board
* @param {Function} props.onDataChange - Callback function when the data changes const getLastDragTime = (laneId) => {
* @param {Function} props.onDragEnd - Callback function when a drag ends return dragMapRef.current.get(laneId);
* @param {Function} props.laneSortFunction - Callback function when a drag ends };
* @param {string} props.orientation - The orientation of the board ("horizontal" or "vertical")
* @param {Function} props.eventBusHandle - Function to handle events from the event bus return { setDragTime, getLastDragTime };
* @param {Object} props.reducerData - The initial data for the Redux reducer };
*
* @returns {JSX.Element} A Trello-like board
*/
const BoardContainer = ({ const BoardContainer = ({
data, data,
onDataChange = () => {}, onDataChange = () => {},
@@ -42,6 +40,7 @@ const BoardContainer = ({
const dispatch = useDispatch(); const dispatch = useDispatch();
const currentReducerData = useSelector((state) => (state.trello.lanes ? state.trello : {})); const currentReducerData = useSelector((state) => (state.trello.lanes ? state.trello : {}));
const { setDragTime, getLastDragTime } = useDragMap();
const wireEventBus = useCallback(() => { const wireEventBus = useCallback(() => {
const eventBus = { const eventBus = {
@@ -71,7 +70,6 @@ const BoardContainer = ({
event event
}) })
); );
default: default:
return; return;
} }
@@ -95,12 +93,12 @@ const BoardContainer = ({
const onDragStart = useCallback(() => { const onDragStart = useCallback(() => {
setIsDragging(true); setIsDragging(true);
}, [setIsDragging]); }, []);
const onLaneDrag = useCallback( const onLaneDrag = useCallback(
async ({ draggableId, type, source, reason, mode, destination, combine }) => { async ({ draggableId, type, source, reason, mode, destination, combine }) => {
setIsDragging(false); setIsDragging(false);
setDragTime(source.droppableId);
if (!type || type !== "lane" || !source || !destination || isEqual(source, destination)) return; if (!type || type !== "lane" || !source || !destination || isEqual(source, destination)) return;
setIsProcessing(true); setIsProcessing(true);
@@ -122,35 +120,34 @@ const BoardContainer = ({
setIsProcessing(false); setIsProcessing(false);
} }
}, },
[dispatch, onDragEnd] [dispatch, onDragEnd, setDragTime]
); );
return ( return (
<PopoverWrapper> <PopoverWrapper>
<BoardWrapper orientation={orientation}> <BoardWrapper orientation={orientation}>
<DragDropContext onDragEnd={onLaneDrag} onDragStart={onDragStart} contextId="production-board"> <DragDropContext onDragEnd={onLaneDrag} onDragStart={onDragStart} contextId="production-board">
{currentReducerData.lanes.map((lane, index) => { {currentReducerData.lanes.map((lane, index) => (
return ( <Lane
<Lane key={lane.id}
key={lane.id} id={lane.id}
id={lane.id} title={lane.title}
title={lane.title} index={index}
index={index} laneSortFunction={laneSortFunction}
laneSortFunction={laneSortFunction} orientation={orientation}
orientation={orientation} cards={lane.cards}
cards={lane.cards} isDragging={isDragging}
isDragging={isDragging} isProcessing={isProcessing}
isProcessing={isProcessing} cardSettings={cardSettings}
cardSettings={cardSettings} maxLaneHeight={maxLaneHeight}
maxLaneHeight={maxLaneHeight} setMaxLaneHeight={setMaxLaneHeight}
setMaxLaneHeight={setMaxLaneHeight} maxCardHeight={maxCardHeight}
maxCardHeight={maxCardHeight} setMaxCardHeight={setMaxCardHeight}
setMaxCardHeight={setMaxCardHeight} maxCardWidth={maxCardWidth}
maxCardWidth={maxCardWidth} setMaxCardWidth={setMaxCardWidth}
setMaxCardWidth={setMaxCardWidth} lastDrag={getLastDragTime(lane.id)}
/> />
); ))}
})}
</DragDropContext> </DragDropContext>
</BoardWrapper> </BoardWrapper>
</PopoverWrapper> </PopoverWrapper>

View File

@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react"; import React, { useCallback, useMemo, useRef, useState } from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { bindActionCreators } from "redux"; import { bindActionCreators } from "redux";
import { connect } from "react-redux"; import { connect } from "react-redux";
@@ -36,6 +36,7 @@ import objectHash from "object-hash";
* @param setMaxCardHeight * @param setMaxCardHeight
* @param maxCardWidth * @param maxCardWidth
* @param setMaxCardWidth * @param setMaxCardWidth
* @param lastDrag
* @param technician -- connected to redux * @param technician -- connected to redux
* @param bodyshop -- connected to redux * @param bodyshop -- connected to redux
* @returns {Element} * @returns {Element}
@@ -56,19 +57,13 @@ const Lane = ({
setMaxCardHeight, setMaxCardHeight,
maxCardWidth, maxCardWidth,
setMaxCardWidth, setMaxCardWidth,
lastDrag,
technician, technician,
bodyshop bodyshop
}) => { }) => {
const [collapsed, setCollapsed] = useState(false); const [collapsed, setCollapsed] = useState(false);
const [isVisible, setIsVisible] = useState(true);
const laneRef = useRef(null); const laneRef = useRef(null);
useEffect(() => {
setIsVisible(false);
const timer = setTimeout(() => setIsVisible(true), 0);
return () => clearTimeout(timer);
}, [cards.length]);
const sortedCards = useMemo(() => { const sortedCards = useMemo(() => {
if (!cards) return []; if (!cards) return [];
if (!laneSortFunction) return cards; if (!laneSortFunction) return cards;
@@ -189,23 +184,13 @@ const Lane = ({
className={`react-trello-lane ${collapsed ? "lane-collapsed" : ""}`} className={`react-trello-lane ${collapsed ? "lane-collapsed" : ""}`}
style={{ ...provided.droppableProps.style }} style={{ ...provided.droppableProps.style }}
> >
{isVisible && <FinalComponent {...finalComponentProps} />} <FinalComponent {...finalComponentProps} />
{shouldRenderPlaceholder && provided.placeholder} {shouldRenderPlaceholder && provided.placeholder}
</div> </div>
</HeightMemoryWrapper> </HeightMemoryWrapper>
); );
}, },
[ [orientation, collapsed, renderDraggable, maxLaneHeight, setMaxLaneHeight, maxCardWidth, id, cardSettings]
orientation,
collapsed,
isVisible,
renderDraggable,
maxLaneHeight,
setMaxLaneHeight,
maxCardWidth,
id,
cardSettings
]
); );
const renderDragContainer = useCallback( const renderDragContainer = useCallback(
@@ -262,7 +247,7 @@ const Lane = ({
); );
return ( return (
<Section key={id} orientation={orientation} cardSettings={cardSettings}> <Section key={`lane-${id}-${lastDrag}`} orientation={orientation} cardSettings={cardSettings}>
<div onDoubleClick={toggleLaneCollapsed} className="react-trello-column-header"> <div onDoubleClick={toggleLaneCollapsed} className="react-trello-column-header">
<span className="lane-title"> <span className="lane-title">
{collapsed ? <EyeInvisibleOutlined className="icon" /> : <EyeOutlined className="icon" />} {collapsed ? <EyeInvisibleOutlined className="icon" /> : <EyeOutlined className="icon" />}
@@ -289,7 +274,8 @@ Lane.propTypes = {
maxCardHeight: PropTypes.number.isRequired, maxCardHeight: PropTypes.number.isRequired,
setMaxCardHeight: PropTypes.func.isRequired, setMaxCardHeight: PropTypes.func.isRequired,
maxCardWidth: PropTypes.number.isRequired, maxCardWidth: PropTypes.number.isRequired,
setMaxCardWidth: PropTypes.func.isRequired setMaxCardWidth: PropTypes.func.isRequired,
lastDrag: PropTypes.number
}; };
const mapDispatchToProps = (dispatch) => ({ const mapDispatchToProps = (dispatch) => ({

View File

@@ -3,8 +3,8 @@
* @type {{small: string, large: string, medium: string}} * @type {{small: string, large: string, medium: string}}
*/ */
export const cardSizesHorizontal = { export const cardSizesHorizontal = {
small: "150px", small: "225px",
medium: "225px", medium: "275px",
large: "350px" large: "350px"
}; };
@@ -13,7 +13,7 @@ export const cardSizesHorizontal = {
* @type {{small: string, large: string, medium: string}} * @type {{small: string, large: string, medium: string}}
*/ */
export const cardSizesVertical = { export const cardSizesVertical = {
small: "150px", small: "225px",
medium: "225px", medium: "275px",
large: "350px" large: "350px"
}; };