Progress Commit

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-05-17 16:29:46 -04:00
parent c3108a17f4
commit 55d729339f
9 changed files with 440 additions and 511 deletions

View File

@@ -1,5 +1,9 @@
import update from "immutability-helper";
const updateLanes = (state, lanes) => update(state, { lanes: { $set: lanes } });
const updateLaneCards = (lane, cards) => update(lane, { cards: { $set: cards } });
const LaneHelper = {
initialiseLanes: (state, { lanes }) => {
const newLanes = lanes.map((lane) => {
@@ -7,13 +11,13 @@ const LaneHelper = {
lane.cards && lane.cards.forEach((c) => (c.laneId = lane.id));
return lane;
});
return update(state, { lanes: { $set: newLanes } });
return updateLanes(state, newLanes);
},
paginateLane: (state, { laneId, newCards, nextPage }) => {
const updatedLanes = LaneHelper.appendCardsToLane(state, { laneId: laneId, newCards: newCards });
updatedLanes.find((lane) => lane.id === laneId).currentPage = nextPage;
return update(state, { lanes: { $set: updatedLanes } });
return updateLanes(state, updatedLanes);
},
appendCardsToLane: (state, { laneId, newCards, index }) => {
@@ -23,12 +27,11 @@ const LaneHelper = {
.filter((c) => lane.cards.find((card) => card.id === c.id) == null);
return state.lanes.map((lane) => {
if (lane.id === laneId) {
if (index !== undefined) {
return update(lane, { cards: { $splice: [[index, 0, ...newCards]] } });
} else {
const cardsToUpdate = [...lane.cards, ...newCards];
return update(lane, { cards: { $set: cardsToUpdate } });
}
const cardsToUpdate =
index !== undefined
? [...lane.cards.slice(0, index), ...newCards, ...lane.cards.slice(index)]
: [...lane.cards, ...newCards];
return updateLaneCards(lane, cardsToUpdate);
} else {
return lane;
}
@@ -37,35 +40,29 @@ const LaneHelper = {
appendCardToLane: (state, { laneId, card, index }) => {
const newLanes = LaneHelper.appendCardsToLane(state, { laneId: laneId, newCards: [card], index });
return update(state, { lanes: { $set: newLanes } });
return updateLanes(state, newLanes);
},
addLane: (state, lane) => {
const newLane = { cards: [], ...lane };
return update(state, { lanes: { $push: [newLane] } });
return updateLanes(state, [...state.lanes, newLane]);
},
updateLane: (state, updatedLane) => {
const newLanes = state.lanes.map((lane) => {
if (updatedLane.id === lane.id) {
return { ...lane, ...updatedLane };
} else {
return lane;
}
});
return update(state, { lanes: { $set: newLanes } });
const newLanes = state.lanes.map((lane) => (updatedLane.id === lane.id ? { ...lane, ...updatedLane } : lane));
return updateLanes(state, newLanes);
},
removeCardFromLane: (state, { laneId, cardId }) => {
const lanes = state.lanes.map((lane) => {
if (lane.id === laneId) {
let newCards = lane.cards.filter((card) => card.id !== cardId);
return update(lane, { cards: { $set: newCards } });
const newCards = lane.cards.filter((card) => card.id !== cardId);
return updateLaneCards(lane, newCards);
} else {
return lane;
}
});
return update(state, { lanes: { $set: lanes } });
return updateLanes(state, lanes);
},
moveCardAcrossLanes: (state, { fromLaneId, toLaneId, cardId, index }) => {
@@ -74,50 +71,36 @@ const LaneHelper = {
if (lane.id === fromLaneId) {
cardToMove = lane.cards.find((card) => card.id === cardId);
const newCards = lane.cards.filter((card) => card.id !== cardId);
return update(lane, { cards: { $set: newCards } });
return updateLaneCards(lane, newCards);
} else {
return lane;
}
});
const updatedState = update(state, { lanes: { $set: interimLanes } });
return LaneHelper.appendCardToLane(updatedState, {
laneId: toLaneId,
card: cardToMove,
index: index
});
return LaneHelper.appendCardToLane(
{ ...state, lanes: interimLanes },
{
laneId: toLaneId,
card: cardToMove,
index: index
}
);
},
updateCardsForLane: (state, { laneId, cards }) => {
const lanes = state.lanes.map((lane) => {
if (lane.id === laneId) {
return update(lane, { cards: { $set: cards } });
} else {
return lane;
}
});
return update(state, { lanes: { $set: lanes } });
const lanes = state.lanes.map((lane) => (lane.id === laneId ? updateLaneCards(lane, cards) : lane));
return updateLanes(state, lanes);
},
updateCardForLane: (state, { laneId, card: updatedCard }) => {
const lanes = state.lanes.map((lane) => {
if (lane.id === laneId) {
const cards = lane.cards.map((card) => {
if (card.id === updatedCard.id) {
return { ...card, ...updatedCard };
} else {
return card;
}
});
return update(lane, { cards: { $set: cards } });
const cards = lane.cards.map((card) => (card.id === updatedCard.id ? { ...card, ...updatedCard } : card));
return updateLaneCards(lane, cards);
} else {
return lane;
}
});
return update(state, { lanes: { $set: lanes } });
},
updateLanes: (state, lanes) => {
return { ...state, ...{ lanes: lanes } };
return updateLanes(state, lanes);
},
moveLane: (state, { oldIndex, newIndex }) => {
@@ -128,7 +111,7 @@ const LaneHelper = {
removeLane: (state, { laneId }) => {
const updatedLanes = state.lanes.filter((lane) => lane.id !== laneId);
return update(state, { lanes: { $set: updatedLanes } });
return updateLanes(state, updatedLanes);
}
};