Skip to content

Commit

Permalink
Merge pull request #1630 from tomivm/fix/lost-of-boards-when-create-a…
Browse files Browse the repository at this point in the history
…-parent-board

Fix/lost of boards when create a parent board
  • Loading branch information
martinbedouret authored Dec 14, 2023
2 parents 078a075 + ca6bb61 commit 3ef1026
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/components/Board/Board.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,8 +758,20 @@ export function updateApiObjects(
.then(res => {
const updatedChildBoardId = res.id;
//create - update parent board
const updateTilesParentBoard = () =>
parentBoard.tiles.map(tile => {
if (tile.loadBoard === childBoard.id)
return { ...tile, loadBoard: updatedChildBoardId };
return tile;
});
const updatedParentBoard = {
...parentBoard,
tiles: createParentBoard
? updateTilesParentBoard()
: parentBoard.tiles
};
const action = createParentBoard ? createApiBoard : updateApiBoard;
return dispatch(action(parentBoard, parentBoard.id))
return dispatch(action(updatedParentBoard, parentBoard.id))
.then(res => {
const updatedParentBoardId = res.id;
//add new boards to the active communicator
Expand Down
6 changes: 5 additions & 1 deletion src/components/Board/Board.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ export class BoardContainer extends Component {

// Loggedin user?
if ('name' in userData && 'email' in userData) {
await this.handleApiUpdates(tile);
await this.handleApiUpdates(tile); // this function could mutate tthe tile
return;
}

Expand Down Expand Up @@ -1125,6 +1125,7 @@ export class BoardContainer extends Component {
//update the parent
updateBoard(parentBoardData);
}
// Untill here all is with shorts ids
//api updates
if (tile && tile.type === 'board') {
//child becomes parent
Expand Down Expand Up @@ -1166,6 +1167,9 @@ export class BoardContainer extends Component {
)
.then(parentBoardId => {
if (createParentBoard) {
/* Here the parentBoardData is not updated with the values
that updatedApiObjects store on the API. Inside the boards are already updated
an the value is not replaced because the oldboard Id was replaced on the updateApiObjects inside createApiBoardSuccess */
replaceBoard(
{ ...parentBoardData },
{ ...parentBoardData, id: parentBoardId }
Expand Down
4 changes: 4 additions & 0 deletions src/components/Board/Board.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ function tileReducer(board, action) {
return {
...board,
tiles: [...board.tiles, { ...action.tile }]
/* some times when a tile folder is created here the last tile change loadBoard to a long Id with no reason
action tile before this copy has a short ID*/
};
case DELETE_TILES:
return {
Expand Down Expand Up @@ -165,6 +167,8 @@ function boardReducer(state = initialState, action) {

if (prev.id !== current.id) {
const boardIndex = boards.findIndex(b => b.id === prev.id);
/* On create a parent board the prev board doesn't exist with a short Id
because is already replaced by a long one */
if (boardIndex >= 0) {
boards[boardIndex] = current;
}
Expand Down

0 comments on commit 3ef1026

Please sign in to comment.