Skip to content

Commit

Permalink
Merge pull request #506 from cboard-org/fix-save-single
Browse files Browse the repository at this point in the history
handle empty Board
  • Loading branch information
martinbedouret authored Oct 31, 2019
2 parents 061de85 + 3e96017 commit bfbcab0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 47 deletions.
77 changes: 47 additions & 30 deletions src/components/Board/Board.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,8 @@ export class BoardContainer extends Component {
updateApiObjectsNoChild,
updateApiObjects,
historyRemovePreviousBoard,
updateBoard
updateBoard,
switchBoard
} = this.props;

// Loggedin user?
Expand All @@ -626,17 +627,20 @@ export class BoardContainer extends Component {
cTile => editedTiles.find(s => s.id === cTile.id) || cTile
);
}
if (tile) {
if (tile && tile.type !== 'board') {
uTiles = [...board.tiles, tile];
}
if (tile && tile.type === 'board') {
uTiles = [...board.tiles];
}

const parentBoardData = {
...board,
tiles: uTiles,
author: userData.name,
email: userData.email,
locale: userData.locale,
isPublic: false
isPublic: false,
hidden: false
};
//check if user has an own communicator
let communicatorData = { ...communicator };
Expand Down Expand Up @@ -678,39 +682,52 @@ export class BoardContainer extends Component {
updateBoard(parentBoardData);
}
//api updates
if (!createChildBoard) {
updateApiObjectsNoChild(
parentBoardData,
createCommunicator,
createParentBoard
)
if (tile && tile.type === 'board') {
//child becomes parent
updateApiObjectsNoChild(childBoardData, createCommunicator, true)
.then(parentBoardId => {
if (createParentBoard) {
historyRemovePreviousBoard(parentBoardId);
}
this.props.history.replace(`/board/${parentBoardId}`);
switchBoard(parentBoardId);
this.props.history.replace(`/board/${parentBoardId}`, []);
this.setState({ isSaving: false });
})
.catch(e => {
this.setState({ isSaving: false });
});
} else {
updateApiObjects(
childBoardData,
parentBoardData,
createCommunicator,
createParentBoard
)
.then(parentBoardId => {
if (createParentBoard) {
historyRemovePreviousBoard(parentBoardId);
}
this.props.history.replace(`/board/${parentBoardId}`);
this.setState({ isSaving: false });
})
.catch(e => {
this.setState({ isSaving: false });
});
if (!createChildBoard) {
updateApiObjectsNoChild(
parentBoardData,
createCommunicator,
createParentBoard
)
.then(parentBoardId => {
if (createParentBoard) {
historyRemovePreviousBoard(parentBoardId);
}
this.props.history.replace(`/board/${parentBoardId}`);
this.setState({ isSaving: false });
})
.catch(e => {
this.setState({ isSaving: false });
});
} else {
updateApiObjects(
childBoardData,
parentBoardData,
createCommunicator,
createParentBoard
)
.then(parentBoardId => {
if (createParentBoard) {
historyRemovePreviousBoard(parentBoardId);
}
this.props.history.replace(`/board/${parentBoardId}`);
this.setState({ isSaving: false });
})
.catch(e => {
this.setState({ isSaving: false });
});
}
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,9 @@ class CommunicatorToolbar extends React.Component {
<ListItemText
inset
primary={board.name || board.id}
secondary={
board.tiles.length +
' ' +
intl.formatMessage(messages.tiles, {
qty: board.tiles.length
})
}
secondary={intl.formatMessage(messages.tiles, {
qty: board.tiles.length
})}
/>
</ListItem>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ exports[`Communicator tests default renderer 1`] = `
<WithStyles(ListItemText)
inset={true}
primary="board-1"
secondary="0 cboard.components.CommunicatorToolbar.tiles"
secondary="cboard.components.CommunicatorToolbar.tiles"
/>
</WithStyles(ListItem)>
<WithStyles(ListItem)
Expand All @@ -51,7 +51,7 @@ exports[`Communicator tests default renderer 1`] = `
<WithStyles(ListItemText)
inset={true}
primary="board-2-name"
secondary="0 cboard.components.CommunicatorToolbar.tiles"
secondary="cboard.components.CommunicatorToolbar.tiles"
/>
</WithStyles(ListItem)>
</WithStyles(Menu)>
Expand Down Expand Up @@ -142,7 +142,7 @@ exports[`Communicator tests menu behavior 1`] = `
<WithStyles(ListItemText)
inset={true}
primary="board-1"
secondary="0 cboard.components.CommunicatorToolbar.tiles"
secondary="cboard.components.CommunicatorToolbar.tiles"
/>
</WithStyles(ListItem)>
<WithStyles(ListItem)
Expand All @@ -158,7 +158,7 @@ exports[`Communicator tests menu behavior 1`] = `
<WithStyles(ListItemText)
inset={true}
primary="board-2-name"
secondary="0 cboard.components.CommunicatorToolbar.tiles"
secondary="cboard.components.CommunicatorToolbar.tiles"
/>
</WithStyles(ListItem)>
</WithStyles(Menu)>
Expand Down Expand Up @@ -249,7 +249,7 @@ exports[`Communicator tests menu behavior 2`] = `
<WithStyles(ListItemText)
inset={true}
primary="board-1"
secondary="0 cboard.components.CommunicatorToolbar.tiles"
secondary="cboard.components.CommunicatorToolbar.tiles"
/>
</WithStyles(ListItem)>
<WithStyles(ListItem)
Expand All @@ -265,7 +265,7 @@ exports[`Communicator tests menu behavior 2`] = `
<WithStyles(ListItemText)
inset={true}
primary="board-2-name"
secondary="0 cboard.components.CommunicatorToolbar.tiles"
secondary="cboard.components.CommunicatorToolbar.tiles"
/>
</WithStyles(ListItem)>
</WithStyles(Menu)>
Expand Down Expand Up @@ -356,7 +356,7 @@ exports[`Communicator tests switching boards behavior 1`] = `
<WithStyles(ListItemText)
inset={true}
primary="board-1"
secondary="0 cboard.components.CommunicatorToolbar.tiles"
secondary="cboard.components.CommunicatorToolbar.tiles"
/>
</WithStyles(ListItem)>
<WithStyles(ListItem)
Expand All @@ -372,7 +372,7 @@ exports[`Communicator tests switching boards behavior 1`] = `
<WithStyles(ListItemText)
inset={true}
primary="board-2-name"
secondary="0 cboard.components.CommunicatorToolbar.tiles"
secondary="cboard.components.CommunicatorToolbar.tiles"
/>
</WithStyles(ListItem)>
</WithStyles(Menu)>
Expand Down Expand Up @@ -463,7 +463,7 @@ exports[`Communicator tests switching boards behavior 2`] = `
<WithStyles(ListItemText)
inset={true}
primary="board-1"
secondary="0 cboard.components.CommunicatorToolbar.tiles"
secondary="cboard.components.CommunicatorToolbar.tiles"
/>
</WithStyles(ListItem)>
<WithStyles(ListItem)
Expand All @@ -479,7 +479,7 @@ exports[`Communicator tests switching boards behavior 2`] = `
<WithStyles(ListItemText)
inset={true}
primary="board-2-name"
secondary="0 cboard.components.CommunicatorToolbar.tiles"
secondary="cboard.components.CommunicatorToolbar.tiles"
/>
</WithStyles(ListItem)>
</WithStyles(Menu)>
Expand Down

0 comments on commit bfbcab0

Please sign in to comment.