feature/IO-2924-Refactor-Production-Board-For-Sockets - Checkpoint

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-09-12 17:50:00 -04:00
parent 08e1cf80c2
commit 88b313b9d8

View File

@@ -1,3 +1,4 @@
import dayjs from "../../utils/day";
import { SyncOutlined } from "@ant-design/icons";
import { useApolloClient } from "@apollo/client";
import Board from "./trello-board/index";
@@ -51,7 +52,6 @@ function ProductionBoardKanbanComponent({ data, bodyshop, refetch, insertAuditTr
const { t } = useTranslation();
const client = useApolloClient();
// Update the lanes or cards based on job update event
const handleJobUpdated = useCallback(
(updatedJob) => {
setBoardLanes((prevBoardLanes) => {
@@ -99,7 +99,16 @@ function ProductionBoardKanbanComponent({ data, bodyshop, refetch, insertAuditTr
// Iterate through the properties of updatedJob and update the corresponding values in currentCard.metadata
Object.keys(updatedJob).forEach((key) => {
if (key in currentCard.metadata && currentCard.metadata[key] !== updatedJob[key]) {
// Normalize date fields by comparing their ISO strings or timestamps
if (key === "updated_at") {
const currentCardDate = dayjs(currentCard.metadata[key]).toISOString();
const updatedJobDate = dayjs(updatedJob[key]).toISOString();
if (currentCardDate !== updatedJobDate) {
console.log(`Updating ${key} from ${currentCardDate} to ${updatedJobDate}`);
currentCard.metadata[key] = updatedJob[key]; // Assign the new value if different
}
} else if (key in currentCard.metadata && currentCard.metadata[key] !== updatedJob[key]) {
console.log(`Updating ${key} from ${currentCard.metadata[key]} to ${updatedJob[key]}`);
currentCard.metadata[key] = updatedJob[key];
}
@@ -132,7 +141,6 @@ function ProductionBoardKanbanComponent({ data, bodyshop, refetch, insertAuditTr
else if (isDataChanged && !isLaneChanged) {
console.log("Case 2: Only Data Changed");
sourceLane.cards[cardIndex] = { ...currentCard, metadata: { ...currentCard.metadata } };
// sourceLane.cards = [...sourceLane.cards]; // Force shallow change for re-render
}
// Case 3: Only the lane has changed
else if (!isDataChanged && isLaneChanged) {