mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
feat(logs): filter improvements
This commit is contained in:
@@ -1,26 +1,16 @@
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import {
|
|
||||||
Select,
|
|
||||||
SelectContent,
|
|
||||||
SelectItem,
|
|
||||||
SelectTrigger,
|
|
||||||
SelectValue,
|
|
||||||
SelectSeparator
|
|
||||||
} from "@/components/ui/select";
|
|
||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
import {
|
import { Download as DownloadIcon, Loader2 } from "lucide-react";
|
||||||
Download as DownloadIcon,
|
|
||||||
Loader2
|
|
||||||
} from "lucide-react";
|
|
||||||
import React, { useEffect, useRef } from "react";
|
import React, { useEffect, useRef } from "react";
|
||||||
|
import { SinceLogsFilter } from "./since-logs-filter";
|
||||||
|
import { StatusLogsFilter } from "./status-logs-filter";
|
||||||
import { TerminalLine } from "./terminal-line";
|
import { TerminalLine } from "./terminal-line";
|
||||||
import { type LogLine, getLogType, parseLogs } from "./utils";
|
import { type LogLine, getLogType, parseLogs } from "./utils";
|
||||||
import { StatusLogsFilter } from "./status-logs-filter";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
containerId: string;
|
containerId: string;
|
||||||
serverId?: string | null;
|
serverId?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
type TimeFilter = "all" | "timestamp" | "1h" | "6h" | "24h" | "168h" | "720h";
|
type TimeFilter = "all" | "timestamp" | "1h" | "6h" | "24h" | "168h" | "720h";
|
||||||
@@ -49,276 +39,264 @@ export const priorities = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export const DockerLogsId: React.FC<Props> = ({ containerId, serverId }) => {
|
export const DockerLogsId: React.FC<Props> = ({ containerId, serverId }) => {
|
||||||
const { data } = api.docker.getConfig.useQuery(
|
const { data } = api.docker.getConfig.useQuery(
|
||||||
{
|
{
|
||||||
containerId,
|
containerId,
|
||||||
serverId: serverId ?? undefined,
|
serverId: serverId ?? undefined,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
enabled: !!containerId,
|
enabled: !!containerId,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const [rawLogs, setRawLogs] = React.useState("");
|
const [rawLogs, setRawLogs] = React.useState("");
|
||||||
const [filteredLogs, setFilteredLogs] = React.useState<LogLine[]>([]);
|
const [filteredLogs, setFilteredLogs] = React.useState<LogLine[]>([]);
|
||||||
const [autoScroll, setAutoScroll] = React.useState(true);
|
const [autoScroll, setAutoScroll] = React.useState(true);
|
||||||
const [lines, setLines] = React.useState<number>(100);
|
const [lines, setLines] = React.useState<number>(100);
|
||||||
const [search, setSearch] = React.useState<string>("");
|
const [search, setSearch] = React.useState<string>("");
|
||||||
const [showTimestamp, setShowTimestamp] = React.useState(true);
|
const [showTimestamp, setShowTimestamp] = React.useState(true);
|
||||||
const [since, setSince] = React.useState<TimeFilter>("all");
|
const [since, setSince] = React.useState<TimeFilter>("all");
|
||||||
const [typeFilter, setTypeFilter] = React.useState<string[]>([]);
|
const [typeFilter, setTypeFilter] = React.useState<string[]>([]);
|
||||||
const scrollRef = useRef<HTMLDivElement>(null);
|
const scrollRef = useRef<HTMLDivElement>(null);
|
||||||
const [isLoading, setIsLoading] = React.useState(false);
|
const [isLoading, setIsLoading] = React.useState(false);
|
||||||
|
|
||||||
const scrollToBottom = () => {
|
const scrollToBottom = () => {
|
||||||
if (autoScroll && scrollRef.current) {
|
if (autoScroll && scrollRef.current) {
|
||||||
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleScroll = () => {
|
const handleScroll = () => {
|
||||||
if (!scrollRef.current) return;
|
if (!scrollRef.current) return;
|
||||||
|
|
||||||
const { scrollTop, scrollHeight, clientHeight } = scrollRef.current;
|
const { scrollTop, scrollHeight, clientHeight } = scrollRef.current;
|
||||||
const isAtBottom = Math.abs(scrollHeight - scrollTop - clientHeight) < 10;
|
const isAtBottom = Math.abs(scrollHeight - scrollTop - clientHeight) < 10;
|
||||||
setAutoScroll(isAtBottom);
|
setAutoScroll(isAtBottom);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSearch = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleSearch = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setSearch(e.target.value || "");
|
setSearch(e.target.value || "");
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleLines = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleLines = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setRawLogs("");
|
setRawLogs("");
|
||||||
setFilteredLogs([]);
|
setFilteredLogs([]);
|
||||||
setLines(Number(e.target.value) || 1);
|
setLines(Number(e.target.value) || 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSince = (value: TimeFilter) => {
|
const handleSince = (value: string) => {
|
||||||
if (value === "timestamp") {
|
if (value === "timestamp") {
|
||||||
setShowTimestamp(!showTimestamp);
|
setShowTimestamp(!showTimestamp);
|
||||||
} else {
|
} else {
|
||||||
setRawLogs("");
|
setRawLogs("");
|
||||||
setFilteredLogs([]);
|
setFilteredLogs([]);
|
||||||
setSince(value);
|
setSince(value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!containerId) return;
|
if (!containerId) return;
|
||||||
|
|
||||||
let isCurrentConnection = true;
|
let isCurrentConnection = true;
|
||||||
let noDataTimeout: NodeJS.Timeout;
|
let noDataTimeout: NodeJS.Timeout;
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
setRawLogs("");
|
setRawLogs("");
|
||||||
setFilteredLogs([]);
|
setFilteredLogs([]);
|
||||||
|
|
||||||
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
|
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
|
||||||
const params = new globalThis.URLSearchParams({
|
const params = new globalThis.URLSearchParams({
|
||||||
containerId,
|
containerId,
|
||||||
tail: lines.toString(),
|
tail: lines.toString(),
|
||||||
since,
|
since,
|
||||||
search,
|
search,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (serverId) {
|
if (serverId) {
|
||||||
params.append("serverId", serverId);
|
params.append("serverId", serverId);
|
||||||
}
|
}
|
||||||
|
|
||||||
const wsUrl = `${protocol}//${
|
const wsUrl = `${protocol}//${
|
||||||
window.location.host
|
window.location.host
|
||||||
}/docker-container-logs?${params.toString()}`;
|
}/docker-container-logs?${params.toString()}`;
|
||||||
console.log("Connecting to WebSocket:", wsUrl);
|
console.log("Connecting to WebSocket:", wsUrl);
|
||||||
const ws = new WebSocket(wsUrl);
|
const ws = new WebSocket(wsUrl);
|
||||||
|
|
||||||
const resetNoDataTimeout = () => {
|
const resetNoDataTimeout = () => {
|
||||||
if (noDataTimeout) clearTimeout(noDataTimeout);
|
if (noDataTimeout) clearTimeout(noDataTimeout);
|
||||||
noDataTimeout = setTimeout(() => {
|
noDataTimeout = setTimeout(() => {
|
||||||
if (isCurrentConnection) {
|
if (isCurrentConnection) {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
}, 2000); // Wait 2 seconds for data before showing "No logs found"
|
}, 2000); // Wait 2 seconds for data before showing "No logs found"
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
if (!isCurrentConnection) {
|
if (!isCurrentConnection) {
|
||||||
ws.close();
|
ws.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log("WebSocket connected");
|
console.log("WebSocket connected");
|
||||||
resetNoDataTimeout();
|
resetNoDataTimeout();
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onmessage = (e) => {
|
ws.onmessage = (e) => {
|
||||||
if (!isCurrentConnection) return;
|
if (!isCurrentConnection) return;
|
||||||
setRawLogs((prev) => prev + e.data);
|
setRawLogs((prev) => prev + e.data);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
if (noDataTimeout) clearTimeout(noDataTimeout);
|
if (noDataTimeout) clearTimeout(noDataTimeout);
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onerror = (error) => {
|
ws.onerror = (error) => {
|
||||||
if (!isCurrentConnection) return;
|
if (!isCurrentConnection) return;
|
||||||
console.error("WebSocket error:", error);
|
console.error("WebSocket error:", error);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
if (noDataTimeout) clearTimeout(noDataTimeout);
|
if (noDataTimeout) clearTimeout(noDataTimeout);
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onclose = (e) => {
|
ws.onclose = (e) => {
|
||||||
if (!isCurrentConnection) return;
|
if (!isCurrentConnection) return;
|
||||||
console.log("WebSocket closed:", e.reason);
|
console.log("WebSocket closed:", e.reason);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
if (noDataTimeout) clearTimeout(noDataTimeout);
|
if (noDataTimeout) clearTimeout(noDataTimeout);
|
||||||
};
|
};
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
isCurrentConnection = false;
|
isCurrentConnection = false;
|
||||||
if (noDataTimeout) clearTimeout(noDataTimeout);
|
if (noDataTimeout) clearTimeout(noDataTimeout);
|
||||||
if (ws.readyState === WebSocket.OPEN) {
|
if (ws.readyState === WebSocket.OPEN) {
|
||||||
ws.close();
|
ws.close();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [containerId, serverId, lines, search, since]);
|
}, [containerId, serverId, lines, search, since]);
|
||||||
|
|
||||||
const handleDownload = () => {
|
const handleDownload = () => {
|
||||||
const logContent = filteredLogs
|
const logContent = filteredLogs
|
||||||
.map(
|
.map(
|
||||||
({ timestamp, message }: { timestamp: Date | null; message: string }) =>
|
({ timestamp, message }: { timestamp: Date | null; message: string }) =>
|
||||||
`${timestamp?.toISOString() || "No timestamp"} ${message}`
|
`${timestamp?.toISOString() || "No timestamp"} ${message}`,
|
||||||
)
|
)
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
const blob = new Blob([logContent], { type: "text/plain" });
|
const blob = new Blob([logContent], { type: "text/plain" });
|
||||||
const url = URL.createObjectURL(blob);
|
const url = URL.createObjectURL(blob);
|
||||||
const a = document.createElement("a");
|
const a = document.createElement("a");
|
||||||
const appName = data.Name.replace("/", "") || "app";
|
const appName = data.Name.replace("/", "") || "app";
|
||||||
const isoDate = new Date().toISOString();
|
const isoDate = new Date().toISOString();
|
||||||
a.href = url;
|
a.href = url;
|
||||||
a.download = `${appName}-${isoDate.slice(0, 10).replace(/-/g, "")}_${isoDate
|
a.download = `${appName}-${isoDate.slice(0, 10).replace(/-/g, "")}_${isoDate
|
||||||
.slice(11, 19)
|
.slice(11, 19)
|
||||||
.replace(/:/g, "")}.log.txt`;
|
.replace(/:/g, "")}.log.txt`;
|
||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
a.click();
|
a.click();
|
||||||
document.body.removeChild(a);
|
document.body.removeChild(a);
|
||||||
URL.revokeObjectURL(url);
|
URL.revokeObjectURL(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleFilter = (logs: LogLine[]) => {
|
const handleFilter = (logs: LogLine[]) => {
|
||||||
return logs.filter((log) => {
|
return logs.filter((log) => {
|
||||||
const logType = getLogType(log.message).type;
|
const logType = getLogType(log.message).type;
|
||||||
|
|
||||||
if (typeFilter.length === 0) {
|
if (typeFilter.length === 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return typeFilter.includes(logType);
|
return typeFilter.includes(logType);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setRawLogs("");
|
setRawLogs("");
|
||||||
setFilteredLogs([]);
|
setFilteredLogs([]);
|
||||||
}, [containerId]);
|
}, [containerId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const logs = parseLogs(rawLogs);
|
const logs = parseLogs(rawLogs);
|
||||||
const filtered = handleFilter(logs);
|
const filtered = handleFilter(logs);
|
||||||
setFilteredLogs(filtered);
|
setFilteredLogs(filtered);
|
||||||
}, [rawLogs, search, lines, since, typeFilter]);
|
}, [rawLogs, search, lines, since, typeFilter]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
|
|
||||||
if (autoScroll && scrollRef.current) {
|
if (autoScroll && scrollRef.current) {
|
||||||
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
||||||
}
|
}
|
||||||
}, [filteredLogs, autoScroll]);
|
}, [filteredLogs, autoScroll]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<div className="rounded-lg overflow-hidden">
|
<div className="rounded-lg overflow-hidden">
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="flex flex-wrap justify-between items-start sm:items-center gap-4">
|
<div className="flex flex-wrap justify-between items-start sm:items-center gap-4">
|
||||||
<div className="flex flex-wrap gap-4">
|
<div className="flex flex-wrap gap-4">
|
||||||
<Input
|
<Input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Number of lines to show"
|
placeholder="Number of lines to show"
|
||||||
value={lines}
|
value={lines}
|
||||||
onChange={handleLines}
|
onChange={handleLines}
|
||||||
className="inline-flex h-9 text-sm placeholder-gray-400 w-full sm:w-auto"
|
className="inline-flex h-9 text-sm placeholder-gray-400 w-full sm:w-auto"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Select value={since} onValueChange={handleSince}>
|
<SinceLogsFilter
|
||||||
<SelectTrigger className="sm:w-[180px] w-full h-9">
|
value={since}
|
||||||
<SelectValue placeholder="Time filter" />
|
onValueChange={handleSince}
|
||||||
</SelectTrigger>
|
showTimestamp={showTimestamp}
|
||||||
<SelectContent>
|
onTimestampChange={setShowTimestamp}
|
||||||
<SelectItem value="1h">Last hour</SelectItem>
|
/>
|
||||||
<SelectItem value="6h">Last 6 hours</SelectItem>
|
|
||||||
<SelectItem value="24h">Last 24 hours</SelectItem>
|
|
||||||
<SelectItem value="168h">Last 7 days</SelectItem>
|
|
||||||
<SelectItem value="720h">Last 30 days</SelectItem>
|
|
||||||
<SelectItem value="all">All time</SelectItem>
|
|
||||||
<SelectSeparator/>
|
|
||||||
<SelectItem value="timestamp">
|
|
||||||
{showTimestamp ? "Hide timestamp" : "Show timestamp"}
|
|
||||||
</SelectItem>
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
|
|
||||||
<StatusLogsFilter
|
<StatusLogsFilter
|
||||||
value={typeFilter}
|
value={typeFilter}
|
||||||
setValue={setTypeFilter}
|
setValue={setTypeFilter}
|
||||||
title="Log type"
|
title="Log type"
|
||||||
options={priorities}
|
options={priorities}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
type="search"
|
type="search"
|
||||||
placeholder="Search logs..."
|
placeholder="Search logs..."
|
||||||
value={search}
|
value={search}
|
||||||
onChange={handleSearch}
|
onChange={handleSearch}
|
||||||
className="inline-flex h-9 text-sm placeholder-gray-400 w-full sm:w-auto"
|
className="inline-flex h-9 text-sm placeholder-gray-400 w-full sm:w-auto"
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
<Button
|
||||||
|
variant="outline"
|
||||||
<Button
|
size="sm"
|
||||||
variant="outline"
|
className="h-9 sm:w-auto w-full"
|
||||||
size="sm"
|
onClick={handleDownload}
|
||||||
className="h-9 sm:w-auto w-full"
|
disabled={filteredLogs.length === 0 || !data?.Name}
|
||||||
onClick={handleDownload}
|
>
|
||||||
disabled={filteredLogs.length === 0 || !data?.Name}
|
<DownloadIcon className="mr-2 h-4 w-4" />
|
||||||
>
|
Download logs
|
||||||
<DownloadIcon className="mr-2 h-4 w-4" />
|
</Button>
|
||||||
Download logs
|
</div>
|
||||||
</Button>
|
<div
|
||||||
</div>
|
ref={scrollRef}
|
||||||
<div
|
onScroll={handleScroll}
|
||||||
ref={scrollRef}
|
className="h-[720px] overflow-y-auto space-y-0 border p-4 bg-[#d4d4d4] dark:bg-[#050506] rounded custom-logs-scrollbar"
|
||||||
onScroll={handleScroll}
|
>
|
||||||
className="h-[720px] overflow-y-auto space-y-0 border p-4 bg-[#d4d4d4] dark:bg-[#050506] rounded custom-logs-scrollbar"
|
{filteredLogs.length > 0 ? (
|
||||||
>
|
filteredLogs.map((filteredLog: LogLine, index: number) => (
|
||||||
{filteredLogs.length > 0 ? (
|
<TerminalLine
|
||||||
filteredLogs.map((filteredLog: LogLine, index: number) => (
|
key={index}
|
||||||
<TerminalLine
|
log={filteredLog}
|
||||||
key={index}
|
searchTerm={search}
|
||||||
log={filteredLog}
|
noTimestamp={!showTimestamp}
|
||||||
searchTerm={search}
|
/>
|
||||||
noTimestamp={!showTimestamp}
|
))
|
||||||
/>
|
) : isLoading ? (
|
||||||
))
|
<div className="flex justify-center items-center h-full text-muted-foreground">
|
||||||
) : isLoading ? (
|
<Loader2 className="h-6 w-6 animate-spin" />
|
||||||
<div className="flex justify-center items-center h-full text-muted-foreground">
|
</div>
|
||||||
<Loader2 className="h-6 w-6 animate-spin" />
|
) : (
|
||||||
</div>
|
<div className="flex justify-center items-center h-full text-muted-foreground">
|
||||||
) : (
|
No logs found
|
||||||
<div className="flex justify-center items-center h-full text-muted-foreground">
|
</div>
|
||||||
No logs found
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
);
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
import { Badge } from "@/components/ui/badge";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
Command,
|
||||||
|
CommandGroup,
|
||||||
|
CommandItem,
|
||||||
|
CommandList,
|
||||||
|
} from "@/components/ui/command";
|
||||||
|
import {
|
||||||
|
Popover,
|
||||||
|
PopoverContent,
|
||||||
|
PopoverTrigger,
|
||||||
|
} from "@/components/ui/popover";
|
||||||
|
import { Separator } from "@/components/ui/separator";
|
||||||
|
import { Switch } from "@/components/ui/switch";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { CheckIcon } from "lucide-react";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
type TimeFilter = "all" | "1h" | "6h" | "24h" | "168h" | "720h";
|
||||||
|
|
||||||
|
const timeRanges = [
|
||||||
|
{
|
||||||
|
label: "All time",
|
||||||
|
value: "all",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Last hour",
|
||||||
|
value: "1h",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Last 6 hours",
|
||||||
|
value: "6h",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Last 24 hours",
|
||||||
|
value: "24h",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Last 7 days",
|
||||||
|
value: "168h",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Last 30 days",
|
||||||
|
value: "720h",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
interface SinceLogsFilterProps {
|
||||||
|
value: string;
|
||||||
|
onValueChange: (value: TimeFilter) => void;
|
||||||
|
showTimestamp: boolean;
|
||||||
|
onTimestampChange: (show: boolean) => void;
|
||||||
|
title?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SinceLogsFilter({
|
||||||
|
value,
|
||||||
|
onValueChange,
|
||||||
|
showTimestamp,
|
||||||
|
onTimestampChange,
|
||||||
|
title = "Time range",
|
||||||
|
}: SinceLogsFilterProps) {
|
||||||
|
const selectedLabel =
|
||||||
|
timeRanges.find((range) => range.value === value)?.label ??
|
||||||
|
"Select time range";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Popover>
|
||||||
|
<PopoverTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
className="h-9 bg-input text-sm placeholder-gray-400 w-full sm:w-auto"
|
||||||
|
>
|
||||||
|
{title}
|
||||||
|
<Separator orientation="vertical" className="mx-2 h-4" />
|
||||||
|
<div className="space-x-1 flex">
|
||||||
|
<Badge variant="blank" className="rounded-sm px-1 font-normal">
|
||||||
|
{selectedLabel}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
</Button>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent className="w-[200px] p-0" align="start">
|
||||||
|
<Command>
|
||||||
|
<CommandList>
|
||||||
|
<CommandGroup>
|
||||||
|
{timeRanges.map((range) => {
|
||||||
|
const isSelected = value === range.value;
|
||||||
|
return (
|
||||||
|
<CommandItem
|
||||||
|
key={range.value}
|
||||||
|
onSelect={() => onValueChange(range.value)}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"mr-2 flex h-4 w-4 items-center rounded-sm border border-primary",
|
||||||
|
isSelected
|
||||||
|
? "bg-primary text-primary-foreground"
|
||||||
|
: "opacity-50 [&_svg]:invisible",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<CheckIcon className={cn("h-4 w-4")} />
|
||||||
|
</div>
|
||||||
|
<span className="text-sm">{range.label}</span>
|
||||||
|
</CommandItem>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</CommandGroup>
|
||||||
|
</CommandList>
|
||||||
|
</Command>
|
||||||
|
<Separator className="my-2" />
|
||||||
|
<div className="p-2 flex items-center justify-between">
|
||||||
|
<span className="text-sm">Show timestamps</span>
|
||||||
|
<Switch checked={showTimestamp} onCheckedChange={onTimestampChange} />
|
||||||
|
</div>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -2,9 +2,7 @@ import { Badge } from "@/components/ui/badge";
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
Command,
|
Command,
|
||||||
CommandEmpty,
|
|
||||||
CommandGroup,
|
CommandGroup,
|
||||||
CommandInput,
|
|
||||||
CommandItem,
|
CommandItem,
|
||||||
CommandList,
|
CommandList,
|
||||||
} from "@/components/ui/command";
|
} from "@/components/ui/command";
|
||||||
@@ -16,7 +14,7 @@ import {
|
|||||||
import { Separator } from "@/components/ui/separator";
|
import { Separator } from "@/components/ui/separator";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { CheckIcon } from "lucide-react";
|
import { CheckIcon } from "lucide-react";
|
||||||
import React from "react";
|
import type React from "react";
|
||||||
|
|
||||||
interface StatusLogsFilterProps {
|
interface StatusLogsFilterProps {
|
||||||
value?: string[];
|
value?: string[];
|
||||||
@@ -36,42 +34,98 @@ export function StatusLogsFilter({
|
|||||||
options,
|
options,
|
||||||
}: StatusLogsFilterProps) {
|
}: StatusLogsFilterProps) {
|
||||||
const selectedValues = new Set(value as string[]);
|
const selectedValues = new Set(value as string[]);
|
||||||
|
const allSelected = selectedValues.size === 0;
|
||||||
|
|
||||||
|
const getSelectedBadges = () => {
|
||||||
|
if (allSelected) {
|
||||||
|
return (
|
||||||
|
<Badge variant="blank" className="rounded-sm px-1 font-normal">
|
||||||
|
All
|
||||||
|
</Badge>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedValues.size >= 1) {
|
||||||
|
const selected = options.find((opt) => selectedValues.has(opt.value));
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Badge
|
||||||
|
variant={
|
||||||
|
selected?.value === "success"
|
||||||
|
? "green"
|
||||||
|
: selected?.value === "error"
|
||||||
|
? "red"
|
||||||
|
: selected?.value === "warning"
|
||||||
|
? "orange"
|
||||||
|
: selected?.value === "info"
|
||||||
|
? "blue"
|
||||||
|
: selected?.value === "debug"
|
||||||
|
? "yellow"
|
||||||
|
: "blank"
|
||||||
|
}
|
||||||
|
className="rounded-sm px-1 font-normal"
|
||||||
|
>
|
||||||
|
{selected?.label}
|
||||||
|
</Badge>
|
||||||
|
{selectedValues.size > 1 && (
|
||||||
|
<Badge variant="blank" className="rounded-sm px-1 font-normal">
|
||||||
|
+{selectedValues.size - 1}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Popover>
|
<Popover>
|
||||||
<PopoverTrigger asChild>
|
<PopoverTrigger asChild>
|
||||||
<Button variant="outline" size="sm" className="h-9 bg-input text-sm placeholder-gray-400 w-full sm:w-auto">
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
className="h-9 bg-input text-sm placeholder-gray-400 w-full sm:w-auto"
|
||||||
|
>
|
||||||
{title}
|
{title}
|
||||||
<Separator orientation="vertical" className="mx-2 h-4" />
|
<Separator orientation="vertical" className="mx-2 h-4" />
|
||||||
<div className="space-x-1 flex">
|
<div className="space-x-1 flex">{getSelectedBadges()}</div>
|
||||||
<Badge
|
|
||||||
variant="blank"
|
|
||||||
className="rounded-sm px-1 font-normal"
|
|
||||||
>
|
|
||||||
{selectedValues.size} selected
|
|
||||||
</Badge>
|
|
||||||
</div>
|
|
||||||
</Button>
|
</Button>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent className="w-[200px] p-0" align="start">
|
<PopoverContent className="w-[200px] p-0" align="start">
|
||||||
<Command>
|
<Command>
|
||||||
<CommandInput placeholder={title} />
|
|
||||||
<CommandList>
|
<CommandList>
|
||||||
<CommandEmpty>No results found.</CommandEmpty>
|
|
||||||
<CommandGroup>
|
<CommandGroup>
|
||||||
|
<CommandItem
|
||||||
|
onSelect={() => {
|
||||||
|
setValue?.([]); // Empty array means "All"
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"mr-2 flex h-4 w-4 items-center rounded-sm border border-primary",
|
||||||
|
allSelected
|
||||||
|
? "bg-primary text-primary-foreground"
|
||||||
|
: "opacity-50 [&_svg]:invisible",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<CheckIcon className={cn("h-4 w-4")} />
|
||||||
|
</div>
|
||||||
|
<Badge variant="blank">All</Badge>
|
||||||
|
</CommandItem>
|
||||||
{options.map((option) => {
|
{options.map((option) => {
|
||||||
const isSelected = selectedValues.has(option.value);
|
const isSelected = selectedValues.has(option.value);
|
||||||
return (
|
return (
|
||||||
<CommandItem
|
<CommandItem
|
||||||
key={option.value}
|
key={option.value}
|
||||||
onSelect={() => {
|
onSelect={() => {
|
||||||
|
const newValues = new Set(selectedValues);
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
selectedValues.delete(option.value);
|
newValues.delete(option.value);
|
||||||
} else {
|
} else {
|
||||||
selectedValues.add(option.value);
|
newValues.add(option.value);
|
||||||
}
|
}
|
||||||
const filterValues = Array.from(selectedValues);
|
setValue?.(Array.from(newValues));
|
||||||
setValue?.(filterValues.length ? filterValues : []);
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@@ -87,18 +141,27 @@ export function StatusLogsFilter({
|
|||||||
{option.icon && (
|
{option.icon && (
|
||||||
<option.icon className="mr-2 h-4 w-4 text-muted-foreground" />
|
<option.icon className="mr-2 h-4 w-4 text-muted-foreground" />
|
||||||
)}
|
)}
|
||||||
<Badge variant={
|
<Badge
|
||||||
option.value === 'success' ? 'green' :
|
variant={
|
||||||
option.value === 'error' ? 'red' :
|
option.value === "success"
|
||||||
option.value === 'warning' ? 'orange' :
|
? "green"
|
||||||
option.value === 'info' ? 'blue' :
|
: option.value === "error"
|
||||||
option.value === 'debug' ? 'yellow' : 'blank'
|
? "red"
|
||||||
} >{option.label}</Badge>
|
: option.value === "warning"
|
||||||
|
? "orange"
|
||||||
|
: option.value === "info"
|
||||||
|
? "blue"
|
||||||
|
: option.value === "debug"
|
||||||
|
? "yellow"
|
||||||
|
: "blank"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{option.label}
|
||||||
|
</Badge>
|
||||||
</CommandItem>
|
</CommandItem>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</CommandGroup>
|
</CommandGroup>
|
||||||
|
|
||||||
</CommandList>
|
</CommandList>
|
||||||
</Command>
|
</Command>
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export type LogType = "error" | "warning" | "success" | "info" | "debug";
|
export type LogType = "error" | "warning" | "success" | "info" | "debug";
|
||||||
export type LogVariant = "red" | "yellow" | "green" | "blue" | "orange";
|
export type LogVariant = "red" | "yellow" | "green" | "blue" | "orange";
|
||||||
|
|
||||||
export interface LogLine {
|
export interface LogLine {
|
||||||
rawTimestamp: string | null;
|
rawTimestamp: string | null;
|
||||||
@@ -138,8 +138,12 @@ export const getLogType = (message: string): LogStyle => {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
/(?:^|\s)(?:info|inf):?\s/i.test(lowerMessage) ||
|
/(?:^|\s)(?:info|inf):?\s/i.test(lowerMessage) ||
|
||||||
/\[(info|log|debug|trace|server|db|api|http|request|response)\]/i.test(lowerMessage) ||
|
/\[(info|log|debug|trace|server|db|api|http|request|response)\]/i.test(
|
||||||
/\b(?:version|config|import|load|get|HTTP|PATCH|POST|debug)\b:?/i.test(lowerMessage)
|
lowerMessage,
|
||||||
|
) ||
|
||||||
|
/\b(?:version|config|import|load|get|HTTP|PATCH|POST|debug)\b:?/i.test(
|
||||||
|
lowerMessage,
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
return LOG_STYLES.debug;
|
return LOG_STYLES.debug;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user