feat: support sub variable operate changes with key and value support

This commit is contained in:
Joel 2024-08-21 15:27:08 +08:00
parent 5628b293f8
commit 0c4af3a1d2
2 changed files with 12 additions and 3 deletions

View File

@ -40,6 +40,7 @@ export type ISelectProps = {
overlayClassName?: string
optionWrapClassName?: string
optionClassName?: string
hideChecked?: boolean
renderOption?: ({
item,
selected,
@ -177,6 +178,7 @@ const SimpleSelect: FC<ISelectProps> = ({
placeholder,
optionWrapClassName,
optionClassName,
hideChecked,
renderOption,
}) => {
const { t } = useTranslation()
@ -257,7 +259,7 @@ const SimpleSelect: FC<ISelectProps> = ({
? renderOption({ item, selected })
: (<>
<span className={classNames('block', selected && 'font-normal')}>{item.name}</span>
{selected && (
{selected && !hideChecked && (
<span
className={classNames(
'absolute inset-y-0 right-0 flex items-center pr-4 text-gray-700',

View File

@ -19,7 +19,7 @@ import type {
import {
ComparisonOperator,
} from '../../types'
import { comparisonOperatorNotRequireValue } from '../../utils'
import { comparisonOperatorNotRequireValue, getOperators } from '../../utils'
import ConditionNumberInput from '../condition-number-input'
import { FILE_TYPE_OPTIONS, SUB_VARIABLES, TRANSFER_METHOD } from '../../default'
import ConditionWrap from '../condition-wrap'
@ -141,7 +141,13 @@ const ConditionItem = ({
const handleSubVarKeyChange = useCallback((key: string) => {
const newCondition = produce(condition, (draft) => {
draft.key = key
if (key === 'size')
draft.varType = VarType.number
else
draft.varType = VarType.string
draft.comparison_operator = getOperators(undefined, { key })[0]
})
onUpdateSubVariableCondition?.(caseId, conditionId, condition.id, newCondition)
}, [caseId, condition, conditionId, onUpdateSubVariableCondition])
@ -179,6 +185,7 @@ const ConditionItem = ({
</div>
: <div className='text-gray-300 system-xs-medium'>{t('common.placeholder.select')}</div>
)}
hideChecked
/>
)
: (
@ -195,7 +202,7 @@ const ConditionItem = ({
varType={condition.varType}
value={condition.comparison_operator}
onSelect={handleUpdateConditionOperator}
file={file}
file={isSubVariableKey ? { key: condition.key! } : file}
/>
</div>
{