Skip to content

Commit 56242e2

Browse files
authored
Merge pull request #1413 from rit-construct-makerspace/main
History Page Fix
2 parents 7fe57e2 + 5876903 commit 56242e2

2 files changed

Lines changed: 49 additions & 53 deletions

File tree

client/src/pages/lab_management/audit_logs/AuditLogsPage.tsx

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { ChangeEvent, useEffect, useState } from "react";
1+
import React, { ChangeEvent, useEffect, useMemo, useState } from "react";
22
import {
33
Box,
44
Button,
@@ -9,6 +9,7 @@ import {
99
FormControlLabel,
1010
FormGroup,
1111
IconButton,
12+
LinearProgress,
1213
Stack,
1314
TextField,
1415
ToggleButton,
@@ -162,6 +163,10 @@ export default function LogPage() {
162163
const showClearButton =
163164
startDateString || stopDateString || search.includes("q=");
164165

166+
const logs = useMemo(() => {
167+
return queryResult.data ? queryResult.data.makerspaceLogs : undefined;
168+
}, [queryResult.data, queryResult.data?.makerspaceLogs])
169+
165170
return (
166171
<Box margin="25px">
167172
<title>{`History | ${makeTheme.title}`}</title>
@@ -277,27 +282,23 @@ export default function LogPage() {
277282
</Stack>
278283
</Collapse>
279284
</Card>
280-
<RequestWrapper2
281-
result={queryResult}
282-
render={(data) => {
283-
if (data.makerspaceLogs.length === 0) {
284-
return (
285-
<Typography
286-
variant="body1"
287-
sx={{
288-
fontStyle: "italic",
289-
color: "grey.700",
290-
mx: "auto",
291-
my: 8,
292-
}}
293-
>
294-
No results.
295-
</Typography>
296-
);
297-
}
298-
return (
299-
<Stack divider={<Divider flexItem />} mt={4} spacing={0.75}>
300-
{data.makerspaceLogs.map((log: any) => (
285+
{
286+
logs === undefined
287+
? <LinearProgress />
288+
: (logs.length === 0)
289+
? <Typography
290+
variant="body1"
291+
sx={{
292+
fontStyle: "italic",
293+
color: "grey.700",
294+
mx: "auto",
295+
my: 8,
296+
}}
297+
>
298+
No results.
299+
</Typography>
300+
: <Stack divider={<Divider flexItem />} mt={4} spacing={0.75}>
301+
{logs.map((log: any) => (
301302
<AuditLogRow
302303
key={log.id}
303304
dateTime={log.dateTime}
@@ -308,9 +309,7 @@ export default function LogPage() {
308309
))}
309310
<Typography variant="body2">This page is limitted to 100 logs. Consider narrowing your search criteria.</Typography>
310311
</Stack>
311-
);
312-
}}
313-
/>
312+
}
314313

315314
<ManualRoomSignInModal modalOpen={manualSignInModal} setModalOpen={setManualSignInModal} />
316315
</Box>

client/src/pages/site-settings/AdminHistoryPage.tsx

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React, { ChangeEvent, useEffect, useState } from "react";
2-
import { Box, Button, Card, Checkbox, Collapse, Divider, FormControlLabel, FormGroup, IconButton, Stack, TextField, ToggleButton, ToggleButtonGroup, Typography } from "@mui/material";
1+
import React, { ChangeEvent, useEffect, useMemo, useState } from "react";
2+
import { Box, Button, Card, Checkbox, Collapse, Divider, FormControlLabel, FormGroup, IconButton, LinearProgress, Stack, TextField, ToggleButton, ToggleButtonGroup, Typography } from "@mui/material";
33
import { gql } from "@apollo/client";
44
import { useLazyQuery } from "@apollo/client/react";
55
import { useLocation, useNavigate, useParams } from "react-router-dom";
@@ -141,8 +141,11 @@ export default function AdminHistoryPage() {
141141
navigate(`/admin/history`, { replace: true });
142142
};
143143

144-
const showClearButton =
145-
startDateString || stopDateString || search.includes("q=");
144+
const showClearButton = startDateString || stopDateString || search.includes("q=");
145+
146+
const logs = useMemo(() => {
147+
return queryResult.data ? queryResult.data.auditLogs : undefined;
148+
}, [queryResult.data, queryResult.data?.auditLogs])
146149

147150
return (
148151
<Box margin="25px">
@@ -259,27 +262,23 @@ export default function AdminHistoryPage() {
259262
</Stack>
260263
</Collapse>
261264
</Card>
262-
<RequestWrapper2
263-
result={queryResult}
264-
render={(data) => {
265-
if (data.auditLogs.length === 0) {
266-
return (
267-
<Typography
268-
variant="body1"
269-
sx={{
270-
fontStyle: "italic",
271-
color: "grey.700",
272-
mx: "auto",
273-
my: 8,
274-
}}
275-
>
276-
No results.
277-
</Typography>
278-
);
279-
}
280-
return (
281-
<Stack divider={<Divider flexItem />} mt={4} spacing={0.75}>
282-
{data.auditLogs.map((log: any) => (
265+
{
266+
logs === undefined
267+
? <LinearProgress />
268+
: (logs.length === 0)
269+
? <Typography
270+
variant="body1"
271+
sx={{
272+
fontStyle: "italic",
273+
color: "grey.700",
274+
mx: "auto",
275+
my: 8,
276+
}}
277+
>
278+
No results.
279+
</Typography>
280+
: <Stack divider={<Divider flexItem />} mt={4} spacing={0.75}>
281+
{logs.map((log: any) => (
283282
<AuditLogRow
284283
key={log.id}
285284
dateTime={log.dateTime}
@@ -290,9 +289,7 @@ export default function AdminHistoryPage() {
290289
))}
291290
<Typography variant="body2">This page is limitted to 100 logs. Consider narrowing your search criteria.</Typography>
292291
</Stack>
293-
);
294-
}}
295-
/>
292+
}
296293

297294
<ManualRoomSignInModal modalOpen={manualSignInModal} setModalOpen={setManualSignInModal} />
298295
</Box>

0 commit comments

Comments
 (0)