From a55a7c50f3934fa749a00448068b60c15841b9a3 Mon Sep 17 00:00:00 2001 From: "jason.lam" Date: Wed, 14 May 2025 18:21:53 +0800 Subject: [PATCH] update editable search result logic --- .../RoughScheduleDetail/ViewByBomDetails.tsx | 8 +-- .../RoughScheduleDetail/ViewByFGDetails.tsx | 50 +++++++++---------- .../SearchResults/EditableSearchResults.tsx | 47 +++++++++-------- 3 files changed, 52 insertions(+), 53 deletions(-) diff --git a/src/components/RoughScheduleDetail/ViewByBomDetails.tsx b/src/components/RoughScheduleDetail/ViewByBomDetails.tsx index 3f2ea8e..d091eb8 100644 --- a/src/components/RoughScheduleDetail/ViewByBomDetails.tsx +++ b/src/components/RoughScheduleDetail/ViewByBomDetails.tsx @@ -312,10 +312,6 @@ const ViewByBomDetails: React.FC = ({ apiRef, isEdit }) => { }); }; - useEffect(()=>{ - console.log("[debug] pagingController", pagingController) - },[]) - const overallColumns = useMemo[]>( () => [ { @@ -420,7 +416,7 @@ const ViewByBomDetails: React.FC = ({ apiRef, isEdit }) => { setPagingController={updatePagingController} pagingController={pagingController[7]} isAutoPaging={true} - isHideButton={true} + isEditable={false} isEdit={false} /> @@ -436,7 +432,7 @@ const ViewByBomDetails: React.FC = ({ apiRef, isEdit }) => { setPagingController={updatePagingController} pagingController={pagingController[index]} isAutoPaging={true} - isHideButton={true} + isEditable={false} isEdit={isEdit} /> diff --git a/src/components/RoughScheduleDetail/ViewByFGDetails.tsx b/src/components/RoughScheduleDetail/ViewByFGDetails.tsx index 1abc932..9ae79f2 100644 --- a/src/components/RoughScheduleDetail/ViewByFGDetails.tsx +++ b/src/components/RoughScheduleDetail/ViewByFGDetails.tsx @@ -512,41 +512,41 @@ const ViewByFGDetails: React.FC = ({ apiRef, isEdit }) => { const fakeOverallRecords = useMemo( () => [ - { id: 1, code: "PP1080", name: "咖哩汁", lastMonthAvgStock: 2400, safetyStock: 2400, inStockQty: 2400, productionQty: 8400.0, + { id: 1, code: "PP1080", name: "咖哩汁", lastMonthAvgStock: 2400, safetyStock: 2400, inStockQty: 2400, productionQty: 8400.0*7, lines: [ - { id: 1, code: "MH0040", name: "大豆油(1噸/桶)", inStockQty: 54.44 , purchaseQty: 544.4 }, - { id: 2, code: "GI3236", name: "清水(煮過牛腩)", inStockQty: 317.52 , purchaseQty: 3175.2 }, - { id: 3, code: "MG1700", name: "STERILTOM 意大利茄粒", inStockQty: 9.00 , purchaseQty: 90 }, - { id: 4, code: "FA0533", name: "乾蔥茸", inStockQty: 6.04 , purchaseQty: 60.4 }, - { id: 5, code: "FA0210", name: "薑茸", inStockQty: 6.04 , purchaseQty: 60.4 }, - { id: 6, code: "FA0608", name: "粗蒜茸", inStockQty: 6.04 , purchaseQty: 60.4 }, - { id: 7, code: "FA0056", name: "洋蔥肉", inStockQty: 241.98 , purchaseQty: 2419.8 }, - { id: 8, code: "PP1188", name: "咖喱膽", inStockQty: 36.00 , purchaseQty: 360 }, - { id: 9, code: "PP8001", name: "咖哩汁箱料粉", inStockQty: 77.42 , purchaseQty: 774.2 }, - { id: 10, code: "PP1096", name: "白麵撈", inStockQty: 60.00 , purchaseQty: 600 }, - { id: 10, code: "NA0476", name: "2磅份量三邊覆合袋 (0.1x225x260mm)個計", inStockQty: 600.00 , purchaseQty: 6000 }, + { id: 1, code: "MH0040", name: "大豆油(1噸/桶)", inStockQty: 54.44 , purchaseQty: 544.4*7 }, + { id: 2, code: "GI3236", name: "清水(煮過牛腩)", inStockQty: 317.52 , purchaseQty: 3175.2*7 }, + { id: 3, code: "MG1700", name: "STERILTOM 意大利茄粒", inStockQty: 9.00 , purchaseQty: 90*7 }, + { id: 4, code: "FA0533", name: "乾蔥茸", inStockQty: 6.04 , purchaseQty: 60.4*7 }, + { id: 5, code: "FA0210", name: "薑茸", inStockQty: 6.04 , purchaseQty: 60.4*7 }, + { id: 6, code: "FA0608", name: "粗蒜茸", inStockQty: 6.04 , purchaseQty: 60.4*7 }, + { id: 7, code: "FA0056", name: "洋蔥肉", inStockQty: 241.98 , purchaseQty: 2419.8*7 }, + { id: 8, code: "PP1188", name: "咖喱膽", inStockQty: 36.00 , purchaseQty: 360*7 }, + { id: 9, code: "PP8001", name: "咖哩汁箱料粉", inStockQty: 77.42 , purchaseQty: 774.2*7 }, + { id: 10, code: "PP1096", name: "白麵撈", inStockQty: 60.00 , purchaseQty: 600*7 }, + { id: 10, code: "NA0476", name: "2磅份量三邊覆合袋 (0.1x225x260mm)個計", inStockQty: 600.00 , purchaseQty: 6000*7 }, ] }, { id: 2, code: "PP1193", name: "蔥油(1磅) ", lastMonthAvgStock: 1320, safetyStock: 1322, inStockQty: 1322, productionQty: 4627, lines: [ - { id: 2, code: "MH0040", name: "大豆油(1噸/桶)", inStockQty: 0, purchaseQty: 20 }, - { id: 3, code: "FA0161", name: "洋蔥粒", inStockQty: 0, purchaseQty: 10 } + { id: 2, code: "MH0040", name: "大豆油(1噸/桶)", inStockQty: 0, purchaseQty: 20*7 }, + { id: 3, code: "FA0161", name: "洋蔥粒", inStockQty: 0, purchaseQty: 10*7 } ] }, { id: 3, code: " PP1188", name: "咖喱膽", lastMonthAvgStock: 1017, safetyStock: 1017, inStockQty: 1016.2, productionQty: 3556.7, lines: [ - { id: 1, code: "MH0040", name: "大豆油(1噸/桶)", inStockQty: 0, purchaseQty: 217.72 }, - { id: 2, code: "FA0161", name: "洋蔥粒", inStockQty: 0, purchaseQty: 18.15 }, - { id: 3, code: "FA0608", name: "粗蒜茸", inStockQty: 0, purchaseQty: 18.15 }, - { id: 4, code: "MG1288", name: "炸紅蔥頭", inStockQty: 0, purchaseQty: 6.05 }, - { id: 5, code: "FA0210", name: "薑茸", inStockQty: 0, purchaseQty: 6.05 }, - { id: 6, code: "MG0066", name: "咖哩料(5斤x16包+2斤/包)", inStockQty: 0, purchaseQty: 241.98 }, + { id: 1, code: "MH0040", name: "大豆油(1噸/桶)", inStockQty: 0, purchaseQty: 217.72*7 }, + { id: 2, code: "FA0161", name: "洋蔥粒", inStockQty: 0, purchaseQty: 18.15*7 }, + { id: 3, code: "FA0608", name: "粗蒜茸", inStockQty: 0, purchaseQty: 18.15*7 }, + { id: 4, code: "MG1288", name: "炸紅蔥頭", inStockQty: 0, purchaseQty: 6.05*7 }, + { id: 5, code: "FA0210", name: "薑茸", inStockQty: 0, purchaseQty: 6.05*7 }, + { id: 6, code: "MG0066", name: "咖哩料(5斤x16包+2斤/包)", inStockQty: 0, purchaseQty: 241.98*7 }, ] }, { id: 4, code: " PP1096", name: "白麵撈", lastMonthAvgStock: 1040, safetyStock: 1040, inStockQty: 1040, productionQty: 3640, lines: [ - { id: 1, code: "MH0040", name: "大豆油(1噸/桶)", inStockQty: 0, purchaseQty: 190.00 }, - { id: 1, code: "MH0040", name: "星加坡綠富貴花牌幼白麵粉 (50磅/包)", inStockQty: 0, purchaseQty: 250.00 }, + { id: 1, code: "MH0040", name: "大豆油(1噸/桶)", inStockQty: 0, purchaseQty: 190.00*7 }, + { id: 1, code: "MH0040", name: "星加坡綠富貴花牌幼白麵粉 (50磅/包)", inStockQty: 0, purchaseQty: 250.00*7 }, { id: 2, code: "FA0161", name: "蔥油", inStockQty: 1322, purchaseQty: 0 }, ] }, @@ -563,12 +563,11 @@ const ViewByFGDetails: React.FC = ({ apiRef, isEdit }) => { index={7} items={fakeOverallRecords} - isMockUp={true} columns={overallColumns} setPagingController={updatePagingController} pagingController={pagingController[7]} isAutoPaging={false} - isHideButton={true} + isEditable={false} isEdit={isEdit} hasCollapse={true} /> @@ -580,12 +579,11 @@ const ViewByFGDetails: React.FC = ({ apiRef, isEdit }) => { items={fakeRecords[index]} // Use the corresponding records for the day - isMockUp={true} columns={columns} setPagingController={updatePagingController} pagingController={pagingController[index]} isAutoPaging={false} - isHideButton={false} + isEditable={true} isEdit={isEdit} hasCollapse={true} /> diff --git a/src/components/SearchResults/EditableSearchResults.tsx b/src/components/SearchResults/EditableSearchResults.tsx index 2308ab6..9aaa563 100644 --- a/src/components/SearchResults/EditableSearchResults.tsx +++ b/src/components/SearchResults/EditableSearchResults.tsx @@ -45,7 +45,6 @@ export type Column = interface Props { items: T[], - isMockUp?: Boolean, columns: Column[], noWrapper?: boolean, setPagingController: (value: { pageNum: number; pageSize: number; totalCount: number, index?: number}) => void, @@ -56,14 +55,13 @@ interface Props { function EditableSearchResults({ index, items, - isMockUp, columns, noWrapper, pagingController, setPagingController, isAutoPaging = true, - isEdit = true, - isHideButton = false, + isEdit = false, + isEditable = true, hasCollapse = false, }: Props) { const [page, setPage] = useState(0); @@ -132,15 +130,19 @@ function EditableSearchResults({ <> { - !isHideButton && + (isEditable || hasCollapse) && {(editingRowId === row.id) ? ( <> - handleSaveClick(row)}> - - - setEditingRowId(null)}> - - + { + isEditable && handleSaveClick(row)}> + + + } + { + isEditable && setEditingRowId(null)}> + + + } { hasCollapse && ({ ) : ( <> - handleEditClick(row.id as number)}> - - - handleDeleteClick(row.id as number)}> - - + { + isEditable && handleEditClick(row.id as number)}> + + + } + { + isEditable && handleDeleteClick(row.id as number)}> + + + } { hasCollapse && ({ )} - } {columns.map((column, idx) => { console.log(column) @@ -254,7 +259,7 @@ function EditableSearchResults({ - {!isHideButton && Actions} {/* Action Column Header */} + {(isEditable || hasCollapse) && Actions} {/* Action Column Header */} {columns.map((column, idx) => ( {column.label}