From 88b313b9d8c4f898847ded78ab1673f5cb8e5dd2 Mon Sep 17 00:00:00 2001 From: Dave Richer Date: Thu, 12 Sep 2024 17:50:00 -0400 Subject: [PATCH] feature/IO-2924-Refactor-Production-Board-For-Sockets - Checkpoint Signed-off-by: Dave Richer --- .../production-board-kanban.component.jsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/client/src/components/production-board-kanban/production-board-kanban.component.jsx b/client/src/components/production-board-kanban/production-board-kanban.component.jsx index f7f76a69c..972f2f1d3 100644 --- a/client/src/components/production-board-kanban/production-board-kanban.component.jsx +++ b/client/src/components/production-board-kanban/production-board-kanban.component.jsx @@ -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) {