import pick from 'lodash/pick'; import React, { useCallback, useRef } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { Link } from 'react-router-dom'; import { DragDropContext, Draggable, Droppable } from 'react-beautiful-dnd'; import { Button, Icon } from 'semantic-ui-react'; import { closePopup, usePopup } from '../../lib/popup'; import Paths from '../../constants/Paths'; import DroppableTypes from '../../constants/DroppableTypes'; import AddStep from './AddStep'; import EditStep from './EditStep'; import styles from './Boards.module.scss'; const Boards = React.memo(({ items, currentId, canEdit, onCreate, onUpdate, onMove, onDelete }) => { const tabsWrapper = useRef(null); const handleWheel = useCallback(({ deltaY }) => { tabsWrapper.current.scrollBy({ left: deltaY, }); }, []); const handleDragStart = useCallback(() => { closePopup(); }, []); const handleDragEnd = useCallback( ({ draggableId, source, destination }) => { if (!destination || source.index === destination.index) { return; } onMove(draggableId, destination.index); }, [onMove], ); const handleUpdate = useCallback( (id, data) => { onUpdate(id, data); }, [onUpdate], ); const handleDelete = useCallback( (id) => { onDelete(id); }, [onDelete], ); const AddPopup = usePopup(AddStep); const EditPopup = usePopup(EditStep); const itemsNode = items.map((item, index) => ( {({ innerRef, draggableProps, dragHandleProps }) => ( // eslint-disable-next-line react/jsx-props-no-spreading
{item.isPersisted ? ( <> {item.name} {canEdit && ( handleUpdate(item.id, data)} onDelete={() => handleDelete(item.id)} > )} ) : ( // eslint-disable-next-line react/jsx-props-no-spreading {item.name} )}
)}
)); return (
{({ innerRef, droppableProps, placeholder }) => ( // eslint-disable-next-line react/jsx-props-no-spreading
{itemsNode} {placeholder} {canEdit && (
)}
); }); Boards.propTypes = { items: PropTypes.array.isRequired, // eslint-disable-line react/forbid-prop-types currentId: PropTypes.string, canEdit: PropTypes.bool.isRequired, onCreate: PropTypes.func.isRequired, onUpdate: PropTypes.func.isRequired, onMove: PropTypes.func.isRequired, onDelete: PropTypes.func.isRequired, }; Boards.defaultProps = { currentId: undefined, }; export default Boards;