Skip to content

Commit

Permalink
Fix/doors pagination (#803)
Browse files Browse the repository at this point in the history
* Fix indexing of doors for entire building, minor refactor

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Turn off sorting for unrelated columns, sort names by default for robot, doors and lifts

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

---------

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
  • Loading branch information
aaronchongth authored Oct 12, 2023
1 parent 67ed39b commit f2df563
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 21 deletions.
39 changes: 19 additions & 20 deletions packages/dashboard/src/components/doors-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getApiErrorMessage } from './utils';
export const DoorsApp = createMicroApp('Doors', () => {
const rmf = React.useContext(RmfAppContext);
const [buildingMap, setBuildingMap] = React.useState<BuildingMap | null>(null);
const [doorTableData, setDoorTableData] = React.useState<Record<string, DoorTableData[]>>({});
const [doorTableData, setDoorTableData] = React.useState<Record<string, DoorTableData>>({});

React.useEffect(() => {
if (!rmf) {
Expand All @@ -24,6 +24,7 @@ export const DoorsApp = createMicroApp('Doors', () => {
return;
}

let doorIndex = 0;
buildingMap?.levels.map((level) =>
level.doors.map(async (door, i) => {
try {
Expand All @@ -33,24 +34,22 @@ export const DoorsApp = createMicroApp('Doors', () => {
setDoorTableData((prev) => {
return {
...prev,
[door.name]: [
{
index: i,
doorName: door.name,
opMode: health_status ? health_status : 'N/A',
levelName: level.name,
doorType: door.door_type,
doorState: doorState,
onClickOpen: () =>
rmf?.doorsApi.postDoorRequestDoorsDoorNameRequestPost(door.name, {
mode: RmfDoorMode.MODE_OPEN,
}),
onClickClose: () =>
rmf?.doorsApi.postDoorRequestDoorsDoorNameRequestPost(door.name, {
mode: RmfDoorMode.MODE_CLOSED,
}),
},
],
[door.name]: {
index: doorIndex++,
doorName: door.name,
opMode: health_status ? health_status : 'N/A',
levelName: level.name,
doorType: door.door_type,
doorState: doorState,
onClickOpen: () =>
rmf?.doorsApi.postDoorRequestDoorsDoorNameRequestPost(door.name, {
mode: RmfDoorMode.MODE_OPEN,
}),
onClickClose: () =>
rmf?.doorsApi.postDoorRequestDoorsDoorNameRequestPost(door.name, {
mode: RmfDoorMode.MODE_CLOSED,
}),
},
};
});
});
Expand All @@ -62,5 +61,5 @@ export const DoorsApp = createMicroApp('Doors', () => {
);
}, [rmf, buildingMap]);

return <DoorDataGridTable doors={Object.values(doorTableData).flatMap((d) => d)} />;
return <DoorDataGridTable doors={Object.values(doorTableData)} />;
});
12 changes: 11 additions & 1 deletion packages/react-components/lib/doors/door-table-datagrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export function DoorDataGridTable({ doors }: DoorDataGridTableProps): JSX.Elemen
flex: 1,
renderCell: OpModeState,
filterable: true,
sortable: false,
},
{
field: 'levelName',
Expand All @@ -160,6 +161,7 @@ export function DoorDataGridTable({ doors }: DoorDataGridTableProps): JSX.Elemen
valueGetter: (params: GridValueGetterParams) => params.row.levelName,
flex: 1,
filterable: true,
sortable: false,
},
{
field: 'doorType',
Expand All @@ -169,6 +171,7 @@ export function DoorDataGridTable({ doors }: DoorDataGridTableProps): JSX.Elemen
valueGetter: (params: GridValueGetterParams) => doorTypeToString(params.row.doorType),
flex: 1,
filterable: true,
sortable: false,
},
{
field: 'doorState',
Expand All @@ -178,6 +181,7 @@ export function DoorDataGridTable({ doors }: DoorDataGridTableProps): JSX.Elemen
flex: 1,
renderCell: DoorState,
filterable: true,
sortable: false,
},
{
field: '-',
Expand All @@ -186,7 +190,8 @@ export function DoorDataGridTable({ doors }: DoorDataGridTableProps): JSX.Elemen
editable: false,
renderCell: OpenCloseButtons,
flex: 1,
filterable: true,
filterable: false,
sortable: false,
},
];

Expand All @@ -203,6 +208,11 @@ export function DoorDataGridTable({ doors }: DoorDataGridTableProps): JSX.Elemen
localeText={{
noRowsLabel: 'No doors available.',
}}
initialState={{
sorting: {
sortModel: [{ field: 'doorName', sort: 'asc' }],
},
}}
/>
</div>
);
Expand Down
6 changes: 6 additions & 0 deletions packages/react-components/lib/lifts/lift-table-datagrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export function LiftDataGridTable({ lifts }: LiftDataGridTableProps): JSX.Elemen
flex: 1,
renderCell: LiftControl,
filterable: true,
sortable: false,
},
];

Expand All @@ -211,6 +212,11 @@ export function LiftDataGridTable({ lifts }: LiftDataGridTableProps): JSX.Elemen
localeText={{
noRowsLabel: 'No lifts available.',
}}
initialState={{
sorting: {
sortModel: [{ field: 'name', sort: 'asc' }],
},
}}
/>
</div>
);
Expand Down
5 changes: 5 additions & 0 deletions packages/react-components/lib/robots/robot-table-datagrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ export function RobotDataGridTable({ onRobotClick, robots }: RobotDataGridTableP
columns={columns}
rowsPerPageOptions={[5]}
onRowClick={handleEvent}
initialState={{
sorting: {
sortModel: [{ field: 'name', sort: 'asc' }],
},
}}
/>
);
}

0 comments on commit f2df563

Please sign in to comment.