Compare commits

...

4 Commits

Author SHA1 Message Date
NFish
151d68b5b3 fix: add github ci on branch v141-hotfix 2025-05-28 18:28:33 +08:00
NFish
9d38441c8d Merge branch 'fix/branding-broken' into v141-hotfix 2025-05-28 18:23:27 +08:00
NFish
7ab0b7346e fix: branding logo broken 2025-05-28 18:23:10 +08:00
zxhlyh
861cdbd8b6 fix: workflow plugins list update (#20357) 2025-05-28 17:46:36 +08:00
14 changed files with 106 additions and 60 deletions

View File

@@ -6,6 +6,7 @@ on:
- "main" - "main"
- "deploy/dev" - "deploy/dev"
- "deploy/enterprise" - "deploy/enterprise"
- "v141-hotfix"
tags: tags:
- "*" - "*"

View File

@@ -6,10 +6,12 @@ import Button from '../components/base/button'
import Avatar from './avatar' import Avatar from './avatar'
import DifyLogo from '@/app/components/base/logo/dify-logo' import DifyLogo from '@/app/components/base/logo/dify-logo'
import { useCallback } from 'react' import { useCallback } from 'react'
import { useGlobalPublicStore } from '@/context/global-public-context'
const Header = () => { const Header = () => {
const { t } = useTranslation() const { t } = useTranslation()
const router = useRouter() const router = useRouter()
const systemFeatures = useGlobalPublicStore(s => s.systemFeatures)
const back = useCallback(() => { const back = useCallback(() => {
router.back() router.back()
@@ -19,7 +21,13 @@ const Header = () => {
<div className='flex flex-1 items-center justify-between px-4'> <div className='flex flex-1 items-center justify-between px-4'>
<div className='flex items-center gap-3'> <div className='flex items-center gap-3'>
<div className='flex cursor-pointer items-center' onClick={back}> <div className='flex cursor-pointer items-center' onClick={back}>
<DifyLogo /> {systemFeatures.branding.enabled && systemFeatures.branding.login_page_logo
? <img
src={systemFeatures.branding.login_page_logo}
className='block h-[22px] w-auto object-contain'
alt='Dify logo'
/>
: <DifyLogo />}
</div> </div>
<div className='h-4 w-[1px] origin-center rotate-[11.31deg] bg-divider-regular' /> <div className='h-4 w-[1px] origin-center rotate-[11.31deg] bg-divider-regular' />
<p className='title-3xl-semi-bold relative mt-[-2px] text-text-primary'>{t('common.account.account')}</p> <p className='title-3xl-semi-bold relative mt-[-2px] text-text-primary'>{t('common.account.account')}</p>

View File

@@ -148,10 +148,12 @@ const Sidebar = ({ isPanel }: Props) => {
'flex shrink-0 items-center gap-1.5 px-1', 'flex shrink-0 items-center gap-1.5 px-1',
)}> )}>
<div className='system-2xs-medium-uppercase text-text-tertiary'>{t('share.chat.poweredBy')}</div> <div className='system-2xs-medium-uppercase text-text-tertiary'>{t('share.chat.poweredBy')}</div>
{systemFeatures.branding.enabled ? ( {
<img src={systemFeatures.branding.login_page_logo} alt='logo' className='block h-5 w-auto' /> systemFeatures.branding.enabled && systemFeatures.branding.workspace_logo
) : ( ? <img src={systemFeatures.branding.workspace_logo} alt='logo' className='block h-5 w-auto' />
<DifyLogo size='small' />) : appData?.custom_config?.replace_webapp_logo
? <img src={`${appData?.custom_config?.replace_webapp_logo}`} alt='logo' className='block h-5 w-auto' />
: <DifyLogo size='small' />
} }
</div> </div>
)} )}

View File

@@ -13,6 +13,7 @@ import Divider from '@/app/components/base/divider'
import ViewFormDropdown from '@/app/components/base/chat/embedded-chatbot/inputs-form/view-form-dropdown' import ViewFormDropdown from '@/app/components/base/chat/embedded-chatbot/inputs-form/view-form-dropdown'
import DifyLogo from '@/app/components/base/logo/dify-logo' import DifyLogo from '@/app/components/base/logo/dify-logo'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import { useGlobalPublicStore } from '@/context/global-public-context'
export type IHeaderProps = { export type IHeaderProps = {
isMobile?: boolean isMobile?: boolean
@@ -42,6 +43,7 @@ const Header: FC<IHeaderProps> = ({
const [parentOrigin, setParentOrigin] = useState('') const [parentOrigin, setParentOrigin] = useState('')
const [showToggleExpandButton, setShowToggleExpandButton] = useState(false) const [showToggleExpandButton, setShowToggleExpandButton] = useState(false)
const [expanded, setExpanded] = useState(false) const [expanded, setExpanded] = useState(false)
const systemFeatures = useGlobalPublicStore(s => s.systemFeatures)
const handleMessageReceived = useCallback((event: MessageEvent) => { const handleMessageReceived = useCallback((event: MessageEvent) => {
let currentParentOrigin = parentOrigin let currentParentOrigin = parentOrigin
@@ -85,12 +87,13 @@ const Header: FC<IHeaderProps> = ({
'flex shrink-0 items-center gap-1.5 px-2', 'flex shrink-0 items-center gap-1.5 px-2',
)}> )}>
<div className='system-2xs-medium-uppercase text-text-tertiary'>{t('share.chat.poweredBy')}</div> <div className='system-2xs-medium-uppercase text-text-tertiary'>{t('share.chat.poweredBy')}</div>
{appData?.custom_config?.replace_webapp_logo && ( {
<img src={appData?.custom_config?.replace_webapp_logo} alt='logo' className='block h-5 w-auto' /> systemFeatures.branding.enabled && systemFeatures.branding.workspace_logo
)} ? <img src={systemFeatures.branding.workspace_logo} alt='logo' className='block h-5 w-auto' />
{!appData?.custom_config?.replace_webapp_logo && ( : appData?.custom_config?.replace_webapp_logo
<DifyLogo size='small' /> ? <img src={`${appData?.custom_config?.replace_webapp_logo}`} alt='logo' className='block h-5 w-auto' />
)} : <DifyLogo size='small' />
}
</div> </div>
)} )}
</div> </div>

View File

@@ -22,6 +22,7 @@ import ChatWrapper from '@/app/components/base/chat/embedded-chatbot/chat-wrappe
import DifyLogo from '@/app/components/base/logo/dify-logo' import DifyLogo from '@/app/components/base/logo/dify-logo'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import useDocumentTitle from '@/hooks/use-document-title' import useDocumentTitle from '@/hooks/use-document-title'
import { useGlobalPublicStore } from '@/context/global-public-context'
const Chatbot = () => { const Chatbot = () => {
const { const {
@@ -37,6 +38,7 @@ const Chatbot = () => {
themeBuilder, themeBuilder,
} = useEmbeddedChatbotContext() } = useEmbeddedChatbotContext()
const { t } = useTranslation() const { t } = useTranslation()
const systemFeatures = useGlobalPublicStore(s => s.systemFeatures)
const customConfig = appData?.custom_config const customConfig = appData?.custom_config
const site = appData?.site const site = appData?.site
@@ -115,12 +117,13 @@ const Chatbot = () => {
'flex shrink-0 items-center gap-1.5 px-2', 'flex shrink-0 items-center gap-1.5 px-2',
)}> )}>
<div className='system-2xs-medium-uppercase text-text-tertiary'>{t('share.chat.poweredBy')}</div> <div className='system-2xs-medium-uppercase text-text-tertiary'>{t('share.chat.poweredBy')}</div>
{appData?.custom_config?.replace_webapp_logo && ( {
<img src={appData?.custom_config?.replace_webapp_logo} alt='logo' className='block h-5 w-auto' /> systemFeatures.branding.enabled && systemFeatures.branding.workspace_logo
)} ? <img src={systemFeatures.branding.workspace_logo} alt='logo' className='block h-5 w-auto' />
{!appData?.custom_config?.replace_webapp_logo && ( : appData?.custom_config?.replace_webapp_logo
<DifyLogo size='small' /> ? <img src={`${appData?.custom_config?.replace_webapp_logo}`} alt='logo' className='block h-5 w-auto' />
)} : <DifyLogo size='small' />
}
</div> </div>
)} )}
</div> </div>

View File

@@ -3,7 +3,6 @@ import type { FC } from 'react'
import classNames from '@/utils/classnames' import classNames from '@/utils/classnames'
import useTheme from '@/hooks/use-theme' import useTheme from '@/hooks/use-theme'
import { basePath } from '@/utils/var' import { basePath } from '@/utils/var'
import { useGlobalPublicStore } from '@/context/global-public-context'
export type LogoStyle = 'default' | 'monochromeWhite' export type LogoStyle = 'default' | 'monochromeWhite'
export const logoPathMap: Record<LogoStyle, string> = { export const logoPathMap: Record<LogoStyle, string> = {
@@ -32,18 +31,12 @@ const DifyLogo: FC<DifyLogoProps> = ({
}) => { }) => {
const { theme } = useTheme() const { theme } = useTheme()
const themedStyle = (theme === 'dark' && style === 'default') ? 'monochromeWhite' : style const themedStyle = (theme === 'dark' && style === 'default') ? 'monochromeWhite' : style
const { systemFeatures } = useGlobalPublicStore()
const hasBrandingLogo = Boolean(systemFeatures.branding.enabled && systemFeatures.branding.workspace_logo)
let src = `${basePath}${logoPathMap[themedStyle]}`
if (hasBrandingLogo)
src = systemFeatures.branding.workspace_logo
return ( return (
<img <img
src={src} src={`${basePath}${logoPathMap[themedStyle]}`}
className={classNames('block object-contain', logoSizeMap[size], hasBrandingLogo && 'w-auto', className)} className={classNames('block object-contain', logoSizeMap[size], className)}
alt={hasBrandingLogo ? 'Logo' : 'Dify logo'} alt='Dify logo'
/> />
) )
} }

View File

@@ -40,7 +40,7 @@ const TabSlider: FC<TabSliderProps> = ({
const newIndex = options.findIndex(option => option.value === value) const newIndex = options.findIndex(option => option.value === value)
setActiveIndex(newIndex) setActiveIndex(newIndex)
updateSliderStyle(newIndex) updateSliderStyle(newIndex)
}, [value, options, pluginList]) }, [value, options, pluginList?.total])
return ( return (
<div className={cn(className, 'relative inline-flex items-center justify-center rounded-[10px] bg-components-segmented-control-bg-normal p-0.5')}> <div className={cn(className, 'relative inline-flex items-center justify-center rounded-[10px] bg-components-segmented-control-bg-normal p-0.5')}>
@@ -69,13 +69,13 @@ const TabSlider: FC<TabSliderProps> = ({
{option.text} {option.text}
{/* if no plugin installed, the badge won't show */} {/* if no plugin installed, the badge won't show */}
{option.value === 'plugins' {option.value === 'plugins'
&& (pluginList?.plugins.length ?? 0) > 0 && (pluginList?.total ?? 0) > 0
&& <Badge && <Badge
size='s' size='s'
uppercase={true} uppercase={true}
state={BadgeState.Default} state={BadgeState.Default}
> >
{pluginList?.plugins.length} {pluginList?.total}
</Badge> </Badge>
} }
</div> </div>

View File

@@ -24,6 +24,7 @@ import {
} from '@/service/common' } from '@/service/common'
import { useAppContext } from '@/context/app-context' import { useAppContext } from '@/context/app-context'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import { useGlobalPublicStore } from '@/context/global-public-context'
const ALLOW_FILE_EXTENSIONS = ['svg', 'png'] const ALLOW_FILE_EXTENSIONS = ['svg', 'png']
@@ -39,6 +40,7 @@ const CustomWebAppBrand = () => {
const [fileId, setFileId] = useState('') const [fileId, setFileId] = useState('')
const [imgKey, setImgKey] = useState(Date.now()) const [imgKey, setImgKey] = useState(Date.now())
const [uploadProgress, setUploadProgress] = useState(0) const [uploadProgress, setUploadProgress] = useState(0)
const systemFeatures = useGlobalPublicStore(s => s.systemFeatures)
const isSandbox = enableBilling && plan.type === Plan.sandbox const isSandbox = enableBilling && plan.type === Plan.sandbox
const uploading = uploadProgress > 0 && uploadProgress < 100 const uploading = uploadProgress > 0 && uploadProgress < 100
const webappLogo = currentWorkspace.custom_config?.replace_webapp_logo || '' const webappLogo = currentWorkspace.custom_config?.replace_webapp_logo || ''
@@ -244,9 +246,12 @@ const CustomWebAppBrand = () => {
{!webappBrandRemoved && ( {!webappBrandRemoved && (
<> <>
<div className='system-2xs-medium-uppercase text-text-tertiary'>POWERED BY</div> <div className='system-2xs-medium-uppercase text-text-tertiary'>POWERED BY</div>
{webappLogo {
? <img src={`${webappLogo}?hash=${imgKey}`} alt='logo' className='block h-5 w-auto' /> systemFeatures.branding.enabled && systemFeatures.branding.workspace_logo
: <DifyLogo size='small' /> ? <img src={systemFeatures.branding.workspace_logo} alt='logo' className='block h-5 w-auto' />
: webappLogo
? <img src={`${webappLogo}?hash=${imgKey}`} alt='logo' className='block h-5 w-auto' />
: <DifyLogo size='small' />
} }
</> </>
)} )}
@@ -303,9 +308,12 @@ const CustomWebAppBrand = () => {
{!webappBrandRemoved && ( {!webappBrandRemoved && (
<> <>
<div className='system-2xs-medium-uppercase text-text-tertiary'>POWERED BY</div> <div className='system-2xs-medium-uppercase text-text-tertiary'>POWERED BY</div>
{webappLogo {
? <img src={`${webappLogo}?hash=${imgKey}`} alt='logo' className='block h-5 w-auto' /> systemFeatures.branding.enabled && systemFeatures.branding.workspace_logo
: <DifyLogo size='small' /> ? <img src={systemFeatures.branding.workspace_logo} alt='logo' className='block h-5 w-auto' />
: webappLogo
? <img src={`${webappLogo}?hash=${imgKey}`} alt='logo' className='block h-5 w-auto' />
: <DifyLogo size='small' />
} }
</> </>
)} )}

View File

@@ -9,6 +9,7 @@ import type { LangGeniusVersionResponse } from '@/models/common'
import { IS_CE_EDITION } from '@/config' import { IS_CE_EDITION } from '@/config'
import DifyLogo from '@/app/components/base/logo/dify-logo' import DifyLogo from '@/app/components/base/logo/dify-logo'
import { noop } from 'lodash-es' import { noop } from 'lodash-es'
import { useGlobalPublicStore } from '@/context/global-public-context'
type IAccountSettingProps = { type IAccountSettingProps = {
langeniusVersionInfo: LangGeniusVersionResponse langeniusVersionInfo: LangGeniusVersionResponse
@@ -21,6 +22,7 @@ export default function AccountAbout({
}: IAccountSettingProps) { }: IAccountSettingProps) {
const { t } = useTranslation() const { t } = useTranslation()
const isLatest = langeniusVersionInfo.current_version === langeniusVersionInfo.latest_version const isLatest = langeniusVersionInfo.current_version === langeniusVersionInfo.latest_version
const systemFeatures = useGlobalPublicStore(s => s.systemFeatures)
return ( return (
<Modal <Modal
@@ -33,7 +35,14 @@ export default function AccountAbout({
<RiCloseLine className='h-4 w-4 text-text-tertiary' /> <RiCloseLine className='h-4 w-4 text-text-tertiary' />
</div> </div>
<div className='flex flex-col items-center gap-4 py-8'> <div className='flex flex-col items-center gap-4 py-8'>
<DifyLogo size='large' className='mx-auto' /> {systemFeatures.branding.enabled && systemFeatures.branding.workspace_logo
? <img
src={systemFeatures.branding.workspace_logo}
className='block h-7 w-auto object-contain'
alt='logo'
/>
: <DifyLogo size='large' className='mx-auto' />}
<div className='text-center text-xs font-normal text-text-tertiary'>Version {langeniusVersionInfo?.current_version}</div> <div className='text-center text-xs font-normal text-text-tertiary'>Version {langeniusVersionInfo?.current_version}</div>
<div className='flex flex-col items-center gap-2 text-center text-xs font-normal text-text-secondary'> <div className='flex flex-col items-center gap-2 text-center text-xs font-normal text-text-secondary'>
<div>© {dayjs().year()} LangGenius, Inc., Contributors.</div> <div>© {dayjs().year()} LangGenius, Inc., Contributors.</div>

View File

@@ -21,6 +21,7 @@ import { useModalContext } from '@/context/modal-context'
import PlanBadge from './plan-badge' import PlanBadge from './plan-badge'
import LicenseNav from './license-env' import LicenseNav from './license-env'
import { Plan } from '../billing/type' import { Plan } from '../billing/type'
import { useGlobalPublicStore } from '@/context/global-public-context'
const navClassName = ` const navClassName = `
flex items-center relative mr-0 sm:mr-3 px-3 h-8 rounded-xl flex items-center relative mr-0 sm:mr-3 px-3 h-8 rounded-xl
@@ -36,6 +37,7 @@ const Header = () => {
const [isShowNavMenu, { toggle, setFalse: hideNavMenu }] = useBoolean(false) const [isShowNavMenu, { toggle, setFalse: hideNavMenu }] = useBoolean(false)
const { enableBilling, plan } = useProviderContext() const { enableBilling, plan } = useProviderContext()
const { setShowPricingModal, setShowAccountSettingModal } = useModalContext() const { setShowPricingModal, setShowAccountSettingModal } = useModalContext()
const systemFeatures = useGlobalPublicStore(s => s.systemFeatures)
const isFreePlan = plan.type === Plan.sandbox const isFreePlan = plan.type === Plan.sandbox
const handlePlanClick = useCallback(() => { const handlePlanClick = useCallback(() => {
if (isFreePlan) if (isFreePlan)
@@ -61,7 +63,13 @@ const Header = () => {
!isMobile !isMobile
&& <div className='flex shrink-0 items-center gap-1.5 self-stretch pl-3'> && <div className='flex shrink-0 items-center gap-1.5 self-stretch pl-3'>
<Link href="/apps" className='flex h-8 shrink-0 items-center justify-center gap-2 px-0.5'> <Link href="/apps" className='flex h-8 shrink-0 items-center justify-center gap-2 px-0.5'>
<DifyLogo /> {systemFeatures.branding.enabled && systemFeatures.branding.workspace_logo
? <img
src={systemFeatures.branding.workspace_logo}
className='block h-[22px] w-auto object-contain'
alt='logo'
/>
: <DifyLogo />}
</Link> </Link>
<div className='font-light text-divider-deep'>/</div> <div className='font-light text-divider-deep'>/</div>
<div className='flex items-center gap-0.5'> <div className='flex items-center gap-0.5'>
@@ -76,7 +84,13 @@ const Header = () => {
{isMobile && ( {isMobile && (
<div className='flex'> <div className='flex'>
<Link href="/apps" className='mr-4 flex items-center'> <Link href="/apps" className='mr-4 flex items-center'>
<DifyLogo /> {systemFeatures.branding.enabled && systemFeatures.branding.workspace_logo
? <img
src={systemFeatures.branding.workspace_logo}
className='block h-[22px] w-auto object-contain'
alt='logo'
/>
: <DifyLogo />}
</Link> </Link>
<div className='font-light text-divider-deep'>/</div> <div className='font-light text-divider-deep'>/</div>
{enableBilling ? <PlanBadge allowHover sandboxAsUpgrade plan={plan.type} onClick={handlePlanClick} /> : <LicenseNav />} {enableBilling ? <PlanBadge allowHover sandboxAsUpgrade plan={plan.type} onClick={handlePlanClick} /> : <LicenseNav />}

View File

@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next'
import type { FilterState } from './filter-management' import type { FilterState } from './filter-management'
import FilterManagement from './filter-management' import FilterManagement from './filter-management'
import List from './list' import List from './list'
import { useInstalledLatestVersion, useInstalledPluginListWithPagination, useInvalidateInstalledPluginList } from '@/service/use-plugins' import { useInstalledLatestVersion, useInstalledPluginList, useInvalidateInstalledPluginList } from '@/service/use-plugins'
import PluginDetailPanel from '@/app/components/plugins/plugin-detail-panel' import PluginDetailPanel from '@/app/components/plugins/plugin-detail-panel'
import { usePluginPageContext } from './context' import { usePluginPageContext } from './context'
import { useDebounceFn } from 'ahooks' import { useDebounceFn } from 'ahooks'
@@ -17,7 +17,7 @@ const PluginsPanel = () => {
const { t } = useTranslation() const { t } = useTranslation()
const filters = usePluginPageContext(v => v.filters) as FilterState const filters = usePluginPageContext(v => v.filters) as FilterState
const setFilters = usePluginPageContext(v => v.setFilters) const setFilters = usePluginPageContext(v => v.setFilters)
const { data: pluginList, isLoading: isPluginListLoading, isFetching, isLastPage, loadNextPage } = useInstalledPluginListWithPagination() const { data: pluginList, isLoading: isPluginListLoading, isFetching, isLastPage, loadNextPage } = useInstalledPluginList()
const { data: installedLatestVersion } = useInstalledLatestVersion( const { data: installedLatestVersion } = useInstalledLatestVersion(
pluginList?.plugins pluginList?.plugins
.filter(plugin => plugin.source === PluginSource.marketplace) .filter(plugin => plugin.source === PluginSource.marketplace)

View File

@@ -641,11 +641,13 @@ const TextGeneration: FC<IMainProps> = ({
!isPC && resultExisted && 'rounded-b-2xl border-b-[0.5px] border-divider-regular', !isPC && resultExisted && 'rounded-b-2xl border-b-[0.5px] border-divider-regular',
)}> )}>
<div className='system-2xs-medium-uppercase text-text-tertiary'>{t('share.chat.poweredBy')}</div> <div className='system-2xs-medium-uppercase text-text-tertiary'>{t('share.chat.poweredBy')}</div>
{systemFeatures.branding.enabled ? ( {
<img src={systemFeatures.branding.login_page_logo} alt='logo' className='block h-5 w-auto' /> systemFeatures.branding.enabled && systemFeatures.branding.workspace_logo
) : ( ? <img src={systemFeatures.branding.workspace_logo} alt='logo' className='block h-5 w-auto' />
<DifyLogo size='small' /> : customConfig?.replace_webapp_logo
)} ? <img src={`${customConfig?.replace_webapp_logo}`} alt='logo' className='block h-5 w-auto' />
: <DifyLogo size='small' />
}
</div> </div>
)} )}
</div> </div>

View File

@@ -7,6 +7,7 @@ import { languages } from '@/i18n/language'
import type { Locale } from '@/i18n' import type { Locale } from '@/i18n'
import I18n from '@/context/i18n' import I18n from '@/context/i18n'
import dynamic from 'next/dynamic' import dynamic from 'next/dynamic'
import { useGlobalPublicStore } from '@/context/global-public-context'
// Avoid rendering the logo and theme selector on the server // Avoid rendering the logo and theme selector on the server
const DifyLogo = dynamic(() => import('@/app/components/base/logo/dify-logo'), { const DifyLogo = dynamic(() => import('@/app/components/base/logo/dify-logo'), {
@@ -20,10 +21,17 @@ const ThemeSelector = dynamic(() => import('@/app/components/base/theme-selector
const Header = () => { const Header = () => {
const { locale, setLocaleOnClient } = useContext(I18n) const { locale, setLocaleOnClient } = useContext(I18n)
const systemFeatures = useGlobalPublicStore(s => s.systemFeatures)
return ( return (
<div className='flex w-full items-center justify-between p-6'> <div className='flex w-full items-center justify-between p-6'>
<DifyLogo size='large' /> {systemFeatures.branding.enabled && systemFeatures.branding.login_page_logo
? <img
src={systemFeatures.branding.login_page_logo}
className='block h-7 w-auto object-contain'
alt='logo'
/>
: <DifyLogo size='large' />}
<div className='flex items-center gap-1'> <div className='flex items-center gap-1'>
<Select <Select
value={locale} value={locale}

View File

@@ -10,7 +10,6 @@ import type {
GitHubItemAndMarketPlaceDependency, GitHubItemAndMarketPlaceDependency,
InstallPackageResponse, InstallPackageResponse,
InstalledLatestVersionResponse, InstalledLatestVersionResponse,
InstalledPluginListResponse,
InstalledPluginListWithTotalResponse, InstalledPluginListWithTotalResponse,
PackageDependency, PackageDependency,
Permissions, Permissions,
@@ -67,16 +66,7 @@ export const useCheckInstalled = ({
}) })
} }
export const useInstalledPluginList = (disable?: boolean) => { export const useInstalledPluginList = (disable?: boolean, pageSize = 100) => {
return useQuery<InstalledPluginListResponse>({
queryKey: useInstalledPluginListKey,
queryFn: () => get<InstalledPluginListResponse>('/workspaces/current/plugin/list'),
enabled: !disable,
initialData: !disable ? undefined : { plugins: [] },
})
}
export const useInstalledPluginListWithPagination = (pageSize = 100) => {
const fetchPlugins = async ({ pageParam = 1 }) => { const fetchPlugins = async ({ pageParam = 1 }) => {
const response = await get<InstalledPluginListWithTotalResponse>( const response = await get<InstalledPluginListWithTotalResponse>(
`/workspaces/current/plugin/list?page=${pageParam}&page_size=${pageSize}`, `/workspaces/current/plugin/list?page=${pageParam}&page_size=${pageSize}`,
@@ -91,8 +81,10 @@ export const useInstalledPluginListWithPagination = (pageSize = 100) => {
hasNextPage, hasNextPage,
isFetchingNextPage, isFetchingNextPage,
isLoading, isLoading,
isSuccess,
} = useInfiniteQuery({ } = useInfiniteQuery({
queryKey: ['installed-plugins', pageSize], enabled: !disable,
queryKey: useInstalledPluginListKey,
queryFn: fetchPlugins, queryFn: fetchPlugins,
getNextPageParam: (lastPage, pages) => { getNextPageParam: (lastPage, pages) => {
const totalItems = lastPage.total const totalItems = lastPage.total
@@ -108,10 +100,12 @@ export const useInstalledPluginListWithPagination = (pageSize = 100) => {
}) })
const plugins = data?.pages.flatMap(page => page.plugins) ?? [] const plugins = data?.pages.flatMap(page => page.plugins) ?? []
const total = data?.pages[0].total ?? 0
return { return {
data: { data: disable ? undefined : {
plugins, plugins,
total,
}, },
isLastPage: !hasNextPage, isLastPage: !hasNextPage,
loadNextPage: () => { loadNextPage: () => {
@@ -120,6 +114,7 @@ export const useInstalledPluginListWithPagination = (pageSize = 100) => {
isLoading, isLoading,
isFetching: isFetchingNextPage, isFetching: isFetchingNextPage,
error, error,
isSuccess,
} }
} }