fixes for mobile view broken
This commit is contained in:
@@ -130,6 +130,15 @@ export default function EnhancedTable({
|
|||||||
return cols;
|
return cols;
|
||||||
}, [config, onDelete, navigate, onNavigateToResource]);
|
}, [config, onDelete, navigate, onNavigateToResource]);
|
||||||
|
|
||||||
|
const mobilePageSize = 10;
|
||||||
|
const [mobilePage, setMobilePage] = React.useState(0);
|
||||||
|
const mobileTotalPages = Math.ceil(data.length / mobilePageSize) || 1;
|
||||||
|
const mobileData = data.slice(mobilePage * mobilePageSize, (mobilePage + 1) * mobilePageSize);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (mobilePage >= mobileTotalPages) setMobilePage(0);
|
||||||
|
}, [data.length, mobilePage, mobileTotalPages]);
|
||||||
|
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
@@ -140,7 +149,7 @@ export default function EnhancedTable({
|
|||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
|
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
|
||||||
{data.map((row) => (
|
{mobileData.map((row) => (
|
||||||
<Box key={row[config.primaryKey] || Math.random()}>
|
<Box key={row[config.primaryKey] || Math.random()}>
|
||||||
<MobileCardRow
|
<MobileCardRow
|
||||||
row={row}
|
row={row}
|
||||||
@@ -153,6 +162,17 @@ export default function EnhancedTable({
|
|||||||
</Box>
|
</Box>
|
||||||
))}
|
))}
|
||||||
</Box>
|
</Box>
|
||||||
|
<Box sx={{ display: 'flex', justifyContent: 'center', gap: 1, mt: 2, flexWrap: 'wrap' }}>
|
||||||
|
<Button size="small" disabled={mobilePage === 0} onClick={() => setMobilePage(mobilePage - 1)}>
|
||||||
|
Previous
|
||||||
|
</Button>
|
||||||
|
<Typography variant="body2" sx={{ alignSelf: 'center', px: 1 }}>
|
||||||
|
Page {mobilePage + 1} of {mobileTotalPages}
|
||||||
|
</Typography>
|
||||||
|
<Button size="small" disabled={mobilePage >= mobileTotalPages - 1} onClick={() => setMobilePage(mobilePage + 1)}>
|
||||||
|
Next
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -240,7 +260,7 @@ function MobileCardRow({ row, config, onDelete, onNavigate, navigate }: any) {
|
|||||||
<Typography variant="caption" color="text.secondary" sx={{ display: 'block' }}>
|
<Typography variant="caption" color="text.secondary" sx={{ display: 'block' }}>
|
||||||
{field.label}
|
{field.label}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography variant="body2" sx={{ fontWeight: 500, wordBreak: 'break-all' }}>
|
<Typography variant="body2" component="div" sx={{ fontWeight: 500, wordBreak: 'break-all' }}>
|
||||||
<FieldRenderer params={{ value: row[key], row }} field={field} fieldKey={key} config={config} onNavigate={onNavigate} navigate={navigate} isMobile />
|
<FieldRenderer params={{ value: row[key], row }} field={field} fieldKey={key} config={config} onNavigate={onNavigate} navigate={navigate} isMobile />
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -5,10 +5,6 @@ import {
|
|||||||
Paper,
|
Paper,
|
||||||
TextField,
|
TextField,
|
||||||
Autocomplete,
|
Autocomplete,
|
||||||
Select,
|
|
||||||
MenuItem,
|
|
||||||
FormControl,
|
|
||||||
InputLabel,
|
|
||||||
Typography,
|
Typography,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import FilterListIcon from "@mui/icons-material/FilterList";
|
import FilterListIcon from "@mui/icons-material/FilterList";
|
||||||
@@ -59,7 +55,7 @@ function extractOptions(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('extracted', fieldName, Array.from(values).sort())
|
// console.log('extracted', fieldName, Array.from(values).sort())
|
||||||
return Array.from(values).sort();
|
return Array.from(values).sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,7 +241,8 @@ export default function FilterBar({
|
|||||||
const field = fields[fieldName];
|
const field = fields[fieldName];
|
||||||
if (!field) return null;
|
if (!field) return null;
|
||||||
|
|
||||||
const options = extractOptions(fieldName, field, data ?? []);
|
const needsOptions = !field.filterType || field.filterType === "autocomplete" || field.filterType === "multiselect";
|
||||||
|
const options = needsOptions ? extractOptions(fieldName, field, data ?? []) : [];
|
||||||
const raw = draft[fieldName];
|
const raw = draft[fieldName];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user