feat: ListVirtual with additional warning check

This commit is contained in:
2026-08-27 15:04:42 +07:00
parent 467fbb89c9
commit 15c0fdce82
3 changed files with 2928 additions and 2851 deletions
+7
View File
@@ -42,6 +42,13 @@ const Testing = () => {
columns: ["min_speed", "max_speed"],
},
]}
warningCheck={(row) =>
row.vehicle_type_height_dimension <= 0 ||
row.vehicle_type_length_dimension <= 0 ||
row.vehicle_type_width_dimension <= 0
? "No compatible capacity"
: null
}
multiple
/>
</ApiProvider>
+47 -12
View File
@@ -40,6 +40,7 @@ export default function ListVirtual({
multiple,
customSxTextField = {},
joins = [],
warningCheck,
}) {
const headersRequest = useApiHeaders();
const [open, setOpen] = useState(false);
@@ -224,6 +225,15 @@ export default function ListVirtual({
getData?.(multiple ? [] : null);
};
// NEW: helper untuk memanggil warningCheck dengan aman
const getRowWarning = useCallback(
(row) => {
if (typeof warningCheck !== "function") return null;
return warningCheck(row) || null;
},
[warningCheck]
);
const displayValue = multiple
? (selected?.length > 1
? `${selected.length} ${label} selected`
@@ -419,19 +429,44 @@ export default function ListVirtual({
</ListItemButton>
)}
{rows.map((row, i) => (
<ListItemButton
key={`${row.id}-${i}`}
onClick={() => handleSelect(row)}
disabled={selectAllLoading}
>
{multiple && (
<Checkbox checked={isSelected(row)} />
)}
{rows.map((row, i) => {
const warning = getRowWarning(row);
<ListItemText primary={row[name]} secondary={row.join?.company_name} />
</ListItemButton>
))}
return (
<ListItemButton
key={`${row.id}-${i}`}
onClick={() => handleSelect(row)}
disabled={selectAllLoading}
>
{multiple && (
<Checkbox checked={isSelected(row)} />
)}
<ListItemText
primary={
<Typography
component="span"
sx={{
fontSize: 14,
color: warning ? "error.main" : "text.primary",
}}
>
{row[name]}
{warning && (
<Typography
component="span"
sx={{ fontSize: 12, color: "error.main", ml: 0.5 }}
>
{" "}| {warning}
</Typography>
)}
</Typography>
}
secondary={row.join?.company_name}
/>
</ListItemButton>
);
})}
{loading && (
<Typography variant="caption" sx={{ display: 'block', textAlign: 'center', p: 1 }}>