Skip to content

Commit 2f14434

Browse files
decreased history to 5 days.
1 parent e615b23 commit 2f14434

File tree

1 file changed

+70
-61
lines changed

1 file changed

+70
-61
lines changed

src/pages/tenant/standards/manage-drift/history.js

Lines changed: 70 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
CircularProgress,
1111
Alert,
1212
Collapse,
13-
Link
13+
Link,
1414
} from "@mui/material";
1515
import {
1616
Timeline,
@@ -19,30 +19,31 @@ import {
1919
TimelineConnector,
2020
TimelineContent,
2121
TimelineDot,
22-
TimelineOppositeContent
22+
TimelineOppositeContent,
2323
} from "@mui/lab";
2424
import { Grid } from "@mui/system";
2525
import { Layout as DashboardLayout } from "/src/layouts/index.js";
2626
import { HeaderedTabbedLayout } from "/src/layouts/HeaderedTabbedLayout";
2727
import { ApiGetCall } from "/src/api/ApiCall";
2828
import { useRouter } from "next/router";
29-
import {
30-
Policy,
31-
Sync,
32-
PlayArrow,
29+
import {
30+
Policy,
31+
Sync,
32+
PlayArrow,
3333
Error as ErrorIcon,
3434
Warning as WarningIcon,
3535
Info as InfoIcon,
3636
CheckCircle as SuccessIcon,
37-
ExpandMore
37+
ExpandMore,
3838
} from "@mui/icons-material";
3939
import tabOptions from "./tabOptions.json";
40+
import { useSettings } from "../../../../hooks/use-settings";
4041

4142
const Page = () => {
4243
const router = useRouter();
4344
const { templateId } = router.query;
44-
const [daysToLoad, setDaysToLoad] = useState(7);
45-
const [tenant] = useState("oglenet.onmicrosoft.com"); // You might want to get this from context or props
45+
const [daysToLoad, setDaysToLoad] = useState(5);
46+
const tenant = useSettings().currentTenant;
4647
const [expandedMessages, setExpandedMessages] = useState(new Set());
4748

4849
// Toggle message expansion
@@ -64,7 +65,7 @@ const Page = () => {
6465
return {
6566
text: message.substring(0, maxLength) + "...",
6667
fullText: message,
67-
isTruncated: true
68+
isTruncated: true,
6869
};
6970
};
7071

@@ -73,16 +74,15 @@ const Page = () => {
7374
const endDate = new Date();
7475
const startDate = new Date();
7576
startDate.setDate(endDate.getDate() - days);
76-
77+
7778
return {
78-
startDate: startDate.toISOString().split('T')[0].replace(/-/g, ''),
79-
endDate: endDate.toISOString().split('T')[0].replace(/-/g, '')
79+
startDate: startDate.toISOString().split("T")[0].replace(/-/g, ""),
80+
endDate: endDate.toISOString().split("T")[0].replace(/-/g, ""),
8081
};
8182
};
8283

8384
const { startDate, endDate } = getDateRange(daysToLoad);
8485

85-
// API call to get logs
8686
const logsData = ApiGetCall({
8787
url: `/api/Listlogs?tenant=${tenant}&StartDate=${startDate}&EndDate=${endDate}&Filter=true`,
8888
queryKey: `Listlogs-${tenant}-${startDate}-${endDate}`,
@@ -92,39 +92,39 @@ const Page = () => {
9292
const getSeverityConfig = (severity) => {
9393
const severityLower = severity?.toLowerCase();
9494
switch (severityLower) {
95-
case 'error':
96-
return { icon: <ErrorIcon />, color: 'error', chipColor: 'error' };
97-
case 'warning':
98-
return { icon: <WarningIcon />, color: 'warning', chipColor: 'warning' };
99-
case 'info':
100-
return { icon: <InfoIcon />, color: 'info', chipColor: 'info' };
101-
case 'success':
102-
return { icon: <SuccessIcon />, color: 'success', chipColor: 'success' };
95+
case "error":
96+
return { icon: <ErrorIcon />, color: "error", chipColor: "error" };
97+
case "warning":
98+
return { icon: <WarningIcon />, color: "warning", chipColor: "warning" };
99+
case "info":
100+
return { icon: <InfoIcon />, color: "info", chipColor: "info" };
101+
case "success":
102+
return { icon: <SuccessIcon />, color: "success", chipColor: "success" };
103103
default:
104-
return { icon: <InfoIcon />, color: 'grey', chipColor: 'default' };
104+
return { icon: <InfoIcon />, color: "grey", chipColor: "default" };
105105
}
106106
};
107107

108108
// Format date for display
109109
const formatDate = (dateString) => {
110110
const date = new Date(dateString);
111111
return {
112-
time: date.toLocaleTimeString('en-US', {
113-
hour: '2-digit',
114-
minute: '2-digit',
115-
hour12: false
112+
time: date.toLocaleTimeString("en-US", {
113+
hour: "2-digit",
114+
minute: "2-digit",
115+
hour12: false,
116+
}),
117+
date: date.toLocaleDateString("en-US", {
118+
month: "short",
119+
day: "numeric",
120+
year: "numeric",
116121
}),
117-
date: date.toLocaleDateString('en-US', {
118-
month: 'short',
119-
day: 'numeric',
120-
year: 'numeric'
121-
})
122122
};
123123
};
124124

125125
// Load more days
126126
const handleLoadMore = () => {
127-
setDaysToLoad(prev => prev + 7);
127+
setDaysToLoad((prev) => prev + 7);
128128
};
129129

130130
// Actions for the ActionsMenu
@@ -175,9 +175,9 @@ const Page = () => {
175175
];
176176

177177
// Sort logs by date (newest first)
178-
const sortedLogs = logsData.data ? [...logsData.data].sort((a, b) =>
179-
new Date(b.DateTime) - new Date(a.DateTime)
180-
) : [];
178+
const sortedLogs = logsData.data
179+
? [...logsData.data].sort((a, b) => new Date(b.DateTime) - new Date(a.DateTime))
180+
: [];
181181

182182
return (
183183
<HeaderedTabbedLayout
@@ -203,15 +203,11 @@ const Page = () => {
203203
)}
204204

205205
{logsData.isError && (
206-
<Alert severity="error">
207-
Failed to load activity logs. Please try again.
208-
</Alert>
206+
<Alert severity="error">Failed to load activity logs. Please try again.</Alert>
209207
)}
210208

211209
{logsData.data && sortedLogs.length === 0 && (
212-
<Alert severity="info">
213-
No activity logs found for the selected time period.
214-
</Alert>
210+
<Alert severity="info">No activity logs found for the selected time period.</Alert>
215211
)}
216212

217213
{logsData.data && sortedLogs.length > 0 && (
@@ -233,58 +229,67 @@ const Page = () => {
233229
const { time, date } = formatDate(log.DateTime);
234230
const { text, fullText, isTruncated } = truncateMessage(log.Message);
235231
const isExpanded = expandedMessages.has(index);
236-
232+
237233
return (
238234
<TimelineItem key={index}>
239235
<TimelineOppositeContent
240-
sx={{ m: 'auto 0', minWidth: 100, maxWidth: 100 }}
236+
sx={{ m: "auto 0", minWidth: 100, maxWidth: 100 }}
241237
align="right"
242238
variant="body2"
243239
color="text.secondary"
244240
>
245241
<Typography variant="caption" display="block" fontSize="0.7rem">
246242
{date}
247243
</Typography>
248-
<Typography variant="caption" display="block" fontWeight="bold" fontSize="0.75rem">
244+
<Typography
245+
variant="caption"
246+
display="block"
247+
fontWeight="bold"
248+
fontSize="0.75rem"
249+
>
249250
{time}
250251
</Typography>
251252
</TimelineOppositeContent>
252-
253+
253254
<TimelineSeparator>
254255
<TimelineDot color={color} variant="outlined" size="small">
255256
{icon}
256257
</TimelineDot>
257258
{index < sortedLogs.length - 1 && <TimelineConnector />}
258259
</TimelineSeparator>
259-
260-
<TimelineContent sx={{ py: '8px', px: 2 }}>
260+
261+
<TimelineContent sx={{ py: "8px", px: 2 }}>
261262
<Stack spacing={1}>
262263
<Box display="flex" alignItems="center" gap={1} flexWrap="wrap">
263264
<Chip
264265
label={log.Severity}
265266
color={chipColor}
266267
size="small"
267268
variant="outlined"
268-
sx={{ fontSize: '0.7rem', height: 20 }}
269+
sx={{ fontSize: "0.7rem", height: 20 }}
269270
/>
270271
<Chip
271272
label={log.API}
272273
size="small"
273274
variant="outlined"
274-
sx={{ fontSize: '0.7rem', height: 20 }}
275+
sx={{ fontSize: "0.7rem", height: 20 }}
275276
/>
276277
{log.IP && (
277278
<Chip
278279
label={`IP: ${log.IP}`}
279280
size="small"
280281
variant="outlined"
281-
sx={{ fontSize: '0.7rem', height: 20 }}
282+
sx={{ fontSize: "0.7rem", height: 20 }}
282283
/>
283284
)}
284285
</Box>
285-
286+
286287
<Box>
287-
<Typography variant="body2" fontWeight="medium" sx={{ fontSize: '0.875rem' }}>
288+
<Typography
289+
variant="body2"
290+
fontWeight="medium"
291+
sx={{ fontSize: "0.875rem" }}
292+
>
288293
{isExpanded ? fullText : text}
289294
</Typography>
290295
{isTruncated && (
@@ -294,18 +299,22 @@ const Page = () => {
294299
onClick={() => toggleMessageExpansion(index)}
295300
sx={{
296301
mt: 0.5,
297-
display: 'block',
298-
textAlign: 'left',
299-
fontSize: '0.75rem'
302+
display: "block",
303+
textAlign: "left",
304+
fontSize: "0.75rem",
300305
}}
301306
>
302-
{isExpanded ? 'Show less' : 'Show more'}
307+
{isExpanded ? "Show less" : "Show more"}
303308
</Link>
304309
)}
305310
</Box>
306-
311+
307312
{log.User && (
308-
<Typography variant="caption" color="text.secondary" sx={{ fontSize: '0.7rem' }}>
313+
<Typography
314+
variant="caption"
315+
color="text.secondary"
316+
sx={{ fontSize: "0.7rem" }}
317+
>
309318
User: {log.User}
310319
</Typography>
311320
)}
@@ -315,7 +324,7 @@ const Page = () => {
315324
);
316325
})}
317326
</Timeline>
318-
327+
319328
<Box display="flex" justifyContent="center" mt={3}>
320329
<Button
321330
variant="outlined"
@@ -337,4 +346,4 @@ const Page = () => {
337346

338347
Page.getLayout = (page) => <DashboardLayout>{page}</DashboardLayout>;
339348

340-
export default Page;
349+
export default Page;

0 commit comments

Comments
 (0)