Skip to content

Commit

Permalink
Fix GladysAssistant#732: Fix RoomSelector when getHouse return houses…
Browse files Browse the repository at this point in the history
… without rooms (GladysAssistant#738)
  • Loading branch information
Pierre-Gilles authored and NickDub committed Apr 13, 2020
1 parent 81bd5b5 commit a7e35a3
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions front/src/components/house/RoomSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,30 @@ class RoomSelector extends Component {

componentWillReceiveProps = newProps => {
let selectedRoom;
const houseOptions = newProps.houses.map(house => {
return {
label: house.name,
options: house.rooms.map(room => {
const option = {
label: room.name,
value: room.selector,
room
};

if (newProps.selectedRoom === room.selector) {
selectedRoom = option;
}

return option;
})
};
});
let houseOptions = [];
if (newProps.houses) {
houseOptions = newProps.houses.map(house => {
return {
label: house.name,
options:
house && house.rooms
? house.rooms.map(room => {
const option = {
label: room.name,
value: room.selector,
room
};

if (newProps.selectedRoom === room.selector) {
selectedRoom = option;
}

return option;
})
: []
};
});
}

this.setState({ houseOptions, selectedRoom });
};
Expand Down

0 comments on commit a7e35a3

Please sign in to comment.