|
|
|
@ -1,15 +1,18 @@
|
|
|
|
'use client'
|
|
|
|
'use client'
|
|
|
|
import type { FC } from 'react'
|
|
|
|
import type { FC } from 'react'
|
|
|
|
|
|
|
|
import { useRef } from 'react'
|
|
|
|
import React, { useCallback, useState } from 'react'
|
|
|
|
import React, { useCallback, useState } from 'react'
|
|
|
|
import type { Dependency, InstallStatusResponse, Plugin, VersionInfo } from '../../../types'
|
|
|
|
import type { Dependency, InstallStatusResponse, Plugin, VersionInfo } from '../../../types'
|
|
|
|
import Button from '@/app/components/base/button'
|
|
|
|
import Button from '@/app/components/base/button'
|
|
|
|
import { RiLoader2Line } from '@remixicon/react'
|
|
|
|
import { RiLoader2Line } from '@remixicon/react'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
|
|
|
|
import type { ExposeRefs } from './install-multi'
|
|
|
|
import InstallMulti from './install-multi'
|
|
|
|
import InstallMulti from './install-multi'
|
|
|
|
import { useInstallOrUpdate } from '@/service/use-plugins'
|
|
|
|
import { useInstallOrUpdate } from '@/service/use-plugins'
|
|
|
|
import useRefreshPluginList from '../../hooks/use-refresh-plugin-list'
|
|
|
|
import useRefreshPluginList from '../../hooks/use-refresh-plugin-list'
|
|
|
|
import { useCanInstallPluginFromMarketplace } from '@/app/components/plugins/plugin-page/use-permission'
|
|
|
|
import { useCanInstallPluginFromMarketplace } from '@/app/components/plugins/plugin-page/use-permission'
|
|
|
|
import { useMittContextSelector } from '@/context/mitt-context'
|
|
|
|
import { useMittContextSelector } from '@/context/mitt-context'
|
|
|
|
|
|
|
|
import Checkbox from '@/app/components/base/checkbox'
|
|
|
|
const i18nPrefix = 'plugin.installModal'
|
|
|
|
const i18nPrefix = 'plugin.installModal'
|
|
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
type Props = {
|
|
|
|
@ -34,18 +37,8 @@ const Install: FC<Props> = ({
|
|
|
|
const [selectedPlugins, setSelectedPlugins] = React.useState<Plugin[]>([])
|
|
|
|
const [selectedPlugins, setSelectedPlugins] = React.useState<Plugin[]>([])
|
|
|
|
const [selectedIndexes, setSelectedIndexes] = React.useState<number[]>([])
|
|
|
|
const [selectedIndexes, setSelectedIndexes] = React.useState<number[]>([])
|
|
|
|
const selectedPluginsNum = selectedPlugins.length
|
|
|
|
const selectedPluginsNum = selectedPlugins.length
|
|
|
|
|
|
|
|
const installMultiRef = useRef<ExposeRefs>(null)
|
|
|
|
const { refreshPluginList } = useRefreshPluginList()
|
|
|
|
const { refreshPluginList } = useRefreshPluginList()
|
|
|
|
const handleSelect = (plugin: Plugin, selectedIndex: number) => {
|
|
|
|
|
|
|
|
const isSelected = !!selectedPlugins.find(p => p.plugin_id === plugin.plugin_id)
|
|
|
|
|
|
|
|
let nextSelectedPlugins
|
|
|
|
|
|
|
|
if (isSelected)
|
|
|
|
|
|
|
|
nextSelectedPlugins = selectedPlugins.filter(p => p.plugin_id !== plugin.plugin_id)
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
nextSelectedPlugins = [...selectedPlugins, plugin]
|
|
|
|
|
|
|
|
setSelectedPlugins(nextSelectedPlugins)
|
|
|
|
|
|
|
|
const nextSelectedIndexes = isSelected ? selectedIndexes.filter(i => i !== selectedIndex) : [...selectedIndexes, selectedIndex]
|
|
|
|
|
|
|
|
setSelectedIndexes(nextSelectedIndexes)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [canInstall, setCanInstall] = React.useState(false)
|
|
|
|
const [canInstall, setCanInstall] = React.useState(false)
|
|
|
|
const [installedInfo, setInstalledInfo] = useState<Record<string, VersionInfo> | undefined>(undefined)
|
|
|
|
const [installedInfo, setInstalledInfo] = useState<Record<string, VersionInfo> | undefined>(undefined)
|
|
|
|
@ -81,6 +74,51 @@ const Install: FC<Props> = ({
|
|
|
|
installedInfo: installedInfo!,
|
|
|
|
installedInfo: installedInfo!,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const [isSelectAll, setIsSelectAll] = useState(false)
|
|
|
|
|
|
|
|
const [isIndeterminate, setIsIndeterminate] = useState(false)
|
|
|
|
|
|
|
|
const handleClickSelectAll = useCallback(() => {
|
|
|
|
|
|
|
|
if (isSelectAll)
|
|
|
|
|
|
|
|
installMultiRef.current?.deSelectAllPlugins()
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
installMultiRef.current?.selectAllPlugins()
|
|
|
|
|
|
|
|
}, [isSelectAll])
|
|
|
|
|
|
|
|
const handleSelectAll = useCallback((plugins: Plugin[], selectedIndexes: number[]) => {
|
|
|
|
|
|
|
|
setSelectedPlugins(plugins)
|
|
|
|
|
|
|
|
setSelectedIndexes(selectedIndexes)
|
|
|
|
|
|
|
|
setIsSelectAll(true)
|
|
|
|
|
|
|
|
setIsIndeterminate(false)
|
|
|
|
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
const handleDeSelectAll = useCallback(() => {
|
|
|
|
|
|
|
|
setSelectedPlugins([])
|
|
|
|
|
|
|
|
setSelectedIndexes([])
|
|
|
|
|
|
|
|
setIsSelectAll(false)
|
|
|
|
|
|
|
|
setIsIndeterminate(false)
|
|
|
|
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleSelect = useCallback((plugin: Plugin, selectedIndex: number, allPluginsLength: number) => {
|
|
|
|
|
|
|
|
const isSelected = !!selectedPlugins.find(p => p.plugin_id === plugin.plugin_id)
|
|
|
|
|
|
|
|
let nextSelectedPlugins
|
|
|
|
|
|
|
|
if (isSelected)
|
|
|
|
|
|
|
|
nextSelectedPlugins = selectedPlugins.filter(p => p.plugin_id !== plugin.plugin_id)
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
nextSelectedPlugins = [...selectedPlugins, plugin]
|
|
|
|
|
|
|
|
setSelectedPlugins(nextSelectedPlugins)
|
|
|
|
|
|
|
|
const nextSelectedIndexes = isSelected ? selectedIndexes.filter(i => i !== selectedIndex) : [...selectedIndexes, selectedIndex]
|
|
|
|
|
|
|
|
setSelectedIndexes(nextSelectedIndexes)
|
|
|
|
|
|
|
|
if (nextSelectedPlugins.length === 0) {
|
|
|
|
|
|
|
|
setIsSelectAll(false)
|
|
|
|
|
|
|
|
setIsIndeterminate(false)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (nextSelectedPlugins.length === allPluginsLength) {
|
|
|
|
|
|
|
|
setIsSelectAll(true)
|
|
|
|
|
|
|
|
setIsIndeterminate(false)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
setIsIndeterminate(true)
|
|
|
|
|
|
|
|
setIsSelectAll(false)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, [selectedPlugins, selectedIndexes])
|
|
|
|
|
|
|
|
|
|
|
|
const { canInstallPluginFromMarketplace } = useCanInstallPluginFromMarketplace()
|
|
|
|
const { canInstallPluginFromMarketplace } = useCanInstallPluginFromMarketplace()
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<>
|
|
|
|
@ -90,9 +128,12 @@ const Install: FC<Props> = ({
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className='w-full space-y-1 rounded-2xl bg-background-section-burn p-2'>
|
|
|
|
<div className='w-full space-y-1 rounded-2xl bg-background-section-burn p-2'>
|
|
|
|
<InstallMulti
|
|
|
|
<InstallMulti
|
|
|
|
|
|
|
|
ref={installMultiRef}
|
|
|
|
allPlugins={allPlugins}
|
|
|
|
allPlugins={allPlugins}
|
|
|
|
selectedPlugins={selectedPlugins}
|
|
|
|
selectedPlugins={selectedPlugins}
|
|
|
|
onSelect={handleSelect}
|
|
|
|
onSelect={handleSelect}
|
|
|
|
|
|
|
|
onSelectAll={handleSelectAll}
|
|
|
|
|
|
|
|
onDeSelectAll={handleDeSelectAll}
|
|
|
|
onLoadedAllPlugin={handleLoadedAllPlugin}
|
|
|
|
onLoadedAllPlugin={handleLoadedAllPlugin}
|
|
|
|
isFromMarketPlace={isFromMarketPlace}
|
|
|
|
isFromMarketPlace={isFromMarketPlace}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
@ -100,7 +141,14 @@ const Install: FC<Props> = ({
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/* Action Buttons */}
|
|
|
|
{/* Action Buttons */}
|
|
|
|
{!isHideButton && (
|
|
|
|
{!isHideButton && (
|
|
|
|
<div className='flex items-center justify-end gap-2 self-stretch p-6 pt-5'>
|
|
|
|
<div className='flex items-center justify-between gap-2 self-stretch p-6 pt-5'>
|
|
|
|
|
|
|
|
<div className='px-2'>
|
|
|
|
|
|
|
|
{canInstall && <div className='flex items-center gap-x-2' onClick={handleClickSelectAll}>
|
|
|
|
|
|
|
|
<Checkbox checked={isSelectAll} indeterminate={isIndeterminate} />
|
|
|
|
|
|
|
|
<p className='system-sm-medium cursor-pointer text-text-secondary'>{isSelectAll ? t('common.operation.deSelectAll') : t('common.operation.selectAll')}</p>
|
|
|
|
|
|
|
|
</div>}
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className='flex items-center justify-end gap-2 self-stretch'>
|
|
|
|
{!canInstall && (
|
|
|
|
{!canInstall && (
|
|
|
|
<Button variant='secondary' className='min-w-[72px]' onClick={onCancel}>
|
|
|
|
<Button variant='secondary' className='min-w-[72px]' onClick={onCancel}>
|
|
|
|
{t('common.operation.cancel')}
|
|
|
|
{t('common.operation.cancel')}
|
|
|
|
@ -116,6 +164,7 @@ const Install: FC<Props> = ({
|
|
|
|
<span>{t(`${i18nPrefix}.${isInstalling ? 'installing' : 'install'}`)}</span>
|
|
|
|
<span>{t(`${i18nPrefix}.${isInstalling ? 'installing' : 'install'}`)}</span>
|
|
|
|
</Button>
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
</>
|
|
|
|
</>
|
|
|
|
|