refactor(env-panel): improve environment variable item layout and styling
- Move padding to inner container for better hover effects - Add description section with divider when present - Use group hover for consistent stylingpull/21556/head
parent
ea135c4e6b
commit
3e8ac9dc2b
@ -1,56 +1,65 @@
|
|||||||
import { memo, useState } from 'react'
|
import { memo, useState } from 'react'
|
||||||
import { capitalize } from 'lodash-es'
|
import { capitalize } from 'lodash-es'
|
||||||
import { RiDeleteBinLine, RiEditLine, RiLock2Line } from '@remixicon/react'
|
import { RiDeleteBinLine, RiEditLine, RiLock2Line } from '@remixicon/react'
|
||||||
import { Env } from '@/app/components/base/icons/src/vender/line/others'
|
import { Env } from '@/app/components/base/icons/src/vender/line/others'
|
||||||
import { useStore } from '@/app/components/workflow/store'
|
import { useStore } from '@/app/components/workflow/store'
|
||||||
import { useTranslation } from 'react-i18next'
|
import type { EnvironmentVariable } from '@/app/components/workflow/types'
|
||||||
import type { EnvironmentVariable } from '@/app/components/workflow/types'
|
import cn from '@/utils/classnames'
|
||||||
import cn from '@/utils/classnames'
|
|
||||||
|
type EnvItemProps = {
|
||||||
type EnvItemProps = {
|
env: EnvironmentVariable
|
||||||
env: EnvironmentVariable
|
onEdit: (env: EnvironmentVariable) => void
|
||||||
onEdit: (env: EnvironmentVariable) => void
|
onDelete: (env: EnvironmentVariable) => void
|
||||||
onDelete: (env: EnvironmentVariable) => void
|
}
|
||||||
}
|
|
||||||
|
const EnvItem = ({
|
||||||
const EnvItem = ({
|
env,
|
||||||
env,
|
onEdit,
|
||||||
onEdit,
|
onDelete,
|
||||||
onDelete,
|
}: EnvItemProps) => {
|
||||||
}: EnvItemProps) => {
|
const envSecrets = useStore(s => s.envSecrets)
|
||||||
const { t } = useTranslation()
|
const [destructive, setDestructive] = useState(false)
|
||||||
const envSecrets = useStore(s => s.envSecrets)
|
|
||||||
const [destructive, setDestructive] = useState(false)
|
return (
|
||||||
|
<div className={cn(
|
||||||
return (
|
'radius-md group mb-1 border border-components-panel-border-subtle bg-components-panel-on-panel-item-bg shadow-xs hover:bg-components-panel-on-panel-item-bg-hover',
|
||||||
<div className={cn(
|
destructive && 'border-state-destructive-border hover:bg-state-destructive-hover',
|
||||||
'radius-md mb-1 border border-components-panel-border-subtle bg-components-panel-on-panel-item-bg px-2.5 py-2 shadow-xs hover:bg-components-panel-on-panel-item-bg-hover',
|
)}>
|
||||||
destructive && 'border-state-destructive-border hover:bg-state-destructive-hover',
|
<div className='px-2.5 py-2'>
|
||||||
)}>
|
<div className='flex items-center justify-between'>
|
||||||
<div className='flex items-center justify-between'>
|
<div className='flex grow items-center gap-1'>
|
||||||
<div className='flex grow items-center gap-1'>
|
<Env className='h-4 w-4 text-util-colors-violet-violet-600' />
|
||||||
<Env className='h-4 w-4 text-util-colors-violet-violet-600' />
|
<div className='system-sm-medium text-text-primary'>{env.name}</div>
|
||||||
<div className='system-sm-medium text-text-primary'>{env.name}</div>
|
<div className='system-xs-medium text-text-tertiary'>{capitalize(env.value_type)}</div>
|
||||||
<div className='system-xs-medium text-text-tertiary'>{capitalize(env.value_type)}</div>
|
{env.value_type === 'secret' && <RiLock2Line className='h-3 w-3 text-text-tertiary' />}
|
||||||
{env.value_type === 'secret' && <RiLock2Line className='h-3 w-3 text-text-tertiary' />}
|
</div>
|
||||||
</div>
|
<div className='flex shrink-0 items-center gap-1 text-text-tertiary'>
|
||||||
<div className='flex shrink-0 items-center gap-1 text-text-tertiary'>
|
<div className='radius-md cursor-pointer p-1 hover:bg-state-base-hover hover:text-text-secondary'>
|
||||||
<div className='radius-md cursor-pointer p-1 hover:bg-state-base-hover hover:text-text-secondary'>
|
<RiEditLine className='h-4 w-4' onClick={() => onEdit(env)}/>
|
||||||
<RiEditLine className='h-4 w-4' onClick={() => onEdit(env)}/>
|
</div>
|
||||||
</div>
|
<div
|
||||||
<div
|
className='radius-md cursor-pointer p-1 hover:bg-state-destructive-hover hover:text-text-destructive'
|
||||||
className='radius-md cursor-pointer p-1 hover:bg-state-destructive-hover hover:text-text-destructive'
|
onMouseOver={() => setDestructive(true)}
|
||||||
onMouseOver={() => setDestructive(true)}
|
onMouseOut={() => setDestructive(false)}
|
||||||
onMouseOut={() => setDestructive(false)}
|
>
|
||||||
>
|
<RiDeleteBinLine className='h-4 w-4' onClick={() => onDelete(env)} />
|
||||||
<RiDeleteBinLine className='h-4 w-4' onClick={() => onDelete(env)} />
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div className='system-xs-regular truncate text-text-tertiary'>{env.value_type === 'secret' ? envSecrets[env.id] : env.value}</div>
|
||||||
<div className='system-xs-regular truncate text-text-tertiary'>{env.description ? (`${t('workflow.env.modal.description')}: ${env.description}`) : ''}</div>
|
</div>
|
||||||
<div className='system-xs-regular truncate text-text-tertiary'>{env.value_type === 'secret' ? envSecrets[env.id] : env.value}</div>
|
{env.description && (
|
||||||
</div>
|
<>
|
||||||
)
|
<div className={'h-[0.5px] bg-divider-subtle'} />
|
||||||
}
|
<div className={cn('rounded-bl-[8px] rounded-br-[8px] bg-background-default-subtle px-2.5 py-2 group-hover:bg-transparent',
|
||||||
|
destructive && 'bg-state-destructive-hover hover:bg-state-destructive-hover',
|
||||||
export default memo(EnvItem)
|
)}>
|
||||||
|
<div className='system-xs-regular truncate text-text-tertiary'>{env.description}</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default memo(EnvItem)
|
||||||
|
|||||||
Loading…
Reference in New Issue