Skip to content
Snippets Groups Projects
Commit c5a1a20a authored by Jörn Künsemöller's avatar Jörn Künsemöller
Browse files

TMSS-2688: cleanup

parent a7fcaf6f
No related branches found
No related tags found
1 merge request!1195TMSS-2688: websockets
...@@ -279,12 +279,10 @@ export default function WeekView() { ...@@ -279,12 +279,10 @@ export default function WeekView() {
*/ */
function handleData(event) { function handleData(event) {
const jsonData = JSON.parse(event?.data) || {}; const jsonData = JSON.parse(event?.data) || {};
console.log('received websocket data:', jsonData)
switch (jsonData.object_type) { switch (jsonData.object_type) {
case 'scheduling_unit_blueprint': { case 'scheduling_unit_blueprint': {
switch (jsonData.action) { switch (jsonData.action) {
case 'delete': { case 'delete': {
console.log('ws delete SU');
const schedulingUnits = data.schedulingUnits const schedulingUnits = data.schedulingUnits
_.remove(schedulingUnits, function (su) { return su.id === jsonData.object_details.id}); _.remove(schedulingUnits, function (su) { return su.id === jsonData.object_details.id});
setData(prevData => ({ setData(prevData => ({
...@@ -297,7 +295,6 @@ export default function WeekView() { ...@@ -297,7 +295,6 @@ export default function WeekView() {
break; break;
} }
case 'update': { case 'update': {
console.log("ws update SU");
setData(prevData => ({ setData(prevData => ({
...prevData, ...prevData,
schedulingUnits: prevData.schedulingUnits.map( schedulingUnits: prevData.schedulingUnits.map(
...@@ -321,8 +318,7 @@ export default function WeekView() { ...@@ -321,8 +318,7 @@ export default function WeekView() {
break; break;
} }
case 'create': { case 'create': {
console.log("ws create SU"); // The websocket message only contains a subset of the details we need, so fetch the full set
// the ws message only contains a subset of the details we need, so fetch the full set */
ScheduleService.getTimelineSlimBlueprints(undefined, undefined, jsonData.object_details.id) // todo: check time ScheduleService.getTimelineSlimBlueprints(undefined, undefined, jsonData.object_details.id) // todo: check time
.then((response) => { .then((response) => {
setData(prevData => ({ setData(prevData => ({
...@@ -330,13 +326,6 @@ export default function WeekView() { ...@@ -330,13 +326,6 @@ export default function WeekView() {
schedulingUnits: prevData.schedulingUnits.concat(response) schedulingUnits: prevData.schedulingUnits.concat(response)
})); }));
}); });
/** Note: the following works in principle, but the ws message is missing details which are
quite extensive to get broadcasted. Still, could be added in the websocket service.
setData(prevData => ({
...prevData,
schedulingUnits: prevData.schedulingUnits.concat([jsonData.object_details])
}));
*/
break; break;
} }
default: { break; } default: { break; }
...@@ -346,7 +335,6 @@ export default function WeekView() { ...@@ -346,7 +335,6 @@ export default function WeekView() {
case 'reservation': { case 'reservation': {
switch (jsonData.action) { switch (jsonData.action) {
case 'delete': { case 'delete': {
console.log('ws delete reservation');
const reservations = data.reservations const reservations = data.reservations
_.remove(reservations, function (res) { return res.id === jsonData.object_details.id}); _.remove(reservations, function (res) { return res.id === jsonData.object_details.id});
setData(prevData => ({ setData(prevData => ({
...@@ -359,7 +347,6 @@ export default function WeekView() { ...@@ -359,7 +347,6 @@ export default function WeekView() {
break; break;
} }
case 'update': { case 'update': {
console.log("ws update reservation");
setData(prevData => ({ setData(prevData => ({
...prevData, ...prevData,
reservations: prevData.reservations.map( reservations: prevData.reservations.map(
...@@ -367,16 +354,15 @@ export default function WeekView() { ...@@ -367,16 +354,15 @@ export default function WeekView() {
), ),
})); }));
if (summaryItem?.id === jsonData.object_details.id) { if (summaryItem?.id === jsonData.object_details.id) {
// Note: this triggers a full fetch again to get all details (see SU above). // Trigger a full refresh of the details panel
setSummaryItem({id: jsonData.object_details.id, type: "RESERVATION"}); setSummaryItem({id: jsonData.object_details.id, type: "RESERVATION"});
} }
break; break;
} }
case 'create': { case 'create': {
console.log("ws create reservation");
const shouldFetchReservations = getStore(UIConstants.STORE_KEY_TIMELINE).reservationsToggle; const shouldFetchReservations = getStore(UIConstants.STORE_KEY_TIMELINE).reservationsToggle;
if (shouldFetchReservations) { if (shouldFetchReservations) {
// the ws message only contains a subset of the details we need, so fetch the full set // The websocket message only contains a subset of the details we need, so fetch the full set
ReservationService.getTimelineReservations(undefined, undefined, jsonData.object_details.id) // todo: check time ReservationService.getTimelineReservations(undefined, undefined, jsonData.object_details.id) // todo: check time
.then((response) => { .then((response) => {
setData(prevData => ({ setData(prevData => ({
...@@ -385,15 +371,6 @@ export default function WeekView() { ...@@ -385,15 +371,6 @@ export default function WeekView() {
})); }));
}); });
} }
/** Note: the following works in principle without fetching details, but new items don't render,
most likely due to missing details in the ws message, which need to be added in the websocket
service for this to work.
setData(prevData => ({
...prevData,
reservations: prevData.reservations.concat([jsonData.object_details])
}));
*/
break; break;
} }
default: { break; } default: { break; }
...@@ -404,11 +381,6 @@ export default function WeekView() { ...@@ -404,11 +381,6 @@ export default function WeekView() {
} }
} }
// debug logging whenever the SU and reservation data gets updated
useEffect(() => {
console.log('data update:', data);
}, [data])
// websocket hook that opens and allows interaction via the wss connection // websocket hook that opens and allows interaction via the wss connection
const { const {
sendMessage, sendMessage,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment