Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
15c0fdce82 | ||
|
|
467fbb89c9 |
Vendored
+4207
-4055
File diff suppressed because it is too large
Load Diff
@@ -42,6 +42,13 @@ const Testing = () => {
|
|||||||
columns: ["min_speed", "max_speed"],
|
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
|
multiple
|
||||||
/>
|
/>
|
||||||
</ApiProvider>
|
</ApiProvider>
|
||||||
|
|||||||
+149
-58
@@ -8,11 +8,13 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
List,
|
List,
|
||||||
ListItemButton,
|
ListItemButton,
|
||||||
|
ListItemIcon,
|
||||||
ListItemText,
|
ListItemText,
|
||||||
Typography,
|
Typography,
|
||||||
InputAdornment,
|
InputAdornment,
|
||||||
IconButton,
|
IconButton,
|
||||||
Checkbox
|
Checkbox,
|
||||||
|
CircularProgress,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import ClearIcon from "@mui/icons-material/Clear";
|
import ClearIcon from "@mui/icons-material/Clear";
|
||||||
import FilterTableBuilder from "../utils/filterTableBuilder";
|
import FilterTableBuilder from "../utils/filterTableBuilder";
|
||||||
@@ -38,6 +40,7 @@ export default function ListVirtual({
|
|||||||
multiple,
|
multiple,
|
||||||
customSxTextField = {},
|
customSxTextField = {},
|
||||||
joins = [],
|
joins = [],
|
||||||
|
warningCheck,
|
||||||
}) {
|
}) {
|
||||||
const headersRequest = useApiHeaders();
|
const headersRequest = useApiHeaders();
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
@@ -45,6 +48,7 @@ export default function ListVirtual({
|
|||||||
const [rows, setRows] = useState([]);
|
const [rows, setRows] = useState([]);
|
||||||
const [selected, setSelected] = useState(null);
|
const [selected, setSelected] = useState(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [selectAllLoading, setSelectAllLoading] = useState(false);
|
||||||
const [offset, setOffset] = useState(0);
|
const [offset, setOffset] = useState(0);
|
||||||
const [totalRecord, setTotalRecord] = useState(0);
|
const [totalRecord, setTotalRecord] = useState(0);
|
||||||
|
|
||||||
@@ -221,9 +225,20 @@ export default function ListVirtual({
|
|||||||
getData?.(multiple ? [] : null);
|
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
|
const displayValue = multiple
|
||||||
? (selected?.length > 0
|
? (selected?.length > 1
|
||||||
? `${selected.length} ${label} selected`
|
? `${selected.length} ${label} selected`
|
||||||
|
: selected?.length === 1
|
||||||
|
? selected[0][name]
|
||||||
: "")
|
: "")
|
||||||
: selected?.[name] || "";
|
: selected?.[name] || "";
|
||||||
|
|
||||||
@@ -235,58 +250,76 @@ export default function ListVirtual({
|
|||||||
return (selected || []).some((x) => x.id === row.id);
|
return (selected || []).some((x) => x.id === row.id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Whether every record matching the current search/filter is currently selected
|
||||||
|
const isAllSelected =
|
||||||
|
multiple && totalRecord > 0 && (selected?.length || 0) === totalRecord;
|
||||||
|
|
||||||
|
const isPartiallySelected =
|
||||||
|
multiple && (selected?.length || 0) > 0 && !isAllSelected;
|
||||||
|
|
||||||
const handleSelectAll = async () => {
|
const handleSelectAll = async () => {
|
||||||
setLoading(true);
|
// Toggle off: if everything is already selected, clicking again clears selection
|
||||||
|
if (isAllSelected) {
|
||||||
|
setSelected([]);
|
||||||
|
getData?.([]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const pageSize = 1000;
|
setSelectAllLoading(true);
|
||||||
const requests = [];
|
|
||||||
|
|
||||||
for (let offset = 0; offset < totalRecord; offset += pageSize) {
|
try {
|
||||||
const payload = new FilterTableBuilder()
|
const pageSize = 1000;
|
||||||
.setPaging(offset, pageSize)
|
const requests = [];
|
||||||
.setOrder([name], true);
|
|
||||||
|
|
||||||
if (search) {
|
for (let pageOffset = 0; pageOffset < totalRecord; pageOffset += pageSize) {
|
||||||
payload.like(name, search);
|
const payload = new FilterTableBuilder()
|
||||||
}
|
.setPaging(pageOffset, pageSize)
|
||||||
|
.setOrder([name], true);
|
||||||
|
|
||||||
if (filter?.length) {
|
if (search) {
|
||||||
filter.forEach(f =>
|
payload.like(name, search);
|
||||||
payload.where(
|
}
|
||||||
f.logic_operator || "=",
|
|
||||||
f.name,
|
if (filter?.length) {
|
||||||
f.value,
|
filter.forEach(f =>
|
||||||
f.operator || "AND",
|
payload.where(
|
||||||
f.value1 || null,
|
f.logic_operator || "=",
|
||||||
f.table_name || null
|
f.name,
|
||||||
|
f.value,
|
||||||
|
f.operator || "AND",
|
||||||
|
f.value1 || null,
|
||||||
|
f.table_name || null
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
joins.forEach(join => {
|
||||||
|
payload.addJoin(join.table, join.columns);
|
||||||
|
});
|
||||||
|
|
||||||
|
requests.push(
|
||||||
|
apiRequest.search(
|
||||||
|
url,
|
||||||
|
payload.build(),
|
||||||
|
{
|
||||||
|
headers: headersRequest,
|
||||||
|
},
|
||||||
|
isApiGo
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
joins.forEach(join => {
|
const responses = await Promise.all(requests);
|
||||||
payload.addJoin(join.table, join.columns);
|
|
||||||
});
|
|
||||||
|
|
||||||
requests.push(
|
const allRows = responses.flatMap(res => res.data || []);
|
||||||
apiRequest.search(
|
|
||||||
url,
|
setSelected(allRows);
|
||||||
payload.build(),
|
getData?.(allRows);
|
||||||
{
|
} catch (err) {
|
||||||
headers: headersRequest,
|
console.error("Select All Error:", err);
|
||||||
},
|
} finally {
|
||||||
isApiGo
|
setSelectAllLoading(false);
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const responses = await Promise.all(requests);
|
|
||||||
|
|
||||||
const allRows = responses.flatMap(res => res.data || []);
|
|
||||||
|
|
||||||
setSelected(allRows);
|
|
||||||
getData?.(allRows);
|
|
||||||
|
|
||||||
setLoading(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -365,27 +398,75 @@ export default function ListVirtual({
|
|||||||
|
|
||||||
<List disablePadding>
|
<List disablePadding>
|
||||||
<>
|
<>
|
||||||
{multiple && (
|
{multiple && rows.length > 0 && (
|
||||||
<ListItemButton
|
<ListItemButton
|
||||||
onClick={handleSelectAll}
|
onClick={handleSelectAll}
|
||||||
|
disabled={selectAllLoading || totalRecord === 0}
|
||||||
sx={{ fontSize: 14 }}
|
sx={{ fontSize: 14 }}
|
||||||
>
|
>
|
||||||
Select All
|
<ListItemIcon sx={{ minWidth: 36 }}>
|
||||||
|
{selectAllLoading ? (
|
||||||
|
<CircularProgress size={18} />
|
||||||
|
) : (
|
||||||
|
<Checkbox
|
||||||
|
edge="start"
|
||||||
|
checked={isAllSelected}
|
||||||
|
indeterminate={isPartiallySelected}
|
||||||
|
tabIndex={-1}
|
||||||
|
disableRipple
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText
|
||||||
|
primary={
|
||||||
|
selectAllLoading
|
||||||
|
? "Selecting all..."
|
||||||
|
: isAllSelected
|
||||||
|
? "Unselect All"
|
||||||
|
: "Select All"
|
||||||
|
}
|
||||||
|
/>
|
||||||
</ListItemButton>
|
</ListItemButton>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{rows.map((row, i) => (
|
{rows.map((row, i) => {
|
||||||
<ListItemButton
|
const warning = getRowWarning(row);
|
||||||
key={`${row.id}-${i}`}
|
|
||||||
onClick={() => handleSelect(row)}
|
|
||||||
>
|
|
||||||
{multiple && (
|
|
||||||
<Checkbox checked={isSelected(row)} />
|
|
||||||
)}
|
|
||||||
|
|
||||||
<ListItemText primary={row[name]} secondary={row.join?.company_name} />
|
return (
|
||||||
</ListItemButton>
|
<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 && (
|
{loading && (
|
||||||
<Typography variant="caption" sx={{ display: 'block', textAlign: 'center', p: 1 }}>
|
<Typography variant="caption" sx={{ display: 'block', textAlign: 'center', p: 1 }}>
|
||||||
@@ -403,8 +484,18 @@ export default function ListVirtual({
|
|||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button onClick={handleClear} size="small">Clear</Button>
|
<Button onClick={handleClear} disabled={selectAllLoading}>Clear</Button>
|
||||||
<Button onClick={() => setOpen(false)} size="small">Cancel</Button>
|
<Button onClick={() => setOpen(false)}>Cancel</Button>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
getData?.(selected ?? (multiple ? [] : null));
|
||||||
|
setOpen(false);
|
||||||
|
}}
|
||||||
|
variant="contained"
|
||||||
|
disabled={selectAllLoading}
|
||||||
|
>
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</>
|
</>
|
||||||
|
|||||||
+1
-1
@@ -60,7 +60,7 @@ const theme = createTheme({
|
|||||||
MuiOutlinedInput: {
|
MuiOutlinedInput: {
|
||||||
styleOverrides: {
|
styleOverrides: {
|
||||||
root: {
|
root: {
|
||||||
borderRadius: 12
|
borderRadius: 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user