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.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 (
<div className='w-full p-0 sm:p-4'>
@@ -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 (
<div className='w-full flex flex-row justify-center'>
<CheckboxInput
name='allRow'
checked={table.getIsAllRowsSelected()}
indeterminate={table.getIsSomeRowsSelected()}
onChange={table.getToggleAllRowsSelectedHandler()}
disabled={hasOnlyUnselectableRows}
checked={isAllGrowingSelected}
indeterminate={
isSomeGrowingSelected && !isAllGrowingSelected
}
onChange={handleSelectAllGrowing}
disabled={hasNoSelectableGrowing}
title={
hasOnlyUnselectableRows
? 'Tidak ada Recording yang bisa dipilih (sudah disetujui final atau belum grading untuk kategori LAYING)'
: ''
hasNoSelectableGrowing
? 'Tidak ada recording GROWING yang bisa dipilih'
: 'Pilih semua recording GROWING'
}
/>
</div>
@@ -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 (
<Badge variant='soft' color={color}>
{status}
</Badge>
);
},
},
// {
// header: 'Status Grading Telur',
// cell: (props) => {
// const status = props.row.original.egg_grading_status;
// if (!status) return '-';
// const color = status === 'COMPLETED' ? 'success' : 'warning';
// return (
// <Badge variant='soft' color={color}>
// {status}
// </Badge>
// );
// },
// },
{
header: 'Dibuat Oleh',
cell: (props) => props.row.original.created_user?.name || '-',