chore: add open log dir to troubleshooting modal (#2605)

This commit is contained in:
Louis 2024-04-04 08:55:00 +07:00 committed by GitHub
parent 931f1da28e
commit 52654b1055
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 76 additions and 40 deletions

View File

@ -2,14 +2,16 @@ import React, { useEffect, useState } from 'react'
import { Button } from '@janhq/uikit' import { Button } from '@janhq/uikit'
import { CopyIcon, CheckIcon } from 'lucide-react' import { CopyIcon, CheckIcon, FolderIcon } from 'lucide-react'
import { useClipboard } from '@/hooks/useClipboard' import { useClipboard } from '@/hooks/useClipboard'
import { useLogs } from '@/hooks/useLogs' import { useLogs } from '@/hooks/useLogs'
import { usePath } from '@/hooks/usePath'
const AppLogs = () => { const AppLogs = () => {
const { getLogs } = useLogs() const { getLogs } = useLogs()
const [logs, setLogs] = useState<string[]>([]) const [logs, setLogs] = useState<string[]>([])
const { onRevealInFinder } = usePath()
useEffect(() => { useEffect(() => {
getLogs('app').then((log) => { getLogs('app').then((log) => {
@ -26,27 +28,41 @@ const AppLogs = () => {
return ( return (
<> <>
<div className="absolute -top-11 right-2"> <div className="absolute -top-11 right-2">
<Button <div className="flex w-full flex-row gap-2">
themes="outline" <Button
className="bg-white dark:bg-secondary/50" themes="outline"
onClick={() => { className="bg-white dark:bg-secondary/50"
clipboard.copy(logs.slice(-50) ?? '') onClick={() => onRevealInFinder('Logs')}
}} >
> <div className="flex items-center space-x-2">
<div className="flex items-center space-x-2">
{clipboard.copied ? (
<> <>
<CheckIcon size={14} className="text-green-600" /> <FolderIcon size={14} />
<span>Copying...</span> <span>Open</span>
</> </>
) : ( </div>
<> </Button>
<CopyIcon size={14} /> <Button
<span>Copy All</span> themes="outline"
</> className="bg-white dark:bg-secondary/50"
)} onClick={() => {
</div> clipboard.copy(logs.slice(-50) ?? '')
</Button> }}
>
<div className="flex items-center space-x-2">
{clipboard.copied ? (
<>
<CheckIcon size={14} className="text-green-600" />
<span>Copying...</span>
</>
) : (
<>
<CopyIcon size={14} />
<span>Copy All</span>
</>
)}
</div>
</Button>
</div>
</div> </div>
<div className="overflow-hidden"> <div className="overflow-hidden">
{logs.length > 1 ? ( {logs.length > 1 ? (

View File

@ -6,11 +6,13 @@ import React from 'react'
import { Button } from '@janhq/uikit' import { Button } from '@janhq/uikit'
import { useAtomValue } from 'jotai' import { useAtomValue } from 'jotai'
import { CopyIcon, CheckIcon } from 'lucide-react' import { CopyIcon, CheckIcon, FolderIcon } from 'lucide-react'
import { useClipboard } from '@/hooks/useClipboard' import { useClipboard } from '@/hooks/useClipboard'
import { useLogs } from '@/hooks/useLogs' import { useLogs } from '@/hooks/useLogs'
import { usePath } from '@/hooks/usePath'
import { serverEnabledAtom } from '@/helpers/atoms/LocalServer.atom' import { serverEnabledAtom } from '@/helpers/atoms/LocalServer.atom'
type ServerLogsProps = { limit?: number; withCopy?: boolean } type ServerLogsProps = { limit?: number; withCopy?: boolean }
@ -20,6 +22,7 @@ const ServerLogs = (props: ServerLogsProps) => {
const { getLogs } = useLogs() const { getLogs } = useLogs()
const serverEnabled = useAtomValue(serverEnabledAtom) const serverEnabled = useAtomValue(serverEnabledAtom)
const [logs, setLogs] = useState<string[]>([]) const [logs, setLogs] = useState<string[]>([])
const { onRevealInFinder } = usePath()
const clipboard = useClipboard({ timeout: 1000 }) const clipboard = useClipboard({ timeout: 1000 })
@ -55,27 +58,41 @@ const ServerLogs = (props: ServerLogsProps) => {
return ( return (
<> <>
<div className="absolute -top-11 right-2"> <div className="absolute -top-11 right-2">
<Button <div className="flex w-full flex-row gap-2">
themes="outline" <Button
className="bg-white dark:bg-secondary/50" themes="outline"
onClick={() => { className="bg-white dark:bg-secondary/50"
clipboard.copy(logs.slice(-100) ?? '') onClick={() => onRevealInFinder('Logs')}
}} >
> <div className="flex items-center space-x-2">
<div className="flex items-center space-x-2">
{clipboard.copied ? (
<> <>
<CheckIcon size={14} className="text-green-600" /> <FolderIcon size={14} />
<span>Copying...</span> <span>Open</span>
</> </>
) : ( </div>
<> </Button>
<CopyIcon size={14} /> <Button
<span>Copy All</span> themes="outline"
</> className="bg-white dark:bg-secondary/50"
)} onClick={() => {
</div> clipboard.copy(logs.slice(-100) ?? '')
</Button> }}
>
<div className="flex items-center space-x-2">
{clipboard.copied ? (
<>
<CheckIcon size={14} className="text-green-600" />
<span>Copying...</span>
</>
) : (
<>
<CopyIcon size={14} />
<span>Copy All</span>
</>
)}
</div>
</Button>
</div>
</div> </div>
<div className="overflow-hidden"> <div className="overflow-hidden">
{logs.length > 1 ? ( {logs.length > 1 ? (

View File

@ -31,6 +31,9 @@ export const usePath = () => {
if (!assistantId) return if (!assistantId) return
filePath = await joinPath(['assistants', assistantId]) filePath = await joinPath(['assistants', assistantId])
break break
case 'Logs':
filePath = 'logs'
break
default: default:
break break
} }