-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dataset test UI improvements #5766
Merged
Merged
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f45e64e
Dataset test UI improvements
galvana 61a6ba0
Adding concept of SinkTypes
galvana f0aa352
Simplifying code
galvana 3bbc7b9
Removing abstract base class
galvana d7ac629
automaton
galvana 53fbeb5
Adding test log endpoint
galvana 13d92f3
Adding test log section to test datasets UI
galvana f4ba271
Performance optimizations
galvana 84512d6
Capturing error logs
galvana bddd82b
Fixing linter issue
galvana 86a2ccd
Adding endpoint tests
galvana 02b9733
Adding missing imports
galvana 6ec221e
Fixing cyclic import
galvana 7cf2a71
Fixing logger contextualize call
galvana b39a358
Moving import to top of file
galvana 170f184
Adding missing import
galvana d7d4d9f
Merge branch 'main' into LJ-348-dataset-test-ui-improvements
galvana 951c2a0
Merging in main
galvana 4947302
Fixing imports
galvana dacce63
Fixing cyclic import
galvana 8b20740
Merge branch 'main' into LJ-348-dataset-test-ui-improvements
galvana 5c1f5f2
Re-adding log statements that were accidentally removed during merge …
galvana 5411b63
Merge branch 'main' into LJ-348-dataset-test-ui-improvements
galvana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
clients/admin-ui/src/features/test-datasets/TestLogsSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
import { format } from "date-fns-tz"; | ||
import { Box, Heading, HStack, Text } from "fidesui"; | ||
import { memo, useCallback, useEffect, useMemo, useRef } from "react"; | ||
import { useSelector } from "react-redux"; | ||
|
||
import { useAppDispatch } from "~/app/hooks"; | ||
import ClipboardButton from "~/features/common/ClipboardButton"; | ||
import { useGetTestLogsQuery } from "~/features/privacy-requests"; | ||
|
||
import { | ||
selectLogs, | ||
selectPrivacyRequestId, | ||
setLogs, | ||
} from "./dataset-test.slice"; | ||
|
||
const formatTimestamp = (isoTimestamp: string) => { | ||
const date = new Date(isoTimestamp); | ||
return format(date, "yyyy-MM-dd HH:mm:ss.SSS"); | ||
}; | ||
|
||
const getLevelColor = (level: string) => { | ||
switch (level) { | ||
case "ERROR": | ||
return "red.500"; | ||
case "WARNING": | ||
return "orange.500"; | ||
case "INFO": | ||
return "blue.500"; | ||
default: | ||
return "gray.500"; | ||
} | ||
}; | ||
|
||
interface LogLineProps { | ||
log: { | ||
timestamp: string; | ||
level: string; | ||
module_info: string; | ||
message: string; | ||
}; | ||
} | ||
|
||
const LogLine = memo(({ log }: LogLineProps) => ( | ||
<Box | ||
as="pre" | ||
margin={0} | ||
fontSize="xs" | ||
fontFamily="monospace" | ||
whiteSpace="pre-wrap" | ||
wordBreak="break-word" | ||
> | ||
<Text as="span" color="green.500"> | ||
{formatTimestamp(log.timestamp)} | ||
</Text> | ||
<Text as="span"> | </Text> | ||
<Text as="span" color={getLevelColor(log.level)}> | ||
{log.level.padEnd(8)} | ||
</Text> | ||
<Text as="span"> | </Text> | ||
<Text as="span" color="cyan.500"> | ||
{log.module_info} | ||
</Text> | ||
<Text as="span"> - </Text> | ||
<Text | ||
as="span" | ||
color={ | ||
log.level === "ERROR" || log.level === "WARNING" | ||
? getLevelColor(log.level) | ||
: "gray.800" | ||
} | ||
> | ||
{log.message} | ||
</Text> | ||
</Box> | ||
)); | ||
|
||
LogLine.displayName = "LogLine"; | ||
|
||
const TestLogsSection = () => { | ||
const dispatch = useAppDispatch(); | ||
const logsRef = useRef<HTMLDivElement>(null); | ||
const privacyRequestId = useSelector(selectPrivacyRequestId); | ||
const logs = useSelector(selectLogs); | ||
|
||
// Poll for logs when we have a privacy request ID | ||
const { data: newLogs } = useGetTestLogsQuery( | ||
{ privacy_request_id: privacyRequestId! }, | ||
{ | ||
skip: !privacyRequestId, | ||
pollingInterval: 1000, | ||
}, | ||
); | ||
|
||
// Update logs in store when new logs arrive | ||
useEffect(() => { | ||
if (newLogs) { | ||
dispatch(setLogs(newLogs)); | ||
} | ||
}, [newLogs, dispatch]); | ||
|
||
// Auto scroll to bottom when new logs arrive | ||
const scrollToBottom = useCallback(() => { | ||
if (logsRef.current) { | ||
logsRef.current.scrollTop = logsRef.current.scrollHeight; | ||
} | ||
}, []); | ||
|
||
useEffect(() => { | ||
scrollToBottom(); | ||
}, [logs, scrollToBottom]); | ||
|
||
// Format logs for copying to clipboard | ||
const plainLogs = useMemo( | ||
() => | ||
logs | ||
?.map( | ||
(log) => | ||
`${formatTimestamp(log.timestamp)} | ${log.level} | ${log.module_info} - ${log.message}`, | ||
) | ||
.join("\n") || "", | ||
[logs], | ||
); | ||
|
||
return ( | ||
<> | ||
<Heading | ||
as="h3" | ||
size="sm" | ||
display="flex" | ||
alignItems="center" | ||
justifyContent="space-between" | ||
> | ||
<HStack> | ||
<Text>Test logs</Text> | ||
<ClipboardButton copyText={plainLogs} /> | ||
</HStack> | ||
</Heading> | ||
<Box | ||
ref={logsRef} | ||
height="200px" | ||
overflowY="auto" | ||
borderWidth={1} | ||
borderColor="gray.200" | ||
borderRadius="md" | ||
p={2} | ||
> | ||
{logs?.map((log) => ( | ||
<LogLine | ||
key={`${log.timestamp}-${log.module_info}-${log.message}`} | ||
log={log} | ||
/> | ||
))} | ||
</Box> | ||
</> | ||
); | ||
}; | ||
|
||
export default memo(TestLogsSection); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New component with color-coded logs and auto-scrolling as new logs are available