feat: ListVirtual with additional warning check
This commit is contained in:
Vendored
+2874
-2839
File diff suppressed because it is too large
Load Diff
@@ -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>
|
||||
|
||||
@@ -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 }}>
|
||||
|
||||
Reference in New Issue
Block a user