responsive columns can now be a column type or a function the returns the type

This commit is contained in:
Carter 2025-02-26 10:56:43 -06:00
parent 80683e29e5
commit d66dc68495
4 changed files with 12 additions and 14 deletions

View file

@ -69,7 +69,7 @@ export interface Column<T> {
interface Props<T> { interface Props<T> {
rows: T[], rows: T[],
columns?: Column<T>[], columns?: Column<T>[] | (() => Column<T>[]),
title?: string | JSX.Element; title?: string | JSX.Element;
subtitle?: string | JSX.Element; subtitle?: string | JSX.Element;
total: number, total: number,
@ -103,7 +103,7 @@ export default function ResponsiveTable<T extends Object>(props: Props<T>) {
setSearchText, setSearchText,
isLoading, isLoading,
multiGutter, multiGutter,
columns, // columns,
rowsPerPageOptions, rowsPerPageOptions,
noDataMessage, noDataMessage,
renderMobile, renderMobile,
@ -112,6 +112,7 @@ export default function ResponsiveTable<T extends Object>(props: Props<T>) {
actions actions
} = props } = props
const classes = useStyles(); const classes = useStyles();
const columns = typeof(props.columns) === "function" ? props.columns() : props.columns
const isMobile = useMobile() const isMobile = useMobile()

View file

@ -24,6 +24,7 @@ import RemoveSelfFromObject from "user/RemoveSelfFromObject";
import ShareObject from "user/ShareObject"; import ShareObject from "user/ShareObject";
import { isOffline } from "utils/environment"; import { isOffline } from "utils/environment";
import { makeStyles } from "@mui/styles"; import { makeStyles } from "@mui/styles";
import ObjectTeams from "teams/ObjectTeams";
// const useStyles = makeStyles((theme: Theme) => { // const useStyles = makeStyles((theme: Theme) => {
// // const isMobile = useMobile() // // const isMobile = useMobile()
@ -166,14 +167,14 @@ export default function GroupActions(props: Props) {
closeDialogCallback={() => setUsersOpen(false)} closeDialogCallback={() => setUsersOpen(false)}
refreshCallback={refreshCallback} refreshCallback={refreshCallback}
/> />
{/* <ObjectTeams <ObjectTeams
scope={groupScope(key)} scope={groupScope(key)}
label={label} label={label}
permissions={permissions} permissions={permissions}
isDialogOpen={teamsOpen} isDialogOpen={teamsOpen}
closeDialogCallback={() => setTeamsOpen(false)} closeDialogCallback={() => setTeamsOpen(false)}
refreshCallback={refreshCallback} refreshCallback={refreshCallback}
/> */} />
<RemoveSelfFromObject <RemoveSelfFromObject
scope={groupScope(key)} scope={groupScope(key)}
label={label} label={label}

View file

@ -303,15 +303,15 @@ export default function Devices() {
render: (device: Device) => { render: (device: Device) => {
if (device.status.plenum?.temperature) { if (device.status.plenum?.temperature) {
return ( return (
<Grid2 container direction="column" margin={1} marginLeft={2}> <Grid2 container direction="column" marginLeft={2}>
<Grid2> <Grid2>
<Typography variant="body2" style={{ color: orange[300]}}> <Typography variant="body2" style={{ color: orange[300]}}>
{device.status.plenum.temperature}°C {device.status.plenum.temperature.toFixed(1)}°C
</Typography> </Typography>
</Grid2> </Grid2>
<Grid2> <Grid2>
<Typography variant="body2" color="info"> <Typography variant="body2" color="info">
{device.status.plenum.humidity}% {device.status.plenum.humidity.toFixed(1)}%
</Typography> </Typography>
</Grid2> </Grid2>
</Grid2> </Grid2>
@ -405,7 +405,7 @@ export default function Devices() {
</Typography> </Typography>
</Grid2> </Grid2>
<Grid2 > <Grid2 >
<Typography marginRight={1}> <Typography style={{ marginRight: 6 }}>
{", "} {", "}
</Typography> </Typography>
</Grid2> </Grid2>
@ -454,8 +454,8 @@ export default function Devices() {
title={<SmartBreadcrumb prependPaths={getGroup() && ["groups", getGroup().id().toString()]} groupName={getGroup() && getGroup().name()} paddingBottom={1}/>} title={<SmartBreadcrumb prependPaths={getGroup() && ["groups", getGroup().id().toString()]} groupName={getGroup() && getGroup().name()} paddingBottom={1}/>}
subtitle={subtitle()} subtitle={subtitle()}
rows={devices} rows={devices}
renderGutter={gutter} renderGutter={ isMobile ? gutter : undefined }
columns={columns()} columns={columns}
renderMobile={mobile} renderMobile={mobile}
total={total} total={total}
pageSize={limit} pageSize={limit}

View file

@ -117,9 +117,6 @@ export default function GroupPage() {
const loadDevices = () => { const loadDevices = () => {
console.log(getContextKeys())
console.log(getContextTypes())
console.log(limit)
setLoadingDevices(true) setLoadingDevices(true)
deviceAPI.list( deviceAPI.list(
limit, limit,
@ -136,7 +133,6 @@ export default function GroupPage() {
getKeys(), getKeys(),
getTypes() getTypes()
).then(resp => { ).then(resp => {
console.log(resp.data)
let newDevices: Device[] = []; let newDevices: Device[] = [];
resp.data.devices.forEach(device => { resp.data.devices.forEach(device => {
newDevices.push(Device.create(device)) newDevices.push(Device.create(device))