Skip to content

Commit

Permalink
fix: merge card position (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
nunocaseiro authored Dec 19, 2022
1 parent ec36c98 commit 0bd563d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
14 changes: 7 additions & 7 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"react-hook-form": "^7.29.0",
"react-query": "^3.34.19",
"react-select": "^5.3.0",
"recoil": "^0.7.0",
"recoil": "^0.7.6",
"socket.io-client": "^4.4.1",
"webpack": "^5.71.0"
},
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/Board/DragDropArea/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const DragDropArea: React.FC<Props> = ({ userId, board, socketId }) => {
sourceDroppableId: string,
draggableId: string,
sourceIndex: number,
sorted: boolean,
) => {
if (!board.hideCards) {
const changes: MergeCardsDto = {
Expand All @@ -51,6 +52,7 @@ const DragDropArea: React.FC<Props> = ({ userId, board, socketId }) => {
socketId,
userId,
cardPosition: sourceIndex,
sorted,
};

mergeCards.mutate(changes);
Expand Down Expand Up @@ -78,6 +80,7 @@ const DragDropArea: React.FC<Props> = ({ userId, board, socketId }) => {
sourceDroppableId,
draggableId,
sourceIndex,
filteredColumns.includes(sourceDroppableId),
);
}

Expand Down
28 changes: 13 additions & 15 deletions frontend/src/helper/board/transformBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,22 @@ export const handleUpdateCardPosition = (board: BoardType, changes: UpdateCardPo
export const handleMergeCard = (board: BoardType, changes: MergeCardsDto) => {
const boardData = removeReadOnly(board);

const { cardGroupId, cardId, colIdOfCardGroup } = changes;
const column = boardData.columns.find((col) => col._id === colIdOfCardGroup);
const cardGroup = column?.cards.find((card) => card._id === cardGroupId);
const selectedCard = column?.cards.find((card) => card._id === cardId);
const { cardGroupId, cardId, colIdOfCardGroup, columnIdOfCard, cardPosition, sorted } = changes;
let currentCardPosition: number | undefined = cardPosition;
const targetColumn = boardData.columns.find((col) => col._id === colIdOfCardGroup);
const cardGroup = targetColumn?.cards.find((card) => card._id === cardGroupId);
const sourceColumn = boardData.columns.find((col) => col._id === columnIdOfCard);
const selectedCard = sourceColumn?.cards.find((card) => card._id === cardId);

if (column && cardGroup && selectedCard) {
if (sorted) {
currentCardPosition = sourceColumn?.cards.findIndex((card) => card._id === cardId);
}

if (cardGroup && selectedCard && sourceColumn && currentCardPosition !== undefined) {
sourceColumn.cards = removeElementAtIndex(sourceColumn.cards, currentCardPosition);
cardGroup.items = addElementAtIndex(cardGroup.items, cardGroup.items.length, {
_id: selectedCard._id,
text: selectedCard.text,
comments: selectedCard.comments,
votes: selectedCard.votes,
createdBy: selectedCard.createdBy,
createdByTeam: selectedCard.createdByTeam,
anonymous: selectedCard.anonymous,
...selectedCard,
});

const index = column.cards.findIndex((idxCard) => idxCard === selectedCard);
column.cards = removeElementAtIndex(column.cards, index);
}

return boardData;
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/types/board/mergeCard.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ export default interface MergeCardsDto {
userId: string;

cardPosition: number;

sorted: boolean;
}

0 comments on commit 0bd563d

Please sign in to comment.