You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

plugins-picker.tsx 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import NoPluginSelected from './no-plugin-selected'
  5. import { AUTO_UPDATE_MODE } from './types'
  6. import PluginsSelected from './plugins-selected'
  7. import Button from '@/app/components/base/button'
  8. import { RiAddLine } from '@remixicon/react'
  9. import { useTranslation } from 'react-i18next'
  10. import { useBoolean } from 'ahooks'
  11. import ToolPicker from './tool-picker'
  12. const i18nPrefix = 'plugin.autoUpdate'
  13. type Props = {
  14. updateMode: AUTO_UPDATE_MODE
  15. value: string[] // plugin ids
  16. onChange: (value: string[]) => void
  17. }
  18. const PluginsPicker: FC<Props> = ({
  19. updateMode,
  20. value,
  21. onChange,
  22. }) => {
  23. const { t } = useTranslation()
  24. const hasSelected = value.length > 0
  25. const isExcludeMode = updateMode === AUTO_UPDATE_MODE.exclude
  26. const handleClear = () => {
  27. onChange([])
  28. }
  29. const [isShowToolPicker, {
  30. set: setToolPicker,
  31. }] = useBoolean(false)
  32. return (
  33. <div className='mt-2 rounded-[10px] bg-background-section-burn p-2.5'>
  34. {hasSelected ? (
  35. <div className='flex justify-between text-text-tertiary'>
  36. <div className='system-xs-medium'>{t(`${i18nPrefix}.${isExcludeMode ? 'excludeUpdate' : 'partialUPdate'}`, { num: value.length })}</div>
  37. <div className='system-xs-medium cursor-pointer' onClick={handleClear}>{t(`${i18nPrefix}.operation.clearAll`)}</div>
  38. </div>
  39. ) : (
  40. <NoPluginSelected updateMode={updateMode} />
  41. )}
  42. {hasSelected && (
  43. <PluginsSelected
  44. className='mt-2'
  45. plugins={value}
  46. />
  47. )}
  48. <ToolPicker
  49. trigger={
  50. <Button className='mt-2 w-[412px]' size='small' variant='secondary-accent'>
  51. <RiAddLine className='size-3.5' />
  52. {t(`${i18nPrefix}.operation.select`)}
  53. </Button>
  54. }
  55. value={value}
  56. onChange={onChange}
  57. isShow={isShowToolPicker}
  58. onShowChange={setToolPicker}
  59. />
  60. </div>
  61. )
  62. }
  63. export default React.memo(PluginsPicker)