import pick from 'lodash/pick'; import React, { useCallback } 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 } from '../../lib/popup'; import Paths from '../../constants/Paths'; import DroppableTypes from '../../constants/DroppableTypes'; import AddPopup from './AddPopup'; import EditPopup from './EditPopup'; import styles from './Boards.module.css'; const Boards = React.memo( ({ items, currentId, isEditable, onCreate, onUpdate, onMove, onDelete }) => { 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 renderItems = useCallback( (safeItems) => safeItems.map((item) => (
{item.isPersisted ? ( {item.name} ) : ( {item.name} )}
)), [currentId], ); const renderEditableItems = useCallback( (safeItems) => safeItems.map((item, index) => ( {({ innerRef, draggableProps, dragHandleProps }) => ( // eslint-disable-next-line react/jsx-props-no-spreading
{item.isPersisted ? ( {item.name} ) : ( // eslint-disable-next-line react/jsx-props-no-spreading {item.name} )} {item.isPersisted && ( handleUpdate(item.id, data)} onDelete={() => handleDelete(item.id)} > )}
)}
)), [currentId, handleUpdate, handleDelete], ); return (
{isEditable ? ( {({ innerRef, droppableProps, placeholder }) => ( // eslint-disable-next-line react/jsx-props-no-spreading
{renderEditableItems(items)} {placeholder}
)}
) : (
{renderItems(items)}
)}
); }, ); Boards.propTypes = { items: PropTypes.array.isRequired, // eslint-disable-line react/forbid-prop-types currentId: PropTypes.string, isEditable: 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;