mirror of
https://github.com/langgenius/dify.git
synced 2025-11-30 21:06:48 +00:00
Signed-off-by: -LAN- <laipz8200@outlook.com> Co-authored-by: twwu <twwu@dify.ai> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: jyong <718720800@qq.com> Co-authored-by: Wu Tianwei <30284043+WTW0313@users.noreply.github.com> Co-authored-by: QuantumGhost <obelisk.reg+git@gmail.com> Co-authored-by: lyzno1 <yuanyouhuilyz@gmail.com> Co-authored-by: quicksand <quicksandzn@gmail.com> Co-authored-by: Jyong <76649700+JohnJyong@users.noreply.github.com> Co-authored-by: lyzno1 <92089059+lyzno1@users.noreply.github.com> Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: Yongtao Huang <yongtaoh2022@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: nite-knite <nkCoding@gmail.com> Co-authored-by: Hanqing Zhao <sherry9277@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Harry <xh001x@hotmail.com>
67 lines
2.0 KiB
TypeScript
67 lines
2.0 KiB
TypeScript
import React, { useState } from 'react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import { ApiAggregate } from '@/app/components/base/icons/src/vender/knowledge'
|
|
import Indicator from '@/app/components/header/indicator'
|
|
import cn from '@/utils/classnames'
|
|
import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger } from '@/app/components/base/portal-to-follow-elem'
|
|
import Card from './card'
|
|
|
|
type ServiceApiProps = {
|
|
expand: boolean
|
|
apiBaseUrl: string
|
|
apiEnabled: boolean
|
|
}
|
|
|
|
const ServiceApi = ({
|
|
expand,
|
|
apiBaseUrl,
|
|
apiEnabled,
|
|
}: ServiceApiProps) => {
|
|
const { t } = useTranslation()
|
|
const [open, setOpen] = useState(false)
|
|
|
|
const handleToggle = () => {
|
|
setOpen(!open)
|
|
}
|
|
|
|
return (
|
|
<div className='p-3 pt-2'>
|
|
<PortalToFollowElem
|
|
open={open}
|
|
onOpenChange={setOpen}
|
|
placement='top-start'
|
|
offset={{
|
|
mainAxis: 4,
|
|
crossAxis: -4,
|
|
}}
|
|
>
|
|
<PortalToFollowElemTrigger
|
|
className='w-full'
|
|
onClick={handleToggle}
|
|
>
|
|
<div className={cn(
|
|
'relative flex h-8 cursor-pointer items-center gap-2 rounded-lg border border-components-panel-border px-3',
|
|
!expand && 'w-8 justify-center',
|
|
open ? 'bg-state-base-hover' : 'hover:bg-state-base-hover',
|
|
)}>
|
|
<ApiAggregate className='size-4 shrink-0 text-text-secondary' />
|
|
{expand && <div className='system-sm-medium grow text-text-secondary'>{t('dataset.serviceApi.title')}</div>}
|
|
<Indicator
|
|
className={cn('shrink-0', !expand && 'absolute -right-px -top-px')}
|
|
color={apiEnabled ? 'green' : 'yellow'}
|
|
/>
|
|
</div>
|
|
</PortalToFollowElemTrigger>
|
|
<PortalToFollowElemContent>
|
|
<Card
|
|
apiEnabled={apiEnabled}
|
|
apiBaseUrl={apiBaseUrl}
|
|
/>
|
|
</PortalToFollowElemContent>
|
|
</PortalToFollowElem>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default React.memo(ServiceApi)
|