import React from 'react'; import { connect } from 'react-redux'; import PropTypes from 'prop-types'; import { Field, reduxForm, formValueSelector } from 'redux-form'; import { withNamespaces, Trans } from 'react-i18next'; import flow from 'lodash/flow'; const renderInterfaces = (interfaces => ( Object.keys(interfaces).map((item) => { const option = interfaces[item]; const { name } = option; const onlyIPv6 = option.ip_addresses.every(ip => ip.includes(':')); let interfaceIP = option.ip_addresses[0]; if (!onlyIPv6) { option.ip_addresses.forEach((ip) => { if (!ip.includes(':')) { interfaceIP = ip; } }); } return ( ); }) )); const renderInterfaceValues = (interfaceValues => ( )); let Interface = (props) => { const { t, handleChange, interfaces, processing, interfaceValue, enabled, } = props; return (
{!processing && interfaces &&
{renderInterfaces(interfaces)}
{interfaceValue &&
{renderInterfaceValues(interfaces[interfaceValue])}
}
}
); }; Interface.propTypes = { handleChange: PropTypes.func, interfaces: PropTypes.object, processing: PropTypes.bool, interfaceValue: PropTypes.string, initialValues: PropTypes.object, enabled: PropTypes.bool, t: PropTypes.func, }; const selector = formValueSelector('dhcpInterface'); Interface = connect((state) => { const interfaceValue = selector(state, 'interface_name'); return { interfaceValue, }; })(Interface); export default flow([ withNamespaces(), reduxForm({ form: 'dhcpInterface' }), ])(Interface);