From 2bf24ff5a1fcac0dd01dd0d62bd123b33d4aff47 Mon Sep 17 00:00:00 2001 From: swtmply Date: Thu, 4 May 2023 23:00:37 +0800 Subject: [PATCH] IO-1722 refactor color function --- ...production-board-kanban-card.component.jsx | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/client/src/components/production-board-kanban-card/production-board-kanban-card.component.jsx b/client/src/components/production-board-kanban-card/production-board-kanban-card.component.jsx index 7a16ebdc0..cb955a9c6 100644 --- a/client/src/components/production-board-kanban-card/production-board-kanban-card.component.jsx +++ b/client/src/components/production-board-kanban-card/production-board-kanban-card.component.jsx @@ -18,14 +18,16 @@ import moment from "moment"; import OwnerNameDisplay from "../owner-name-display/owner-name-display.component"; import JobPartsQueueCount from "../job-parts-queue-count/job-parts-queue-count.component"; -const cardColor = (job_sizes, totalHrs) => { - for (const size of job_sizes) { - if (totalHrs <= (size.lt || 999) && totalHrs >= size.gte) { - if (size.color) { - return size.color.hex; - } - } +const cardColor = (ssbuckets, totalHrs) => { + const bucket = ssbuckets.filter( + (bucket) => + bucket.gte <= totalHrs && (!!bucket.lt ? bucket.lt > totalHrs : true) + )[0]; + + if (bucket.color) { + return bucket.color.hex; } + return ""; }; @@ -76,18 +78,16 @@ export default function ProductionBoardCard( const totalHrs = card.labhrs.aggregate.sum.mod_lb_hrs + card.larhrs.aggregate.sum.mod_lb_hrs; + const bgColor = cardColor(bodyshop.ssbuckets, totalHrs); return (