fix tracing dropdown

This commit is contained in:
JzoNg 2025-01-08 15:40:13 +08:00
parent 5481b42257
commit 05d273d643
3 changed files with 20 additions and 26 deletions

View File

@ -4,19 +4,15 @@ import React, { useCallback, useEffect, useRef, useState } from 'react'
import { import {
RiEqualizer2Line, RiEqualizer2Line,
} from '@remixicon/react' } from '@remixicon/react'
import { useTranslation } from 'react-i18next'
import type { PopupProps } from './config-popup' import type { PopupProps } from './config-popup'
import ConfigPopup from './config-popup' import ConfigPopup from './config-popup'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import Button from '@/app/components/base/button'
import { import {
PortalToFollowElem, PortalToFollowElem,
PortalToFollowElemContent, PortalToFollowElemContent,
PortalToFollowElemTrigger, PortalToFollowElemTrigger,
} from '@/app/components/base/portal-to-follow-elem' } from '@/app/components/base/portal-to-follow-elem'
const I18N_PREFIX = 'app.tracing'
type Props = { type Props = {
readOnly: boolean readOnly: boolean
className?: string className?: string
@ -30,7 +26,6 @@ const ConfigBtn: FC<Props> = ({
controlShowPopup, controlShowPopup,
...popupProps ...popupProps
}) => { }) => {
const { t } = useTranslation()
const [open, doSetOpen] = useState(false) const [open, doSetOpen] = useState(false)
const openRef = useRef(open) const openRef = useRef(open)
const setOpen = useCallback((v: boolean) => { const setOpen = useCallback((v: boolean) => {
@ -52,21 +47,6 @@ const ConfigBtn: FC<Props> = ({
if (popupProps.readOnly && !hasConfigured) if (popupProps.readOnly && !hasConfigured)
return null return null
const triggerContent = hasConfigured
? (
<div className={cn(className, 'p-1 rounded-md')}>
<RiEqualizer2Line className='w-4 h-4 text-text-tertiary' />
</div>
)
: (
<Button variant='primary'
className={cn(className, '!h-8 !px-3 select-none')}
>
<RiEqualizer2Line className='mr-1 w-4 h-4' />
<span className='text-[13px]'>{t(`${I18N_PREFIX}.config`)}</span>
</Button>
)
return ( return (
<PortalToFollowElem <PortalToFollowElem
open={open} open={open}
@ -74,11 +54,13 @@ const ConfigBtn: FC<Props> = ({
placement='bottom-end' placement='bottom-end'
offset={{ offset={{
mainAxis: 12, mainAxis: 12,
crossAxis: hasConfigured ? 8 : 0, crossAxis: hasConfigured ? 8 : 49,
}} }}
> >
<PortalToFollowElemTrigger onClick={handleTrigger}> <PortalToFollowElemTrigger onClick={handleTrigger}>
{triggerContent} <div className={cn(className, 'p-1 rounded-md')}>
<RiEqualizer2Line className='w-4 h-4 text-text-tertiary' />
</div>
</PortalToFollowElemTrigger> </PortalToFollowElemTrigger>
<PortalToFollowElemContent className='z-[11]'> <PortalToFollowElemContent className='z-[11]'>
<ConfigPopup {...popupProps} /> <ConfigPopup {...popupProps} />

View File

@ -3,7 +3,6 @@ import type { FC } from 'react'
import React, { useCallback, useEffect, useState } from 'react' import React, { useCallback, useEffect, useState } from 'react'
import { import {
RiArrowDownDoubleLine, RiArrowDownDoubleLine,
RiEqualizer2Line,
} from '@remixicon/react' } from '@remixicon/react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { usePathname } from 'next/navigation' import { usePathname } from 'next/navigation'
@ -151,8 +150,21 @@ const Panel: FC = () => {
<> <>
<TracingIcon size='md' /> <TracingIcon size='md' />
<div className='mx-2 system-sm-semibold text-text-secondary'>{t(`${I18N_PREFIX}.title`)}</div> <div className='mx-2 system-sm-semibold text-text-secondary'>{t(`${I18N_PREFIX}.title`)}</div>
<div className='p-1 rounded-md'> <div className='flex items-center' onClick={e => e.stopPropagation()}>
<RiEqualizer2Line className='w-4 h-4 text-text-tertiary' /> <ConfigButton
appId={appId}
readOnly={readOnly}
hasConfigured={false}
enabled={enabled}
onStatusChange={handleTracingEnabledChange}
chosenProvider={inUseTracingProvider}
onChooseProvider={handleChooseProvider}
langSmithConfig={langSmithConfig}
langFuseConfig={langFuseConfig}
onConfigUpdated={handleTracingConfigUpdated}
onConfigRemoved={handleTracingConfigRemoved}
controlShowPopup={controlShowPopup}
/>
</div> </div>
<Divider type='vertical' className='h-3.5' /> <Divider type='vertical' className='h-3.5' />
<div className='p-1 rounded-md'> <div className='p-1 rounded-md'>

View File

@ -127,7 +127,7 @@ export const AppContextProvider: FC<AppContextProviderProps> = ({ children }) =>
setCurrentWorkspace(currentWorkspaceResponse) setCurrentWorkspace(currentWorkspaceResponse)
}, [currentWorkspaceResponse]) }, [currentWorkspaceResponse])
const [theme, setTheme] = useState<Theme>(Theme.dark) const [theme, setTheme] = useState<Theme>(Theme.light)
const handleSetTheme = useCallback((theme: Theme) => { const handleSetTheme = useCallback((theme: Theme) => {
setTheme(theme) setTheme(theme)
globalThis.document.documentElement.setAttribute('data-theme', theme) globalThis.document.documentElement.setAttribute('data-theme', theme)