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

View File

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

View File

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