import React from 'react' import { connect, ConnectedProps } from 'react-redux' import { t } from 'ttag' import Variable from './Variable' import { variables as allVariables } from '../config' import { addVariable } from '../actions/variables' import { setError } from '../actions/error' const connector = connect( (state: any) => { const { runConfiguration } = state const { variables } = runConfiguration const names = variables.map((item: any) => item.name) const unusedVariables = allVariables.filter(item => !names.includes(item.name)) return { variables, unusedVariables } }, (dispatch: (action: any) => any) => { return { onChange: (variable: string, variables: any[]) => { if (variables.length >= 6) { dispatch( setError( t`Configuration error`, t`You may only add 6 variables to your configuration. Please remove an exiting variable before adding another.`, ), ) return } dispatch(addVariable(variable)) }, } }, ) type VariablesProps = ConnectedProps & { edit: boolean } const Variables = ({ variables, unusedVariables, edit, onChange }: VariablesProps) => { let table = null if (variables.length > 0) { table = ( {variables.map((item: any, index: number) => ( ))}
 
{t`Name`}
{t`Center`} {t`Transfer limit (+/-)`}
) } return (
{table}
) } export default connector(Variables)