chore: update the plugins tab button

This commit is contained in:
Yi 2024-11-14 18:26:16 +08:00
parent a403fb565d
commit 42ba4e4f0e
7 changed files with 38 additions and 18 deletions

View File

@ -4,6 +4,8 @@ import { useTranslation } from 'react-i18next'
import Link from 'next/link' import Link from 'next/link'
import classNames from '@/utils/classnames' import classNames from '@/utils/classnames'
import { Group } from '@/app/components/base/icons/src/vender/other' import { Group } from '@/app/components/base/icons/src/vender/other'
import { useSelectedLayoutSegment } from 'next/navigation'
type PluginsNavProps = { type PluginsNavProps = {
className?: string className?: string
} }
@ -12,12 +14,17 @@ const PluginsNav = ({
className, className,
}: PluginsNavProps) => { }: PluginsNavProps) => {
const { t } = useTranslation() const { t } = useTranslation()
const selectedSegment = useSelectedLayoutSegment()
const activated = selectedSegment === 'plugins'
return ( return (
<Link href="/plugins" className={classNames( <Link href="/plugins" className={classNames(
className, 'group', className, 'group',
)}> )}>
<div className='flex flex-row h-8 p-1.5 gap-0.5 items-center justify-center rounded-xl system-sm-medium-uppercase hover:bg-state-base-hover text-text-tertiary hover:text-text-secondary'> <div className={`flex flex-row h-8 p-1.5 gap-0.5 items-center justify-center
rounded-xl system-sm-medium-uppercase ${activated
? 'border border-components-main-nav-nav-button-border bg-components-main-nav-nav-button-bg-active shadow-md text-components-main-nav-nav-button-text'
: 'text-text-tertiary hover:bg-state-base-hover hover:text-text-secondary'}`}>
<div className='flex w-4 h-4 justify-center items-center'> <div className='flex w-4 h-4 justify-center items-center'>
<Group /> <Group />
</div> </div>

View File

@ -7,7 +7,8 @@ import Card from '../../../card'
import Badge, { BadgeState } from '@/app/components/base/badge/index' import Badge, { BadgeState } from '@/app/components/base/badge/index'
import { pluginManifestToCardPluginProps } from '../../utils' import { pluginManifestToCardPluginProps } from '../../utils'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { installPackageFromGitHub, updateFromGitHub } from '@/service/plugins' import { updateFromGitHub } from '@/service/plugins'
import { useInstallPackageFromGitHub } from '@/service/use-plugins'
import { RiLoader2Line } from '@remixicon/react' import { RiLoader2Line } from '@remixicon/react'
import { usePluginTaskList } from '@/service/use-plugins' import { usePluginTaskList } from '@/service/use-plugins'
import checkTaskStatus from '../../base/check-task-status' import checkTaskStatus from '../../base/check-task-status'
@ -40,6 +41,7 @@ const Loaded: React.FC<LoadedProps> = ({
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
const [isInstalling, setIsInstalling] = React.useState(false) const [isInstalling, setIsInstalling] = React.useState(false)
const { mutateAsync: installPackageFromGitHub } = useInstallPackageFromGitHub()
const { handleRefetch } = usePluginTaskList() const { handleRefetch } = usePluginTaskList()
const { check } = checkTaskStatus() const { check } = checkTaskStatus()
@ -72,12 +74,12 @@ const Loaded: React.FC<LoadedProps> = ({
onInstalled() onInstalled()
} }
else { else {
const { all_installed: isInstalled, task_id: taskId } = await installPackageFromGitHub( const { all_installed: isInstalled, task_id: taskId } = await installPackageFromGitHub({
`${owner}/${repo}`, repoUrl: `${owner}/${repo}`,
selectedVersion, selectedVersion,
selectedPackage, selectedPackage,
uniqueIdentifier, uniqueIdentifier,
) })
if (isInstalled) { if (isInstalled) {
onInstalled() onInstalled()

View File

@ -132,7 +132,7 @@ const PluginPage = ({
options={options} options={options}
/> />
</div> </div>
<div className='flex flex-shrink-0 items-center gap-1'> <div className='flex shrink-0 items-center gap-1'>
<PluginTasks /> <PluginTasks />
{canManagement && ( {canManagement && (
<InstallPluginDropdown <InstallPluginDropdown
@ -172,7 +172,7 @@ const PluginPage = ({
)} )}
<div className={`flex py-4 justify-center items-center gap-2 ${dragging ? 'text-text-accent' : 'text-text-quaternary'}`}> <div className={`flex py-4 justify-center items-center gap-2 ${dragging ? 'text-text-accent' : 'text-text-quaternary'}`}>
<RiDragDropLine className="w-4 h-4" /> <RiDragDropLine className="w-4 h-4" />
<span className="system-xs-regular">Drop plugin package here to install</span> <span className="system-xs-regular">{t('plugin.installModal.dropPluginToInstall')}</span>
</div> </div>
{currentFile && ( {currentFile && (
<InstallFromLocalPackage <InstallFromLocalPackage

View File

@ -103,6 +103,7 @@ const translation = {
readyToInstallPackage: 'About to install the following plugin', readyToInstallPackage: 'About to install the following plugin',
readyToInstallPackages: 'About to install the following {{num}} plugins', readyToInstallPackages: 'About to install the following {{num}} plugins',
fromTrustSource: 'Please make sure that you only install plugins from a <trustSource>trusted source</trustSource>.', fromTrustSource: 'Please make sure that you only install plugins from a <trustSource>trusted source</trustSource>.',
dropPluginToInstall: 'Drop plugin package here to install',
labels: { labels: {
repository: 'Repository', repository: 'Repository',
version: 'Version', version: 'Version',

View File

@ -103,6 +103,7 @@ const translation = {
readyToInstallPackage: '即将安装以下插件', readyToInstallPackage: '即将安装以下插件',
readyToInstallPackages: '即将安装以下 {{num}} 个插件', readyToInstallPackages: '即将安装以下 {{num}} 个插件',
fromTrustSource: '请保证仅从<trustSource>可信源</trustSource>安装插件。', fromTrustSource: '请保证仅从<trustSource>可信源</trustSource>安装插件。',
dropPluginToInstall: '拖放插件包到此处安装',
labels: { labels: {
repository: '仓库', repository: '仓库',
version: '版本', version: '版本',

View File

@ -54,17 +54,6 @@ export const uploadGitHub = async (repoUrl: string, selectedVersion: string, sel
}) })
} }
export const installPackageFromGitHub = async (repoUrl: string, selectedVersion: string, selectedPackage: string, uniqueIdentifier: string) => {
return post<InstallPackageResponse>('/workspaces/current/plugin/install/github', {
body: {
repo: repoUrl,
version: selectedVersion,
package: selectedPackage,
plugin_unique_identifier: uniqueIdentifier,
},
})
}
export const fetchIcon = (tenantId: string, fileName: string) => { export const fetchIcon = (tenantId: string, fileName: string) => {
return get(`workspaces/current/plugin/icon?tenant_id=${tenantId}&filename=${fileName}`) return get(`workspaces/current/plugin/icon?tenant_id=${tenantId}&filename=${fileName}`)
} }

View File

@ -60,6 +60,26 @@ export const useInstallPackageFromLocal = () => {
}) })
} }
export const useInstallPackageFromGitHub = () => {
return useMutation({
mutationFn: ({ repoUrl, selectedVersion, selectedPackage, uniqueIdentifier }: {
repoUrl: string
selectedVersion: string
selectedPackage: string
uniqueIdentifier: string
}) => {
return post<InstallPackageResponse>('/workspaces/current/plugin/install/github', {
body: {
repo: repoUrl,
version: selectedVersion,
package: selectedPackage,
plugin_unique_identifier: uniqueIdentifier,
},
})
},
})
}
export const useDebugKey = () => { export const useDebugKey = () => {
return useQuery({ return useQuery({
queryKey: [NAME_SPACE, 'debugKey'], queryKey: [NAME_SPACE, 'debugKey'],