env-item.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { memo, useState } from 'react'
  2. import { capitalize } from 'lodash-es'
  3. import { RiDeleteBinLine, RiEditLine, RiLock2Line } from '@remixicon/react'
  4. import { Env } from '@/app/components/base/icons/src/vender/line/others'
  5. import { useStore } from '@/app/components/workflow/store'
  6. import type { EnvironmentVariable } from '@/app/components/workflow/types'
  7. import cn from '@/utils/classnames'
  8. type EnvItemProps = {
  9. env: EnvironmentVariable
  10. onEdit: (env: EnvironmentVariable) => void
  11. onDelete: (env: EnvironmentVariable) => void
  12. }
  13. const EnvItem = ({
  14. env,
  15. onEdit,
  16. onDelete,
  17. }: EnvItemProps) => {
  18. const envSecrets = useStore(s => s.envSecrets)
  19. const [destructive, setDestructive] = useState(false)
  20. return (
  21. <div className={cn(
  22. 'mb-1 px-2.5 py-2 bg-components-panel-on-panel-item-bg radius-md border border-components-panel-border-subtle shadow-xs hover:bg-components-panel-on-panel-item-bg-hover',
  23. destructive && 'border-state-destructive-border hover:bg-state-destructive-hover',
  24. )}>
  25. <div className='flex items-center justify-between'>
  26. <div className='grow flex gap-1 items-center'>
  27. <Env className='w-4 h-4 text-util-colors-violet-violet-600' />
  28. <div className='text-text-primary system-sm-medium'>{env.name}</div>
  29. <div className='text-text-tertiary system-xs-medium'>{capitalize(env.value_type)}</div>
  30. {env.value_type === 'secret' && <RiLock2Line className='w-3 h-3 text-text-tertiary' />}
  31. </div>
  32. <div className='shrink-0 flex gap-1 items-center text-text-tertiary'>
  33. <div className='p-1 radius-md cursor-pointer hover:bg-state-base-hover hover:text-text-secondary'>
  34. <RiEditLine className='w-4 h-4' onClick={() => onEdit(env)}/>
  35. </div>
  36. <div
  37. className='p-1 radius-md cursor-pointer hover:bg-state-destructive-hover hover:text-text-destructive'
  38. onMouseOver={() => setDestructive(true)}
  39. onMouseOut={() => setDestructive(false)}
  40. >
  41. <RiDeleteBinLine className='w-4 h-4' onClick={() => onDelete(env)} />
  42. </div>
  43. </div>
  44. </div>
  45. <div className='text-text-tertiary system-xs-regular truncate'>{env.value_type === 'secret' ? envSecrets[env.id] : env.value}</div>
  46. </div>
  47. )
  48. }
  49. export default memo(EnvItem)