Skip to content
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

chore: add open log dir to troubleshooting modal #2605

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 36 additions & 20 deletions web/containers/ModalTroubleShoot/AppLogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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 ? (
Expand Down
57 changes: 37 additions & 20 deletions web/containers/ServerLogs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 })

Expand Down Expand Up @@ -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 ? (
<>
<CheckIcon size={14} className="text-green-600" />
<span>Copying...</span>
</>
) : (
<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">
<>
<CopyIcon size={14} />
<span>Copy All</span>
<FolderIcon size={14} />
<span>Open</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 ? (
Expand Down
3 changes: 3 additions & 0 deletions web/hooks/usePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export const usePath = () => {
if (!assistantId) return
filePath = await joinPath(['assistants', assistantId])
break
case 'Logs':
filePath = 'logs'
break
default:
break
}
Expand Down
Loading