Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

item.tsx 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import {
  2. memo,
  3. useState,
  4. } from 'react'
  5. import { useTranslation } from 'react-i18next'
  6. import Indicator from '@/app/components/header/indicator'
  7. import Operator from './operator'
  8. import type {
  9. DataSourceCredential,
  10. } from './types'
  11. import Input from '@/app/components/base/input'
  12. import Button from '@/app/components/base/button'
  13. type ItemProps = {
  14. credentialItem: DataSourceCredential
  15. onAction: (action: string, credentialItem: DataSourceCredential, renamePayload?: Record<string, any>) => void
  16. }
  17. const Item = ({
  18. credentialItem,
  19. onAction,
  20. }: ItemProps) => {
  21. const { t } = useTranslation()
  22. const [renaming, setRenaming] = useState(false)
  23. const [renameValue, setRenameValue] = useState(credentialItem.name)
  24. return (
  25. <div className='flex h-10 items-center rounded-lg bg-components-panel-on-panel-item-bg pl-3 pr-1'>
  26. {/* <div className='mr-2 h-5 w-5 shrink-0'></div> */}
  27. {
  28. renaming && (
  29. <div className='flex w-full items-center space-x-1'>
  30. <Input
  31. wrapperClassName='grow rounded-[6px]'
  32. className='h-6'
  33. value={renameValue}
  34. onChange={e => setRenameValue(e.target.value)}
  35. placeholder={t('common.placeholder.input')}
  36. onClick={e => e.stopPropagation()}
  37. />
  38. <Button
  39. size='small'
  40. variant='primary'
  41. onClick={(e) => {
  42. e.stopPropagation()
  43. onAction?.(
  44. 'rename',
  45. credentialItem,
  46. {
  47. credential_id: credentialItem.id,
  48. name: renameValue,
  49. },
  50. )
  51. setRenaming(false)
  52. }}
  53. >
  54. {t('common.operation.save')}
  55. </Button>
  56. <Button
  57. size='small'
  58. onClick={(e) => {
  59. e.stopPropagation()
  60. setRenaming(false)
  61. }}
  62. >
  63. {t('common.operation.cancel')}
  64. </Button>
  65. </div>
  66. )
  67. }
  68. {
  69. !renaming && (
  70. <div className='system-sm-medium grow text-text-secondary'>
  71. {credentialItem.name}
  72. </div>
  73. )
  74. }
  75. <div className='flex shrink-0 items-center'>
  76. <div className='mr-1 flex h-3 w-3 items-center justify-center'>
  77. <Indicator color='green' />
  78. </div>
  79. <div className='system-xs-semibold-uppercase text-util-colors-green-green-600'>
  80. connected
  81. </div>
  82. </div>
  83. <div className='ml-3 mr-2 h-3 w-[1px] bg-divider-regular'></div>
  84. <Operator
  85. credentialItem={credentialItem}
  86. onAction={onAction}
  87. onRename={() => setRenaming(true)}
  88. />
  89. </div>
  90. )
  91. }
  92. export default memo(Item)