/* eslint-disable camelcase */ import React, { Fragment } from 'react'; import { Field } from 'redux-form'; import { Margin, Padding } from 'styled-components-spacing'; import Flex, { FlexItem } from 'styled-flex-component'; import styled from 'styled-components'; import remcalc from 'remcalc'; import { H3, FormGroup, Toggle, Divider, Row, Col, TagList, P } from 'joyent-ui-toolkit'; import Tag from '@components/instances/tags'; import Empty from './empty'; const capitalizeFirstLetter = string => string.charAt(0).toUpperCase() + string.slice(1); const Box = styled.div` display: inline-block; background-color: ${props => props.theme.white}; border: ${remcalc(1)} solid ${props => props.theme.grey}; min-width: 100%; `; const Wildcards = { vmall: 'All VMs in DC', any: 'Any' }; const parsePartial = (p, index) => { if (p[0] === 'wildcard') { return {Wildcards[p[1]]}; } if (p[0] === 'tag') { const value = Array.isArray(p[1]) ? p[1][1] : ''; const name = Array.isArray(p[1]) ? p[1][0] : p[1]; return ; } }; const Rule = ({ enabled, rule_obj }) => { const { action, protocol } = rule_obj; const froms = rule_obj.from.map(parsePartial); const tos = rule_obj.to.map(parsePartial); return ( From: {froms} To: {tos} Protocol: {protocol.name} Ports: {protocol.targets.join(';')} Action: {capitalizeFirstLetter(action)} ); }; export default ({ defaultRules = [], tagRules = [], enabled = false, handleSubmit }) => (
Enable firewall rules {enabled ? ( Show inactive rules ) : null} {enabled && defaultRules.length ? (

Default firewall rules

{defaultRules.map(rule => ( ))}
) : null} {enabled && !defaultRules.length ? ( Sorry, but we weren’t able to find any firewalls. ) : null} {enabled && tagRules.length && defaultRules.length ? ( ) : null} {enabled && tagRules.length ? (

Firewall rules from instance tags

{tagRules.map(rule => ( ))}
) : null} {enabled && (tagRules.length || defaultRules.length) ? ( ) : null} {enabled ? (

*Other firewall rules may apply as defined by wildcard(s), IP(s), subnet(s), tag(s) or VM(s). Please see{' '} firewall rule list {' '} for more details.

) : null} );