feat(FE-170,174): update RecordingTable to restrict selection and approval to GROWING category only

This commit is contained in:
rstubryan
2025-11-19 19:34:46 +07:00
parent 7e58e46254
commit 427887a0e0
@@ -542,12 +542,39 @@ const RecordingTable = () => {
if (!recording || isRecordingApproved(recording)) return false; if (!recording || isRecordingApproved(recording)) return false;
if (recording.project_flock_category === 'LAYING') { 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<string, boolean> = {};
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 ( return (
<div className='w-full p-0 sm:p-4'> <div className='w-full p-0 sm:p-4'>
@@ -579,7 +606,7 @@ const RecordingTable = () => {
className='w-full sm:w-fit' className='w-full sm:w-fit'
title={ title={
eligibleRowIds.length === 0 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' className='w-full sm:w-fit'
title={ title={
eligibleRowIds.length === 0 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', id: 'select',
header: ({ table }) => { header: ({ table }) => {
const allRows = table.getRowModel().rows; const allRows = table.getRowModel().rows;
const selectableRows = allRows.filter((row) => {
const selectableGrowingRows = allRows.filter((row) => {
const recording = row.original; const recording = row.original;
if (isRecordingApproved(recording)) return false; return (
recording.project_flock_category === 'GROWING' &&
if (recording.project_flock_category === 'LAYING') { !isRecordingApproved(recording)
return isGradingCompleted(recording); );
}
return true;
}); });
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 ( return (
<div className='w-full flex flex-row justify-center'> <div className='w-full flex flex-row justify-center'>
<CheckboxInput <CheckboxInput
name='allRow' name='allRow'
checked={table.getIsAllRowsSelected()} checked={isAllGrowingSelected}
indeterminate={table.getIsSomeRowsSelected()} indeterminate={
onChange={table.getToggleAllRowsSelectedHandler()} isSomeGrowingSelected && !isAllGrowingSelected
disabled={hasOnlyUnselectableRows} }
onChange={handleSelectAllGrowing}
disabled={hasNoSelectableGrowing}
title={ title={
hasOnlyUnselectableRows hasNoSelectableGrowing
? 'Tidak ada Recording yang bisa dipilih (sudah disetujui final atau belum grading untuk kategori LAYING)' ? 'Tidak ada recording GROWING yang bisa dipilih'
: '' : 'Pilih semua recording GROWING'
} }
/> />
</div> </div>
@@ -674,21 +728,18 @@ const RecordingTable = () => {
}, },
cell: ({ row }) => { cell: ({ row }) => {
const isApproved = isRecordingApproved(row.original); const isApproved = isRecordingApproved(row.original);
const isGradingDone = isGradingCompleted(row.original);
const isLayingCategory = const isLayingCategory =
row.original.project_flock_category === 'LAYING'; row.original.project_flock_category === 'LAYING';
const isDisabled = if (isLayingCategory) {
!row.getCanSelect() || return null;
isApproved || }
(isLayingCategory && !isGradingDone);
const isDisabled = !row.getCanSelect() || isApproved;
let tooltip = ''; let tooltip = '';
if (isApproved) { if (isApproved) {
tooltip = 'Recording sudah disetujui final'; tooltip = 'Recording sudah disetujui final';
} else if (isLayingCategory && !isGradingDone) {
tooltip =
'Recording LAYING belum bisa dipilih karena grading telur belum selesai';
} }
return ( return (
@@ -809,19 +860,19 @@ const RecordingTable = () => {
); );
}, },
}, },
{ // {
header: 'Status Grading Telur', // header: 'Status Grading Telur',
cell: (props) => { // cell: (props) => {
const status = props.row.original.egg_grading_status; // const status = props.row.original.egg_grading_status;
if (!status) return '-'; // if (!status) return '-';
const color = status === 'COMPLETED' ? 'success' : 'warning'; // const color = status === 'COMPLETED' ? 'success' : 'warning';
return ( // return (
<Badge variant='soft' color={color}> // <Badge variant='soft' color={color}>
{status} // {status}
</Badge> // </Badge>
); // );
}, // },
}, // },
{ {
header: 'Dibuat Oleh', header: 'Dibuat Oleh',
cell: (props) => props.row.original.created_user?.name || '-', cell: (props) => props.row.original.created_user?.name || '-',