import React from 'react' import { connect, ConnectedProps } from 'react-redux' import ReactTooltip from 'react-tooltip' import { t } from 'ttag' import EditableLabel from '../components/EditableLabel' import config from '../config' import { removeTrait, setTraitTransfer } from '../actions/traits' const connector = connect( (_: any, { trait }: { trait: any }) => { const traitConfig = config.functions.find(item => item.name === trait.name) return { trait, traitConfig } }, (dispatch: (action: any) => any) => { return { onRemove: (index: number) => dispatch(removeTrait(index)), onTransferChange: (index: number, transfer: string) => dispatch(setTraitTransfer(index, parseFloat(transfer))), } }, ) type TraitProps = ConnectedProps & { index: number } const Trait = ({ index, trait, traitConfig, onRemove, onTransferChange }: TraitProps) => { const { name, value } = trait const { customTransfer, label, units = null, description = null } = traitConfig const transfer = trait.transfer === null ? traitConfig.transfer : trait.transfer return ( { e.stopPropagation() onRemove(index) }} /> {label} {value !== null ? value.toFixed(2) : '--'} {units} {customTransfer ? ( onTransferChange(index, newValue)} /> ) : ( transfer )} {units}
{label}
{description !== null ?
{description}
: null}
{t`Value at point:`} {value !== null ? value.toFixed(2) : '--'} {units}
{t`Transfer limit (+/-):`} {transfer} {units}
) } export default connector(Trait)