Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/lost of boards when create a parent board #1630

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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