Drag to select boards (#1127)

- drag to select boards
This commit is contained in:
brendanlaschke
2023-08-09 18:25:09 +02:00
committed by GitHub
parent 2b166927d1
commit 3122541f3b
3 changed files with 26 additions and 3 deletions

View File

@ -1,4 +1,4 @@
import { useCallback } from 'react'; import { useCallback, useRef } from 'react';
import { getOperationName } from '@apollo/client/utilities'; import { getOperationName } from '@apollo/client/utilities';
import { useTheme } from '@emotion/react'; import { useTheme } from '@emotion/react';
import styled from '@emotion/styled'; import styled from '@emotion/styled';
@ -12,6 +12,7 @@ import { StyledBoard } from '@/ui/board/components/StyledBoard';
import { useUpdateBoardCardIds } from '@/ui/board/hooks/useUpdateBoardCardIds'; import { useUpdateBoardCardIds } from '@/ui/board/hooks/useUpdateBoardCardIds';
import { BoardColumnIdContext } from '@/ui/board/states/BoardColumnIdContext'; import { BoardColumnIdContext } from '@/ui/board/states/BoardColumnIdContext';
import { SelectedSortType } from '@/ui/filter-n-sort/types/interface'; import { SelectedSortType } from '@/ui/filter-n-sort/types/interface';
import { DragSelect } from '@/ui/utilities/drag-select/components/DragSelect';
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope'; import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
import { import {
PipelineProgress, PipelineProgress,
@ -23,6 +24,7 @@ import {
import { GET_PIPELINE_PROGRESS } from '../../../pipeline/queries'; import { GET_PIPELINE_PROGRESS } from '../../../pipeline/queries';
import { BoardColumnContext } from '../states/BoardColumnContext'; import { BoardColumnContext } from '../states/BoardColumnContext';
import { boardColumnsState } from '../states/boardColumnsState'; import { boardColumnsState } from '../states/boardColumnsState';
import { selectedBoardCardIdsState } from '../states/selectedBoardCardIdsState';
import { BoardOptions } from '../types/BoardOptions'; import { BoardOptions } from '../types/BoardOptions';
import { EntityBoardColumn } from './EntityBoardColumn'; import { EntityBoardColumn } from './EntityBoardColumn';
@ -103,6 +105,21 @@ export function EntityBoard({
return a.index - b.index; return a.index - b.index;
}); });
const boardRef = useRef(null);
const [selectedBoardCards, setSelectedBoardCards] = useRecoilState(
selectedBoardCardIdsState,
);
function setRowSelectedState(boardCardId: string, selected: boolean) {
if (selected && !selectedBoardCards.includes(boardCardId)) {
setSelectedBoardCards([...selectedBoardCards, boardCardId ?? '']);
} else if (!selected && selectedBoardCards.includes(boardCardId)) {
setSelectedBoardCards(
selectedBoardCards.filter((id) => id !== boardCardId),
);
}
}
return (boardColumns?.length ?? 0) > 0 ? ( return (boardColumns?.length ?? 0) > 0 ? (
<StyledBoardWithHeader> <StyledBoardWithHeader>
<BoardHeader <BoardHeader
@ -112,7 +129,7 @@ export function EntityBoard({
onSortsUpdate={updateSorts} onSortsUpdate={updateSorts}
context={CompanyBoardContext} context={CompanyBoardContext}
/> />
<StyledBoard> <StyledBoard ref={boardRef}>
<DragDropContext onDragEnd={onDragEnd}> <DragDropContext onDragEnd={onDragEnd}>
{sortedBoardColumns.map((column) => ( {sortedBoardColumns.map((column) => (
<BoardColumnIdContext.Provider value={column.id} key={column.id}> <BoardColumnIdContext.Provider value={column.id} key={column.id}>
@ -128,6 +145,10 @@ export function EntityBoard({
))} ))}
</DragDropContext> </DragDropContext>
</StyledBoard> </StyledBoard>
<DragSelect
dragSelectable={boardRef}
onDragSelectionChange={setRowSelectedState}
/>
</StyledBoardWithHeader> </StyledBoardWithHeader>
) : ( ) : (
<></> <></>

View File

@ -18,6 +18,8 @@ export function EntityBoardCard({
ref={draggableProvided?.innerRef} ref={draggableProvided?.innerRef}
{...draggableProvided?.dragHandleProps} {...draggableProvided?.dragHandleProps}
{...draggableProvided?.draggableProps} {...draggableProvided?.draggableProps}
data-selectable-id={cardId}
data-select-disable
> >
{boardOptions.cardComponent} {boardOptions.cardComponent}
</div> </div>

View File

@ -7,7 +7,7 @@ import {
type OwnProps = { type OwnProps = {
dragSelectable: RefObject<HTMLElement>; dragSelectable: RefObject<HTMLElement>;
onDragSelectionChange: (id: string, selected: boolean) => void; onDragSelectionChange: (id: string, selected: boolean) => void;
onDragSelectionStart: () => void; onDragSelectionStart?: () => void;
}; };
export function DragSelect({ export function DragSelect({