Skip to content

Commit 7301939

Browse files
committed
audit log content history
1 parent b0b1c29 commit 7301939

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

apps/sensenet/src/components/Home.tsx

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ const useStyles = makeStyles((theme: Theme) =>
8585
display: 'none',
8686
},
8787
'&:hover': {
88-
backgroundColor: theme.palette.type === 'light' ? '#ddddddff' : '#4a4a4a',
8988
cursor: 'default',
9089
},
9190
},
@@ -183,6 +182,8 @@ export const Home = () => {
183182
// const [myLogs, setMyLogs] = useState<any[]>([])
184183
const [hasGetLogs, setHasGetLogs] = useState(false)
185184
// const [hasGetTopLogsByUser, setHasGetTopLogsByUser] = useState(false)
185+
const [canContentHistory, setCanContentHistory] = useState(false)
186+
const [contentHistory, setContentHistory] = useState<any[]>([])
186187

187188
useEffect(() => {
188189
async function getActionsAndLogs() {
@@ -191,6 +192,7 @@ export const Home = () => {
191192
const actionNames = d.results.map((a: any) => a.Name)
192193

193194
const canGetLogs = actionNames.includes('GetLogsForLastMinutes')
195+
setCanContentHistory(actionNames.includes('GetTopLogsByContentId'))
194196
// const canGetUserLogs = actionNames.includes('GetTopLogsByUser')
195197

196198
setHasGetLogs(canGetLogs)
@@ -299,6 +301,21 @@ export const Home = () => {
299301
)
300302
}
301303

304+
async function fetchContentHistory(contentId: string) {
305+
try {
306+
const response = await repo.executeAction<any[], any>({
307+
idOrPath: '/Root',
308+
name: 'LogEntries/GetTopLogsByContentId',
309+
method: 'GET',
310+
oDataOptions: { contentId, limit: 10 } as any,
311+
})
312+
console.log('response:', response)
313+
setContentHistory(response || [])
314+
} catch (error: any) {
315+
console.error('GetTopLogsByContentId error:', error.message)
316+
}
317+
}
318+
302319
return !hasGetLogs ? (
303320
<DashboardComponent />
304321
) : (
@@ -332,6 +349,27 @@ export const Home = () => {
332349
{hasChanges && (
333350
<AccordionDetails className={classes.accordionDetails}>{getTable(log)}</AccordionDetails>
334351
)}
352+
{canContentHistory && (
353+
<>
354+
<Accordion
355+
className={''}
356+
onClick={() => fetchContentHistory(log.ContentId)}
357+
style={{ margin: '8px' }}>
358+
<AccordionSummary
359+
expandIcon={<ExpandMoreIcon />}
360+
aria-controls="content-history-content"
361+
id="content-history-header"
362+
className={''}>
363+
<Typography>Content History</Typography>
364+
</AccordionSummary>
365+
<AccordionDetails style={{ display: 'flex', flexDirection: 'column' }}>
366+
{contentHistory.map((historyLog, idx) => (
367+
<div key={idx}>{getTable(historyLog)}</div>
368+
))}
369+
</AccordionDetails>
370+
</Accordion>
371+
</>
372+
)}
335373
</Accordion>
336374
)
337375
})}

0 commit comments

Comments
 (0)