From 802020318c6380335f9497f837690ad7b3e8e7d3 Mon Sep 17 00:00:00 2001 From: "PC-20260115JRSN\\Administrator" Date: Tue, 1 Sep 2026 00:32:11 +0800 Subject: [PATCH] fixing the job status filder --- .../DrinkProductionQtyDashboard.tsx | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/src/components/ProductionProcess/DrinkProductionQtyDashboard.tsx b/src/components/ProductionProcess/DrinkProductionQtyDashboard.tsx index a99d3607..c6bb8d31 100644 --- a/src/components/ProductionProcess/DrinkProductionQtyDashboard.tsx +++ b/src/components/ProductionProcess/DrinkProductionQtyDashboard.tsx @@ -1,5 +1,5 @@ "use client"; -import React, { useState, useEffect, useCallback, useRef } from "react"; +import React, { useState, useEffect, useCallback, useMemo, useRef } from "react"; import { Box, Typography, @@ -209,12 +209,32 @@ const DrinkProductionQtyDashboard: React.FC = () => { }); }; - const filterJobOrders = ( - jobOrders: DrinkProductionQtyJobOrderDetail[], - ): DrinkProductionQtyJobOrderDetail[] => { - if (!joStatusFilter) return jobOrders; - return jobOrders.filter((jo) => jo.jobOrderStatus === joStatusFilter); - }; + const filteredItemRows = useMemo(() => { + const rows: Array<{ + row: DrinkProductionQtyResponse; + jobOrders: DrinkProductionQtyJobOrderDetail[]; + totalReqQty: number; + totalQty: number; + }> = []; + for (const row of data) { + const allJobOrders = row.jobOrders ?? []; + const jobOrders = joStatusFilter + ? allJobOrders.filter((jo) => jo.jobOrderStatus === joStatusFilter) + : allJobOrders; + if (joStatusFilter && jobOrders.length === 0) continue; + rows.push({ + row, + jobOrders, + totalReqQty: joStatusFilter + ? jobOrders.reduce((sum, jo) => sum + (jo.reqQty ?? 0), 0) + : row.totalReqQty, + totalQty: joStatusFilter + ? jobOrders.reduce((sum, jo) => sum + (jo.productionQty ?? 0), 0) + : row.totalQty, + }); + } + return rows; + }, [data, joStatusFilter]); const renderActualEnd = (jo: DrinkProductionQtyJobOrderDetail) => { const start = parseProcessTime(jo.startTime); @@ -611,7 +631,7 @@ const DrinkProductionQtyDashboard: React.FC = () => { ); }) ) - ) : data.length === 0 ? ( + ) : filteredItemRows.length === 0 ? ( { ) : ( - data.map((row, idx) => { + filteredItemRows.map(({ row, jobOrders, totalReqQty, totalQty }, idx) => { const rowKey = getRowKey(row, idx); - const allJobOrders = row.jobOrders ?? []; - const jobOrders = filterJobOrders(allJobOrders); const isExpanded = expandedRowKeys.has(rowKey); - const hasExpandable = - allJobOrders.length > 0 && - (joStatusFilter === "" || jobOrders.length > 0); + const hasExpandable = jobOrders.length > 0; return ( @@ -671,12 +687,12 @@ const DrinkProductionQtyDashboard: React.FC = () => { - {formatQty(row.totalReqQty)} + {formatQty(totalReqQty)} - {formatQty(row.totalQty)} + {formatQty(totalQty)}