diff --git a/src/components/pages/production/recording/RecordingTable.tsx b/src/components/pages/production/recording/RecordingTable.tsx index 3a7defb3..f4703c89 100644 --- a/src/components/pages/production/recording/RecordingTable.tsx +++ b/src/components/pages/production/recording/RecordingTable.tsx @@ -542,12 +542,39 @@ const RecordingTable = () => { if (!recording || isRecordingApproved(recording)) return false; if (recording.project_flock_category === 'LAYING') { - return isGradingCompleted(recording); + return false; } - return true; + return recording.project_flock_category === 'GROWING'; }); - }, [selectedRowIds, recordings, isRecordingApproved, isGradingCompleted]); + }, [selectedRowIds, recordings, isRecordingApproved]); + + useEffect(() => { + if (isResponseSuccess(recordings) && recordings.data) { + const newSelection: Record = {}; + + Object.entries(rowSelection).forEach(([rowId, isSelected]) => { + if (isSelected) { + const recording = recordings.data.find( + (r) => r.id === parseInt(rowId) + ); + if ( + recording && + recording.project_flock_category === 'GROWING' && + !isRecordingApproved(recording) + ) { + newSelection[rowId] = true; + } + } + }); + + if ( + Object.keys(newSelection).length !== Object.keys(rowSelection).length + ) { + setRowSelection(newSelection); + } + } + }, [recordings, rowSelection, isRecordingApproved, setRowSelection]); return (
@@ -579,7 +606,7 @@ const RecordingTable = () => { className='w-full sm:w-fit' title={ eligibleRowIds.length === 0 - ? 'Tidak ada Recording yang bisa disetujui (sudah disetujui final atau belum grading untuk kategori LAYING)' + ? 'Hanya recording GROWING yang bisa disetujui' : '' } > @@ -600,7 +627,7 @@ const RecordingTable = () => { className='w-full sm:w-fit' title={ eligibleRowIds.length === 0 - ? 'Tidak ada Recording yang bisa ditolak (sudah disetujui final atau belum grading untuk kategori LAYING)' + ? 'Hanya recording GROWING yang bisa ditolak' : '' } > @@ -643,30 +670,57 @@ const RecordingTable = () => { id: 'select', header: ({ table }) => { const allRows = table.getRowModel().rows; - const selectableRows = allRows.filter((row) => { + + const selectableGrowingRows = allRows.filter((row) => { const recording = row.original; - if (isRecordingApproved(recording)) return false; - - if (recording.project_flock_category === 'LAYING') { - return isGradingCompleted(recording); - } - - return true; + return ( + recording.project_flock_category === 'GROWING' && + !isRecordingApproved(recording) + ); }); - const hasOnlyUnselectableRows = selectableRows.length === 0; + + const hasNoSelectableGrowing = selectableGrowingRows.length === 0; + + const handleSelectAllGrowing = () => { + const isAllSelected = selectableGrowingRows.every((row) => + row.getIsSelected() + ); + + allRows.forEach((row) => { + const recording = row.original; + if ( + recording.project_flock_category === 'GROWING' && + !isRecordingApproved(recording) + ) { + row.toggleSelected(!isAllSelected); + } else if (recording.project_flock_category === 'LAYING') { + row.toggleSelected(false); + } + }); + }; + + const isAllGrowingSelected = + selectableGrowingRows.length > 0 && + selectableGrowingRows.every((row) => row.getIsSelected()); + + const isSomeGrowingSelected = selectableGrowingRows.some((row) => + row.getIsSelected() + ); return (
@@ -674,21 +728,18 @@ const RecordingTable = () => { }, cell: ({ row }) => { const isApproved = isRecordingApproved(row.original); - const isGradingDone = isGradingCompleted(row.original); const isLayingCategory = row.original.project_flock_category === 'LAYING'; - const isDisabled = - !row.getCanSelect() || - isApproved || - (isLayingCategory && !isGradingDone); + if (isLayingCategory) { + return null; + } + + const isDisabled = !row.getCanSelect() || isApproved; let tooltip = ''; if (isApproved) { tooltip = 'Recording sudah disetujui final'; - } else if (isLayingCategory && !isGradingDone) { - tooltip = - 'Recording LAYING belum bisa dipilih karena grading telur belum selesai'; } return ( @@ -809,19 +860,19 @@ const RecordingTable = () => { ); }, }, - { - header: 'Status Grading Telur', - cell: (props) => { - const status = props.row.original.egg_grading_status; - if (!status) return '-'; - const color = status === 'COMPLETED' ? 'success' : 'warning'; - return ( - - {status} - - ); - }, - }, + // { + // header: 'Status Grading Telur', + // cell: (props) => { + // const status = props.row.original.egg_grading_status; + // if (!status) return '-'; + // const color = status === 'COMPLETED' ? 'success' : 'warning'; + // return ( + // + // {status} + // + // ); + // }, + // }, { header: 'Dibuat Oleh', cell: (props) => props.row.original.created_user?.name || '-',