mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-25 13:18:47 +00:00
Merge pull request #3859 from Dokploy/3851-ui-3-issues-in-1
feat: enhance request logging display with formatted status and duration
This commit is contained in:
@@ -6,6 +6,9 @@ import { Button } from "@/components/ui/button";
|
|||||||
import type { LogEntry } from "./show-requests";
|
import type { LogEntry } from "./show-requests";
|
||||||
|
|
||||||
export const getStatusColor = (status: number) => {
|
export const getStatusColor = (status: number) => {
|
||||||
|
if (status === 0) {
|
||||||
|
return "secondary";
|
||||||
|
}
|
||||||
if (status >= 100 && status < 200) {
|
if (status >= 100 && status < 200) {
|
||||||
return "outline";
|
return "outline";
|
||||||
}
|
}
|
||||||
@@ -21,6 +24,24 @@ export const getStatusColor = (status: number) => {
|
|||||||
return "destructive";
|
return "destructive";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const formatStatusLabel = (status: number) => {
|
||||||
|
if (status === 0) {
|
||||||
|
return "N/A";
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatDuration = (nanos: number) => {
|
||||||
|
const ms = nanos / 1000000;
|
||||||
|
if (ms < 1) {
|
||||||
|
return `${(nanos / 1000).toFixed(2)} µs`;
|
||||||
|
}
|
||||||
|
if (ms < 1000) {
|
||||||
|
return `${ms.toFixed(2)} ms`;
|
||||||
|
}
|
||||||
|
return `${(ms / 1000).toFixed(2)} s`;
|
||||||
|
};
|
||||||
|
|
||||||
export const columns: ColumnDef<LogEntry>[] = [
|
export const columns: ColumnDef<LogEntry>[] = [
|
||||||
{
|
{
|
||||||
accessorKey: "level",
|
accessorKey: "level",
|
||||||
@@ -59,10 +80,10 @@ export const columns: ColumnDef<LogEntry>[] = [
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex flex-row gap-3 w-full">
|
<div className="flex flex-row gap-3 w-full">
|
||||||
<Badge variant={getStatusColor(log.OriginStatus)}>
|
<Badge variant={getStatusColor(log.OriginStatus)}>
|
||||||
Status: {log.OriginStatus}
|
Status: {formatStatusLabel(log.OriginStatus)}
|
||||||
</Badge>
|
</Badge>
|
||||||
<Badge variant={"secondary"}>
|
<Badge variant={"secondary"}>
|
||||||
Exec Time: {`${log.Duration / 1000000000}s`}
|
Exec Time: {formatDuration(log.Duration)}
|
||||||
</Badge>
|
</Badge>
|
||||||
<Badge variant={"secondary"}>IP: {log.ClientAddr}</Badge>
|
<Badge variant={"secondary"}>IP: {log.ClientAddr}</Badge>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -152,7 +152,15 @@ export const RequestsTable = ({ dateRange }: RequestsTableProps) => {
|
|||||||
return JSON.stringify(value, null, 2);
|
return JSON.stringify(value, null, 2);
|
||||||
}
|
}
|
||||||
if (key === "Duration" || key === "OriginDuration" || key === "Overhead") {
|
if (key === "Duration" || key === "OriginDuration" || key === "Overhead") {
|
||||||
return `${value / 1000000000} s`;
|
const nanos = Number(value);
|
||||||
|
const ms = nanos / 1000000;
|
||||||
|
if (ms < 1) {
|
||||||
|
return `${(nanos / 1000).toFixed(2)} µs`;
|
||||||
|
}
|
||||||
|
if (ms < 1000) {
|
||||||
|
return `${ms.toFixed(2)} ms`;
|
||||||
|
}
|
||||||
|
return `${(ms / 1000).toFixed(2)} s`;
|
||||||
}
|
}
|
||||||
if (key === "level") {
|
if (key === "level") {
|
||||||
return <Badge variant="secondary">{value}</Badge>;
|
return <Badge variant="secondary">{value}</Badge>;
|
||||||
@@ -161,7 +169,11 @@ export const RequestsTable = ({ dateRange }: RequestsTableProps) => {
|
|||||||
return <Badge variant="outline">{value}</Badge>;
|
return <Badge variant="outline">{value}</Badge>;
|
||||||
}
|
}
|
||||||
if (key === "DownstreamStatus" || key === "OriginStatus") {
|
if (key === "DownstreamStatus" || key === "OriginStatus") {
|
||||||
return <Badge variant={getStatusColor(value)}>{value}</Badge>;
|
const num = Number(value);
|
||||||
|
if (num === 0) {
|
||||||
|
return <Badge variant="secondary">N/A</Badge>;
|
||||||
|
}
|
||||||
|
return <Badge variant={getStatusColor(num)}>{value}</Badge>;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const Command = React.forwardRef<
|
|||||||
<CommandPrimitive
|
<CommandPrimitive
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
|
"flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground p-px",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
@@ -44,7 +44,7 @@ const CommandInput = React.forwardRef<
|
|||||||
<CommandPrimitive.Input
|
<CommandPrimitive.Input
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
|
"flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-0 focus-visible:ring-inset",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
|
|||||||
Reference in New Issue
Block a user