From 902de72cc080628eb768426bf359f9bde0e6c3d0 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Thu, 10 Oct 2024 12:58:28 +0800 Subject: [PATCH 1/7] new style of settings --- .../header/account-dropdown/index.tsx | 2 +- .../header/account-setting/index.tsx | 61 ++++++++++--------- .../header/account-setting/menu-dialog.tsx | 46 ++++++++++++++ web/i18n/en-US/common.ts | 1 + web/i18n/zh-Hans/common.ts | 1 + 5 files changed, 81 insertions(+), 30 deletions(-) create mode 100644 web/app/components/header/account-setting/menu-dialog.tsx diff --git a/web/app/components/header/account-dropdown/index.tsx b/web/app/components/header/account-dropdown/index.tsx index 4c42374ffd..c29e0f159b 100644 --- a/web/app/components/header/account-dropdown/index.tsx +++ b/web/app/components/header/account-dropdown/index.tsx @@ -102,7 +102,7 @@ export default function AppSelector({ isMobile }: IAppSelector) {
-
setShowAccountSettingModal({ payload: 'account' })}> +
setShowAccountSettingModal({ payload: 'provider' })}>
{t('common.userProfile.settings')}
diff --git a/web/app/components/header/account-setting/index.tsx b/web/app/components/header/account-setting/index.tsx index c8f757de28..d56f231a55 100644 --- a/web/app/components/header/account-setting/index.tsx +++ b/web/app/components/header/account-setting/index.tsx @@ -6,8 +6,8 @@ import { RiAccountCircleLine, RiApps2AddFill, RiApps2AddLine, - RiBox3Fill, - RiBox3Line, + RiBrainFill, + RiBrainLine, RiCloseLine, RiColorFilterFill, RiColorFilterLine, @@ -31,17 +31,14 @@ import ModelProviderPage from './model-provider-page' import cn from '@/utils/classnames' import BillingPage from '@/app/components/billing/billing-page' import CustomPage from '@/app/components/custom/custom-page' -import Modal from '@/app/components/base/modal' import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' import { useProviderContext } from '@/context/provider-context' import { useAppContext } from '@/context/app-context' +import MenuDialog from '@/app/components/header/account-setting/menu-dialog' +import Input from '@/app/components/base/input' const iconClassName = ` - w-4 h-4 ml-3 mr-2 -` - -const scrolledClassName = ` - border-b shadow-xs bg-white/[.98] + w-5 h-5 mr-2 ` type IAccountSettingProps = { @@ -59,7 +56,7 @@ type GroupItem = { export default function AccountSetting({ onCancel, - activeTab = 'account', + activeTab = 'provider', }: IAccountSettingProps) { const [activeMenu, setActiveMenu] = useState(activeTab) const { t } = useTranslation() @@ -73,8 +70,8 @@ export default function AccountSetting({ { key: 'provider', name: t('common.settings.provider'), - icon: , - activeIcon: , + icon: , + activeIcon: , }, { key: 'members', @@ -122,7 +119,7 @@ export default function AccountSetting({ }, { key: 'account-group', - name: t('common.settings.accountGroup'), + name: t('common.settings.generalGroup'), items: [ { key: 'account', @@ -161,32 +158,31 @@ export default function AccountSetting({ const activeItem = [...menuItems[0].items, ...menuItems[1].items].find(item => item.key === activeMenu) + const [searchValue, setSearchValue] = useState('') + return ( - { }} - className='my-[60px] p-0 max-w-[1024px] rounded-xl overflow-y-auto' - wrapperClassName='pt-[60px]' > -
-
-
{t('common.userProfile.settings')}
+
+
+
{t('common.userProfile.settings')}
{ menuItems.map(menuItem => ( -
+
{!isCurrentWorkspaceDatasetOperator && ( -
{menuItem.name}
+
{menuItem.name}
)}
{ menuItem.items.map(item => (
setActiveMenu(item.key)} > @@ -201,15 +197,22 @@ export default function AccountSetting({ }
-
-
-
{activeItem?.name}
+
+
+
{activeItem?.name}
{ activeItem?.description && (
{activeItem?.description}
) }
+ setSearchValue(e.target.value)} + value={searchValue} + />
@@ -228,6 +231,6 @@ export default function AccountSetting({
- + ) } diff --git a/web/app/components/header/account-setting/menu-dialog.tsx b/web/app/components/header/account-setting/menu-dialog.tsx new file mode 100644 index 0000000000..2f13311d0d --- /dev/null +++ b/web/app/components/header/account-setting/menu-dialog.tsx @@ -0,0 +1,46 @@ +import { Fragment, useCallback } from 'react' +import type { ReactNode } from 'react' +import { Dialog, Transition } from '@headlessui/react' +import cn from '@/utils/classnames' + +type DialogProps = { + className?: string + children: ReactNode + show: boolean + onClose?: () => void +} + +const MenuDialog = ({ + className, + children, + show, + onClose, +}: DialogProps) => { + const close = useCallback(() => onClose?.(), [onClose]) + return ( + + +
+
+ + +
+ {children} + + +
+
+
+
+ ) +} + +export default MenuDialog diff --git a/web/i18n/en-US/common.ts b/web/i18n/en-US/common.ts index 23e301485a..483c4788e6 100644 --- a/web/i18n/en-US/common.ts +++ b/web/i18n/en-US/common.ts @@ -142,6 +142,7 @@ const translation = { settings: { accountGroup: 'ACCOUNT', workplaceGroup: 'WORKSPACE', + generalGroup: 'GENERAL', account: 'My account', members: 'Members', billing: 'Billing', diff --git a/web/i18n/zh-Hans/common.ts b/web/i18n/zh-Hans/common.ts index 7947d32f25..7d906ed0b4 100644 --- a/web/i18n/zh-Hans/common.ts +++ b/web/i18n/zh-Hans/common.ts @@ -142,6 +142,7 @@ const translation = { settings: { accountGroup: '账户', workplaceGroup: '工作空间', + generalGroup: '通用', account: '我的账户', members: '成员', billing: '账单', From 49856d8d174672172752d17dfbbe36762e2b3b96 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Thu, 10 Oct 2024 16:01:07 +0800 Subject: [PATCH 2/7] setting content header & close button --- .../header/account-setting/index.tsx | 6 +--- .../header/account-setting/menu-dialog.tsx | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/web/app/components/header/account-setting/index.tsx b/web/app/components/header/account-setting/index.tsx index d56f231a55..02895b0255 100644 --- a/web/app/components/header/account-setting/index.tsx +++ b/web/app/components/header/account-setting/index.tsx @@ -8,7 +8,6 @@ import { RiApps2AddLine, RiBrainFill, RiBrainLine, - RiCloseLine, RiColorFilterFill, RiColorFilterLine, RiDatabase2Fill, @@ -163,7 +162,7 @@ export default function AccountSetting({ return ( { }} + onClose={onCancel} >
@@ -213,9 +212,6 @@ export default function AccountSetting({ onChange={e => setSearchValue(e.target.value)} value={searchValue} /> -
- -
diff --git a/web/app/components/header/account-setting/menu-dialog.tsx b/web/app/components/header/account-setting/menu-dialog.tsx index 2f13311d0d..19639488da 100644 --- a/web/app/components/header/account-setting/menu-dialog.tsx +++ b/web/app/components/header/account-setting/menu-dialog.tsx @@ -1,6 +1,8 @@ -import { Fragment, useCallback } from 'react' +import { Fragment, useCallback, useEffect } from 'react' import type { ReactNode } from 'react' +import { RiCloseLine } from '@remixicon/react' import { Dialog, Transition } from '@headlessui/react' +import Button from '@/app/components/base/button' import cn from '@/utils/classnames' type DialogProps = { @@ -17,9 +19,22 @@ const MenuDialog = ({ onClose, }: DialogProps) => { const close = useCallback(() => onClose?.(), [onClose]) + + useEffect(() => { + const handleKeyDown = (event: KeyboardEvent) => { + if (event.key === 'Escape') + close() + } + + document.addEventListener('keydown', handleKeyDown) + return () => { + document.removeEventListener('keydown', handleKeyDown) + } + }, [close]) + return ( - + {}}>
+
+ +
ESC
+
{children} From d68ca56b3aaafbb4b126783f5839d66f6ed956ee Mon Sep 17 00:00:00 2001 From: JzoNg Date: Fri, 11 Oct 2024 12:26:53 +0800 Subject: [PATCH 3/7] system default model --- .../header/account-setting/index.tsx | 2 +- .../model-provider-page/index.tsx | 43 +++++++++++-------- .../system-model-selector/index.tsx | 17 ++++---- web/i18n/en-US/common.ts | 2 +- web/i18n/zh-Hans/common.ts | 2 +- 5 files changed, 36 insertions(+), 30 deletions(-) diff --git a/web/app/components/header/account-setting/index.tsx b/web/app/components/header/account-setting/index.tsx index 02895b0255..33b4a0f68a 100644 --- a/web/app/components/header/account-setting/index.tsx +++ b/web/app/components/header/account-setting/index.tsx @@ -197,7 +197,7 @@ export default function AccountSetting({
-
+
{activeItem?.name}
{ activeItem?.description && ( diff --git a/web/app/components/header/account-setting/model-provider-page/index.tsx b/web/app/components/header/account-setting/model-provider-page/index.tsx index a8a5a0cf42..8862b0029b 100644 --- a/web/app/components/header/account-setting/model-provider-page/index.tsx +++ b/web/app/components/header/account-setting/model-provider-page/index.tsx @@ -1,5 +1,6 @@ import { useMemo } from 'react' import { useTranslation } from 'react-i18next' +import { RiAlertFill } from '@remixicon/react' import SystemModelSelector from './system-model-selector' import ProviderAddedCard, { UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST } from './provider-added-card' import ProviderCard from './provider-card' @@ -17,10 +18,10 @@ import { useUpdateModelList, useUpdateModelProviders, } from './hooks' -import { AlertTriangle } from '@/app/components/base/icons/src/vender/solid/alertsAndFeedback' import { useProviderContext } from '@/context/provider-context' import { useModalContextSelector } from '@/context/modal-context' import { useEventEmitterContextContext } from '@/context/event-emitter' +import cn from '@/utils/classnames' const ModelProviderPage = () => { const { t } = useTranslation() @@ -90,24 +91,28 @@ const ModelProviderPage = () => { return (
-
- { - defaultModelNotConfigured - ? ( -
- - {t('common.modelProvider.notConfigured')} -
- ) - :
{t('common.modelProvider.models')}
- } - +
+
{t('common.modelProvider.models')}
+
+ {defaultModelNotConfigured &&
} + {defaultModelNotConfigured && ( +
+ + {t('common.modelProvider.notConfigured')} +
+ )} + +
{ !!configuredProviders?.length && ( diff --git a/web/app/components/header/account-setting/model-provider-page/system-model-selector/index.tsx b/web/app/components/header/account-setting/model-provider-page/system-model-selector/index.tsx index 1574785898..846738d4ae 100644 --- a/web/app/components/header/account-setting/model-provider-page/system-model-selector/index.tsx +++ b/web/app/components/header/account-setting/model-provider-page/system-model-selector/index.tsx @@ -1,6 +1,7 @@ import type { FC } from 'react' import { useState } from 'react' import { useTranslation } from 'react-i18next' +import { RiEqualizer2Line } from '@remixicon/react' import ModelSelector from '../model-selector' import { useModelList, @@ -13,7 +14,6 @@ import type { } from '../declarations' import { ModelTypeEnum } from '../declarations' import Tooltip from '@/app/components/base/tooltip' -import { Settings01 } from '@/app/components/base/icons/src/vender/line/general' import { PortalToFollowElem, PortalToFollowElemContent, @@ -31,6 +31,7 @@ type SystemModelSelectorProps = { rerankDefaultModel: DefaultModelResponse | undefined speech2textDefaultModel: DefaultModelResponse | undefined ttsDefaultModel: DefaultModelResponse | undefined + notConfigured: boolean } const SystemModel: FC = ({ textGenerationDefaultModel, @@ -38,6 +39,7 @@ const SystemModel: FC = ({ rerankDefaultModel, speech2textDefaultModel, ttsDefaultModel, + notConfigured, }) => { const { t } = useTranslation() const { notify } = useToastContext() @@ -128,14 +130,13 @@ const SystemModel: FC = ({ }} > setOpen(v => !v)}> -
- +
+
diff --git a/web/i18n/en-US/common.ts b/web/i18n/en-US/common.ts index 483c4788e6..3bdeb7cec9 100644 --- a/web/i18n/en-US/common.ts +++ b/web/i18n/en-US/common.ts @@ -276,7 +276,7 @@ const translation = { }, }, modelProvider: { - notConfigured: 'The system model has not yet been fully configured, and some functions may be unavailable.', + notConfigured: 'The system model has not yet been fully configured', systemModelSettings: 'System Model Settings', systemModelSettingsLink: 'Why is it necessary to set up a system model?', selectModel: 'Select your model', diff --git a/web/i18n/zh-Hans/common.ts b/web/i18n/zh-Hans/common.ts index 7d906ed0b4..f80afe8fca 100644 --- a/web/i18n/zh-Hans/common.ts +++ b/web/i18n/zh-Hans/common.ts @@ -276,7 +276,7 @@ const translation = { }, }, modelProvider: { - notConfigured: '系统模型尚未完全配置,部分功能可能无法使用。', + notConfigured: '系统模型尚未完全配置', systemModelSettings: '系统模型设置', systemModelSettingsLink: '为什么需要设置系统模型?', selectModel: '选择您的模型', From d1452d4af4ec2d41e90f7f3db68ae81bfdc4e280 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Fri, 11 Oct 2024 13:04:57 +0800 Subject: [PATCH 4/7] no provider installed --- .../model-provider-page/index.tsx | 48 +++++++++++-------- web/i18n/en-US/common.ts | 6 +++ web/i18n/zh-Hans/common.ts | 6 +++ 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/web/app/components/header/account-setting/model-provider-page/index.tsx b/web/app/components/header/account-setting/model-provider-page/index.tsx index 8862b0029b..744e8b8daa 100644 --- a/web/app/components/header/account-setting/model-provider-page/index.tsx +++ b/web/app/components/header/account-setting/model-provider-page/index.tsx @@ -1,6 +1,6 @@ import { useMemo } from 'react' import { useTranslation } from 'react-i18next' -import { RiAlertFill } from '@remixicon/react' +import { RiAlertFill, RiBrainLine } from '@remixicon/react' import SystemModelSelector from './system-model-selector' import ProviderAddedCard, { UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST } from './provider-added-card' import ProviderCard from './provider-card' @@ -58,25 +58,25 @@ const ModelProviderPage = () => { const handleOpenModal = ( provider: ModelProvider, - configurateMethod: ConfigurationMethodEnum, + configurationMethod: ConfigurationMethodEnum, CustomConfigurationModelFixedFields?: CustomConfigurationModelFixedFields, ) => { setShowModelModal({ payload: { currentProvider: provider, - currentConfigurationMethod: configurateMethod, + currentConfigurationMethod: configurationMethod, currentCustomConfigurationModelFixedFields: CustomConfigurationModelFixedFields, }, onSaveCallback: () => { updateModelProviders() - if (configurateMethod === ConfigurationMethodEnum.predefinedModel) { + if (configurationMethod === ConfigurationMethodEnum.predefinedModel) { provider.supported_model_types.forEach((type) => { updateModelList(type) }) } - if (configurateMethod === ConfigurationMethodEnum.customizableModel && provider.custom_configuration.status === CustomConfigurationStatusEnum.active) { + if (configurationMethod === ConfigurationMethodEnum.customizableModel && provider.custom_configuration.status === CustomConfigurationStatusEnum.active) { eventEmitter?.emit({ type: UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST, payload: provider.provider, @@ -114,21 +114,29 @@ const ModelProviderPage = () => { />
- { - !!configuredProviders?.length && ( -
- { - configuredProviders?.map(provider => ( - handleOpenModal(provider, configurateMethod, currentCustomConfigurationModelFixedFields)} - /> - )) - } + {!configuredProviders?.length && ( +
+
+
- ) - } +
{t('common.modelProvider.emptyProviderTitle')}
+
{t('common.modelProvider.emptyProviderTip')}
+
+ )} + {!!configuredProviders?.length && ( +
+ {configuredProviders?.map(provider => ( + handleOpenModal(provider, configurationMethod, currentCustomConfigurationModelFixedFields)} + /> + ))} +
+ )} +
{t('common.modelProvider.configureRequired')}
+
{t('common.modelProvider.installProvider')}
+
{t('common.modelProvider.discoverMore')}
{ !!notConfiguredProviders?.length && ( <> @@ -142,7 +150,7 @@ const ModelProviderPage = () => { handleOpenModal(provider, configurateMethod)} + onOpenModal={(configurationMethod: ConfigurationMethodEnum) => handleOpenModal(provider, configurationMethod)} /> )) } diff --git a/web/i18n/en-US/common.ts b/web/i18n/en-US/common.ts index 3bdeb7cec9..11db6f7359 100644 --- a/web/i18n/en-US/common.ts +++ b/web/i18n/en-US/common.ts @@ -374,6 +374,12 @@ const translation = { loadBalancingLeastKeyWarning: 'To enable load balancing at least 2 keys must be enabled.', loadBalancingInfo: 'By default, load balancing uses the Round-robin strategy. If rate limiting is triggered, a 1-minute cooldown period will be applied.', upgradeForLoadBalancing: 'Upgrade your plan to enable Load Balancing.', + configureRequired: 'Configure required', + configureTip: 'Set up api-key or add model to use', + installProvider: 'Install model providers', + discoverMore: 'Discover more in', + emptyProviderTitle: 'Model provider not set up', + emptyProviderTip: 'Please install a model provider first.', }, dataSource: { add: 'Add a data source', diff --git a/web/i18n/zh-Hans/common.ts b/web/i18n/zh-Hans/common.ts index f80afe8fca..17edc3a958 100644 --- a/web/i18n/zh-Hans/common.ts +++ b/web/i18n/zh-Hans/common.ts @@ -374,6 +374,12 @@ const translation = { loadBalancingInfo: '默认情况下,负载平衡使用 Round-robin 策略。如果触发速率限制,将应用 1 分钟的冷却时间', upgradeForLoadBalancing: '升级以解锁负载均衡功能', apiKey: 'API 密钥', + configureRequired: '尚未配置', + configureTip: '请配置 API 密钥,添加模型。', + installProvider: '安装模型供应商', + discoverMore: '发现更多就在', + emptyProviderTitle: '尚未安装模型供应商', + emptyProviderTip: '请安装模型供应商。', }, dataSource: { add: '添加数据源', From 4cc6dfa2329d4babf38e4f3d8091d556d304068b Mon Sep 17 00:00:00 2001 From: JzoNg Date: Fri, 11 Oct 2024 13:55:09 +0800 Subject: [PATCH 5/7] new style of provider card --- .../header/account-setting/model-provider-page/index.tsx | 2 +- .../provider-added-card/credential-panel.tsx | 6 +++--- .../model-provider-page/provider-added-card/index.tsx | 9 +++++---- .../provider-added-card/model-list.tsx | 9 ++++++--- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/web/app/components/header/account-setting/model-provider-page/index.tsx b/web/app/components/header/account-setting/model-provider-page/index.tsx index 744e8b8daa..84916fb05a 100644 --- a/web/app/components/header/account-setting/model-provider-page/index.tsx +++ b/web/app/components/header/account-setting/model-provider-page/index.tsx @@ -124,7 +124,7 @@ const ModelProviderPage = () => {
)} {!!configuredProviders?.length && ( -
+
{configuredProviders?.map(provider => ( = ({
API-KEY - +
{ diff --git a/web/app/components/header/account-setting/model-provider-page/provider-added-card/index.tsx b/web/app/components/header/account-setting/model-provider-page/provider-added-card/index.tsx index 5e73b36c42..9cb3899235 100644 --- a/web/app/components/header/account-setting/model-provider-page/provider-added-card/index.tsx +++ b/web/app/components/header/account-setting/model-provider-page/provider-added-card/index.tsx @@ -2,6 +2,7 @@ import type { FC } from 'react' import { useState } from 'react' import { useTranslation } from 'react-i18next' import { + RiArrowRightSLine, RiLoader2Line, } from '@remixicon/react' import type { @@ -21,7 +22,6 @@ import CredentialPanel from './credential-panel' import QuotaPanel from './quota-panel' import ModelList from './model-list' import AddModelButton from './add-model-button' -import { ChevronDownDouble } from '@/app/components/base/icons/src/vender/line/arrows' import { fetchModelProviderModelList } from '@/service/common' import { useEventEmitterContextContext } from '@/context/event-emitter' import { IS_CE_EDITION } from '@/config' @@ -116,23 +116,24 @@ const ProviderAddedCard: FC = ({ { collapsed && (
-
+
{ hasModelList ? t('common.modelProvider.modelsNum', { num: modelList.length }) : t('common.modelProvider.showModels') } + {!loading && }
- { hasModelList ? t('common.modelProvider.showModelsNum', { num: modelList.length }) : t('common.modelProvider.showModels') } + {!loading && } { loading && ( @@ -143,7 +144,7 @@ const ProviderAddedCard: FC = ({ configurationMethods.includes(ConfigurationMethodEnum.customizableModel) && isCurrentWorkspaceManager && ( onOpenModal(ConfigurationMethodEnum.customizableModel)} - className='hidden group-hover:flex group-hover:text-primary-600' + className='flex' /> ) } diff --git a/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-list.tsx b/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-list.tsx index e321d4076d..709560b419 100644 --- a/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-list.tsx +++ b/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-list.tsx @@ -1,6 +1,9 @@ import type { FC } from 'react' import { useCallback } from 'react' import { useTranslation } from 'react-i18next' +import { + RiArrowRightSLine, +} from '@remixicon/react' import type { CustomConfigurationModelFixedFields, ModelItem, @@ -12,7 +15,6 @@ import { // import Tab from './tab' import AddModelButton from './add-model-button' import ModelListItem from './model-list-item' -import { ChevronDownDouble } from '@/app/components/base/icons/src/vender/line/arrows' import { useModalContextSelector } from '@/context/modal-context' import { useAppContext } from '@/context/app-context' @@ -53,13 +55,14 @@ const ModelList: FC = ({ {t('common.modelProvider.modelsNum', { num: models.length })} + onCollapse()} > - - {t('common.modelProvider.collapse')} + {t('common.modelProvider.modelsNum', { num: models.length })} + {/* { From 495dec143c6314af0a0e0d87a52bdf0b55cd77c5 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Fri, 11 Oct 2024 15:14:13 +0800 Subject: [PATCH 6/7] unconfigured provider --- .../model-provider-page/index.tsx | 39 +++++------ .../provider-added-card/index.tsx | 64 +++++++++++-------- .../provider-added-card/model-list.tsx | 2 +- 3 files changed, 56 insertions(+), 49 deletions(-) diff --git a/web/app/components/header/account-setting/model-provider-page/index.tsx b/web/app/components/header/account-setting/model-provider-page/index.tsx index 84916fb05a..8dc6513c05 100644 --- a/web/app/components/header/account-setting/model-provider-page/index.tsx +++ b/web/app/components/header/account-setting/model-provider-page/index.tsx @@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next' import { RiAlertFill, RiBrainLine } from '@remixicon/react' import SystemModelSelector from './system-model-selector' import ProviderAddedCard, { UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST } from './provider-added-card' -import ProviderCard from './provider-card' +// import ProviderCard from './provider-card' import type { CustomConfigurationModelFixedFields, ModelProvider, @@ -134,30 +134,23 @@ const ModelProviderPage = () => { ))}
)} -
{t('common.modelProvider.configureRequired')}
+ {!!notConfiguredProviders?.length && ( + <> +
{t('common.modelProvider.configureRequired')}
+
+ {notConfiguredProviders?.map(provider => ( + handleOpenModal(provider, configurationMethod, currentCustomConfigurationModelFixedFields)} + /> + ))} +
+ + )}
{t('common.modelProvider.installProvider')}
{t('common.modelProvider.discoverMore')}
- { - !!notConfiguredProviders?.length && ( - <> -
- + {t('common.modelProvider.addMoreModelProvider')} - -
-
- { - notConfiguredProviders?.map(provider => ( - handleOpenModal(provider, configurationMethod)} - /> - )) - } -
- - ) - }
) } diff --git a/web/app/components/header/account-setting/model-provider-page/provider-added-card/index.tsx b/web/app/components/header/account-setting/model-provider-page/provider-added-card/index.tsx index 9cb3899235..46ef6add24 100644 --- a/web/app/components/header/account-setting/model-provider-page/provider-added-card/index.tsx +++ b/web/app/components/header/account-setting/model-provider-page/provider-added-card/index.tsx @@ -3,6 +3,7 @@ import { useState } from 'react' import { useTranslation } from 'react-i18next' import { RiArrowRightSLine, + RiInformation2Fill, RiLoader2Line, } from '@remixicon/react' import type { @@ -29,10 +30,12 @@ import { useAppContext } from '@/context/app-context' export const UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST = 'UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST' type ProviderAddedCardProps = { + notConfigured?: boolean provider: ModelProvider onOpenModal: (configurationMethod: ConfigurationMethodEnum, currentCustomConfigurationModelFixedFields?: CustomConfigurationModelFixedFields) => void } const ProviderAddedCard: FC = ({ + notConfigured, provider, onOpenModal, }) => { @@ -47,6 +50,7 @@ const ProviderAddedCard: FC = ({ const hasModelList = fetched && !!modelList.length const { isCurrentWorkspaceManager } = useAppContext() const showQuota = systemConfig.enabled && [...MODEL_PROVIDER_QUOTA_GET_PAID].includes(provider.provider) && !IS_CE_EDITION + const showCredential = configurationMethods.includes(ConfigurationMethodEnum.predefinedModel) && isCurrentWorkspaceManager const getModelList = async (providerName: string) => { if (loading) @@ -105,7 +109,7 @@ const ProviderAddedCard: FC = ({ ) } { - configurationMethods.includes(ConfigurationMethodEnum.predefinedModel) && isCurrentWorkspaceManager && ( + showCredential && ( onOpenModal(ConfigurationMethodEnum.predefinedModel)} provider={provider} @@ -116,30 +120,40 @@ const ProviderAddedCard: FC = ({ { collapsed && (
-
- { - hasModelList - ? t('common.modelProvider.modelsNum', { num: modelList.length }) - : t('common.modelProvider.showModels') - } - {!loading && } -
-
- { - hasModelList - ? t('common.modelProvider.showModelsNum', { num: modelList.length }) - : t('common.modelProvider.showModels') - } - {!loading && } - { - loading && ( - - ) - } -
+ {(showQuota || !notConfigured) && ( + <> +
+ { + hasModelList + ? t('common.modelProvider.modelsNum', { num: modelList.length }) + : t('common.modelProvider.showModels') + } + {!loading && } +
+
+ { + hasModelList + ? t('common.modelProvider.showModelsNum', { num: modelList.length }) + : t('common.modelProvider.showModels') + } + {!loading && } + { + loading && ( + + ) + } +
+ + )} + {!showQuota && notConfigured && ( +
+ + {t('common.modelProvider.configureTip')} +
+ )} { configurationMethods.includes(ConfigurationMethodEnum.customizableModel) && isCurrentWorkspaceManager && ( = ({
- + {t('common.modelProvider.modelsNum', { num: models.length })} From e7dc16fd08d09966c2fd191bbe28a2d51413f2fe Mon Sep 17 00:00:00 2001 From: JzoNg Date: Fri, 11 Oct 2024 16:21:03 +0800 Subject: [PATCH 7/7] provider card --- .../(commonLayout)/plugins/test/card/page.tsx | 2 +- .../model-provider-page/index.tsx | 49 ++++++++++-- .../components/plugins/install-model-item.tsx | 7 +- web/app/components/plugins/provider-card.tsx | 74 +++++++++++++++++++ web/i18n/en-US/common.ts | 2 +- 5 files changed, 124 insertions(+), 10 deletions(-) create mode 100644 web/app/components/plugins/provider-card.tsx diff --git a/web/app/(commonLayout)/plugins/test/card/page.tsx b/web/app/(commonLayout)/plugins/test/card/page.tsx index e7ba6849bb..0b76e183f9 100644 --- a/web/app/(commonLayout)/plugins/test/card/page.tsx +++ b/web/app/(commonLayout)/plugins/test/card/page.tsx @@ -43,7 +43,7 @@ const PluginList = async () => {

Install model provide

{pluginList.map((plugin, index) => ( - + ))}
diff --git a/web/app/components/header/account-setting/model-provider-page/index.tsx b/web/app/components/header/account-setting/model-provider-page/index.tsx index 8dc6513c05..5f0ac829c1 100644 --- a/web/app/components/header/account-setting/model-provider-page/index.tsx +++ b/web/app/components/header/account-setting/model-provider-page/index.tsx @@ -1,6 +1,13 @@ -import { useMemo } from 'react' +import { useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' -import { RiAlertFill, RiBrainLine } from '@remixicon/react' +import Link from 'next/link' +import { + RiAlertFill, + RiArrowDownSLine, + RiArrowRightUpLine, + RiBrainLine, +} from '@remixicon/react' +import { useContext } from 'use-context-selector' import SystemModelSelector from './system-model-selector' import ProviderAddedCard, { UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST } from './provider-added-card' // import ProviderCard from './provider-card' @@ -18,11 +25,16 @@ import { useUpdateModelList, useUpdateModelProviders, } from './hooks' +import Divider from '@/app/components/base/divider' +import ProviderCard from '@/app/components/plugins/provider-card' +import I18n from '@/context/i18n' import { useProviderContext } from '@/context/provider-context' import { useModalContextSelector } from '@/context/modal-context' import { useEventEmitterContextContext } from '@/context/event-emitter' import cn from '@/utils/classnames' +import { extensionDallE, modelGPT4, toolNotion } from '@/app/components/plugins/card/card-mock' + const ModelProviderPage = () => { const { t } = useTranslation() const { eventEmitter } = useEventEmitterContextContext() @@ -89,6 +101,12 @@ const ModelProviderPage = () => { }) } + const [collapse, setCollapse] = useState(false) + const { locale } = useContext(I18n) + + // TODO #Plugin list API# + const pluginList = [toolNotion, extensionDallE, modelGPT4] + return (
@@ -134,7 +152,7 @@ const ModelProviderPage = () => { ))}
)} - {!!notConfiguredProviders?.length && ( + {false && !!notConfiguredProviders?.length && ( <>
{t('common.modelProvider.configureRequired')}
@@ -149,8 +167,29 @@ const ModelProviderPage = () => {
)} -
{t('common.modelProvider.installProvider')}
-
{t('common.modelProvider.discoverMore')}
+
+ +
+
setCollapse(!collapse)}> + + {t('common.modelProvider.installProvider')} +
+
+ {t('common.modelProvider.discoverMore')} + + Dify Marketplace + + +
+
+ {!collapse && ( +
+ {pluginList.map((plugin, index) => ( + + ))} +
+ )} +
) } diff --git a/web/app/components/plugins/install-model-item.tsx b/web/app/components/plugins/install-model-item.tsx index 05d8426566..57a00ce1ef 100644 --- a/web/app/components/plugins/install-model-item.tsx +++ b/web/app/components/plugins/install-model-item.tsx @@ -1,5 +1,5 @@ -import type { FC } from 'react' import React from 'react' +import type { FC } from 'react' import { RiVerifiedBadgeLine } from '@remixicon/react' import Badge from '../base/badge' import type { Plugin } from './types' @@ -7,19 +7,20 @@ import Description from './card/base/description' import Icon from './card/base/card-icon' import Title from './card/base/title' import DownloadCount from './card/base/download-count' -import { getLocaleOnServer } from '@/i18n/server' +import type { Locale } from '@/i18n' import cn from '@/utils/classnames' type Props = { className?: string + locale: Locale // The component is used in both client and server side, so we can't get the locale from both side(getLocaleOnServer and useContext) payload: Plugin } const PluginItem: FC = async ({ className, + locale, payload, }) => { - const locale = getLocaleOnServer() const { org, label } = payload return ( diff --git a/web/app/components/plugins/provider-card.tsx b/web/app/components/plugins/provider-card.tsx new file mode 100644 index 0000000000..4892d9da29 --- /dev/null +++ b/web/app/components/plugins/provider-card.tsx @@ -0,0 +1,74 @@ +import React from 'react' +import type { FC } from 'react' +import { RiArrowRightUpLine, RiVerifiedBadgeLine } from '@remixicon/react' +import Badge from '../base/badge' +import type { Plugin } from './types' +import Description from './card/base/description' +import Icon from './card/base/card-icon' +import Title from './card/base/title' +import DownloadCount from './card/base/download-count' +import Button from '@/app/components/base/button' +import type { Locale } from '@/i18n' +import cn from '@/utils/classnames' + +type Props = { + className?: string + locale: Locale // The component is used in both client and server side, so we can't get the locale from both side(getLocaleOnServer and useContext) + payload: Plugin +} + +const ProviderCard: FC = ({ + className, + locale, + payload, +}) => { + const { org, label } = payload + + return ( +
+ {/* Header */} +
+ +
+
+ + <RiVerifiedBadgeLine className="shrink-0 ml-0.5 w-4 h-4 text-text-accent" /> + </div> + <div className='mb-1 flex justify-between items-center h-4'> + <div className='flex items-center'> + <div className='text-text-tertiary system-xs-regular'>{org}</div> + <div className='mx-2 text-text-quaternary system-xs-regular'>·</div> + <DownloadCount downloadCount={payload.install_count || 0} /> + </div> + </div> + </div> + </div> + <Description className='mt-3' text={payload.brief[locale]} descriptionLineRows={2}></Description> + <div className='mt-3 flex space-x-0.5'> + {['LLM', 'text embedding', 'speech2text'].map(tag => ( + <Badge key={tag} text={tag} /> + ))} + </div> + <div + className='hidden group-hover:flex items-center gap-2 absolute bottom-0 left-0 right-0 p-4 pt-8' + style={{ background: 'linear-gradient(0deg, #F9FAFB 60.27%, rgba(249, 250, 251, 0.00) 100%)' }} + > + <Button + className='flex-grow' + variant='primary' + > + Install + </Button> + <Button + className='flex-grow' + variant='secondary' + > + Details + <RiArrowRightUpLine className='w-4 h-4' /> + </Button> + </div> + </div> + ) +} + +export default ProviderCard diff --git a/web/i18n/en-US/common.ts b/web/i18n/en-US/common.ts index 11db6f7359..963a9d6a59 100644 --- a/web/i18n/en-US/common.ts +++ b/web/i18n/en-US/common.ts @@ -377,7 +377,7 @@ const translation = { configureRequired: 'Configure required', configureTip: 'Set up api-key or add model to use', installProvider: 'Install model providers', - discoverMore: 'Discover more in', + discoverMore: 'Discover more in ', emptyProviderTitle: 'Model provider not set up', emptyProviderTip: 'Please install a model provider first.', },