-
Notifications
You must be signed in to change notification settings - Fork 587
chore: implement new design for log details #4052
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,4 @@ | ||||||
| "use client"; | ||||||
| import { Card, CardContent, CopyButton } from "@unkey/ui"; | ||||||
| import React from "react"; | ||||||
| import { CopyButton } from "@unkey/ui"; | ||||||
|
|
||||||
| export const LogSection = ({ | ||||||
| details, | ||||||
|
|
@@ -9,115 +7,51 @@ export const LogSection = ({ | |||||
| details: Record<string, React.ReactNode> | string; | ||||||
| title: string; | ||||||
| }) => { | ||||||
| // Helper function to get the text to copy | ||||||
| const getTextToCopy = () => { | ||||||
| let textToCopy: string; | ||||||
|
|
||||||
| if (typeof details === "string") { | ||||||
| textToCopy = details; | ||||||
| } else { | ||||||
| // Extract text content from React components | ||||||
| textToCopy = Object.entries(details) | ||||||
| .map(([key, value]) => { | ||||||
| if (value === null || value === undefined) { | ||||||
| return key; | ||||||
| } | ||||||
| // If it's a React element, try to extract text content | ||||||
| if (typeof value === "object" && value !== null && "props" in value) { | ||||||
| return `${key}: ${extractTextFromReactElement(value)}`; | ||||||
| } | ||||||
| return `${key}: ${value}`; | ||||||
| }) | ||||||
| .join("\n"); | ||||||
| } | ||||||
| return textToCopy; | ||||||
| }; | ||||||
|
|
||||||
| // Helper function to extract text from React elements | ||||||
| // This is used to extract text from React elements like TimestampInfo and Link components | ||||||
| const extractTextFromReactElement = (element: React.ReactNode): string => { | ||||||
| if (typeof element === "string" || typeof element === "number") { | ||||||
| return String(element); | ||||||
| return details; | ||||||
| } | ||||||
|
|
||||||
| if (element === null || element === undefined) { | ||||||
| return ""; | ||||||
| } | ||||||
|
|
||||||
| // Handle React elements | ||||||
| if (React.isValidElement(element)) { | ||||||
| const reactElement = element as React.ReactElement<{ | ||||||
| value?: string | Date | number; | ||||||
| children?: React.ReactNode; | ||||||
| href?: string; | ||||||
| title?: string; | ||||||
| }>; | ||||||
|
|
||||||
| // For TimestampInfo and similar components, check for a 'value' prop first | ||||||
| if (reactElement.props.value) { | ||||||
| // If value is a date/timestamp, format it appropriately | ||||||
| if (reactElement.props.value instanceof Date) { | ||||||
| return reactElement.props.value.toISOString(); | ||||||
| return Object.entries(details) | ||||||
| .map(([key, value]) => { | ||||||
| if (value === null || value === undefined) { | ||||||
| return key; | ||||||
| } | ||||||
| return String(reactElement.props.value); | ||||||
| } | ||||||
|
|
||||||
| // Then check for children | ||||||
| if (reactElement.props.children) { | ||||||
| if (typeof reactElement.props.children === "string") { | ||||||
| return reactElement.props.children; | ||||||
| } | ||||||
| if (Array.isArray(reactElement.props.children)) { | ||||||
| return reactElement.props.children | ||||||
| .map((child: React.ReactNode) => extractTextFromReactElement(child)) | ||||||
| .join(""); | ||||||
| if (typeof value === "object" && value !== null && "props" in value) { | ||||||
| return `${key}: ${value}`; | ||||||
| } | ||||||
| return extractTextFromReactElement(reactElement.props.children); | ||||||
| } | ||||||
|
|
||||||
| // For Link components, check for href or title | ||||||
| if (reactElement.props.href || reactElement.props.title) { | ||||||
| return reactElement.props.title || reactElement.props.href || ""; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| return String(element); | ||||||
| return `${key}: ${value}`; | ||||||
| }) | ||||||
| .join("\n"); | ||||||
| }; | ||||||
|
|
||||||
| return ( | ||||||
| <div className="flex flex-col gap-1 mt-[16px]"> | ||||||
| <div className="flex justify-between items-center"> | ||||||
| <span className="text-[13px] text-accent-9 font-sans">{title}</span> | ||||||
| </div> | ||||||
| <Card className="bg-gray-2 border-gray-4 rounded-lg"> | ||||||
| <CardContent className="py-2 px-3 text-xs relative group"> | ||||||
| <pre className="flex flex-col gap-1 whitespace-pre-wrap leading-relaxed"> | ||||||
| <div className="flex flex-col gap-1 mt-[16px] px-4"> | ||||||
| <div className="border bg-gray-2 border-gray-4 rounded-[10px] relative group"> | ||||||
| <div className="text-gray-11 text-[12px] leading-6 px-[14px] py-1.5 font-sans">{title}</div> | ||||||
| <div className="border-gray-4 border-t rounded-[10px] bg-white dark:bg-black px-3.5 py-2"> | ||||||
| <pre className="whitespace-pre-wrap break-words leading-relaxed text-xs"> | ||||||
| {typeof details === "object" | ||||||
| ? Object.entries(details).map((detail) => { | ||||||
| const [key, value] = detail; | ||||||
| return ( | ||||||
| <div className="group flex items-center w-full p-[3px]" key={key}> | ||||||
| <span className="text-left text-accent-9 whitespace-nowrap"> | ||||||
| {key} | ||||||
| {value ? ":" : ""} | ||||||
| </span> | ||||||
| <span className="ml-2 text-xs text-accent-12 truncate">{value}</span> | ||||||
| </div> | ||||||
| ); | ||||||
| }) | ||||||
| ? Object.entries(details).map(([key, value]) => ( | ||||||
| <div className="flex items-center w-full px-[3px] leading-7" key={key}> | ||||||
| <span className="text-left text-gray-11 whitespace-nowrap"> | ||||||
| {key} | ||||||
| {value ? ":" : ""} | ||||||
| </span> | ||||||
| <span className="ml-2 text-accent-12 truncate">{value}</span> | ||||||
| </div> | ||||||
| )) | ||||||
| : details} | ||||||
| </pre> | ||||||
|
|
||||||
| <CopyButton | ||||||
| value={getTextToCopy()} | ||||||
| shape="square" | ||||||
| variant="primary" | ||||||
| size="2xlg" | ||||||
| className="absolute bottom-1 right-1 opacity-0 group-hover:opacity-100 transition-opacity rounded-md p-4" | ||||||
| aria-label="Copy content" | ||||||
| /> | ||||||
| </CardContent> | ||||||
| </Card> | ||||||
| </div> | ||||||
| <CopyButton | ||||||
| value={getTextToCopy()} | ||||||
| shape="square" | ||||||
| variant="outline" | ||||||
| className="absolute bottom-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity rounded-md p-4 bg-gray-2 hover:bg-gray-2 size-2" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix incorrect button size. The Remove - className="absolute bottom-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity rounded-md p-4 bg-gray-2 hover:bg-gray-2 size-2"
+ className="absolute bottom-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity rounded-md p-4 bg-gray-2 hover:bg-gray-2"Alternatively, if a specific size is needed, consider 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| aria-label="Copy content" | ||||||
| /> | ||||||
| </div> | ||||||
| </div> | ||||||
| ); | ||||||
| }; | ||||||
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.
🛠️ Refactor suggestion | 🟠 Major
Remove dead code from previous React element extraction logic.
Lines 20-22 check for objects with a
propsproperty but perform the same operation as the fallback case (line 23). Based on the past review comments, this appears to be leftover code from the removed React element text-extraction logic.Apply this diff to remove the redundant check:
return Object.entries(details) .map(([key, value]) => { if (value === null || value === undefined) { return key; } - if (typeof value === "object" && value !== null && "props" in value) { - return `${key}: ${value}`; - } return `${key}: ${value}`; }) .join("\n");📝 Committable suggestion
🤖 Prompt for AI Agents