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 constantCase from 'constant-case'; import { NameIcon, H3, P, FormGroup, FormLabel, Input, FormMeta, Button, Toggle, Card, CardOutlet, Divider, Row, Col, TagList } from 'joyent-ui-toolkit'; import Tag from '@components/instances/tags'; import Title from './title'; 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:{' '} {constantCase(action)} ); }; export default ({ defaultRules = [], tagRules = [], enabled = false, handleSubmit }) => (
Enable firewall rules {enabled ? ( Show inactive rules ) : null} {enabled && defaultRules.length ? (

Default firewall rules

{/* trick H3 margin sibling rule */} {defaultRules.map(rule => ( ))}
) : null} {enabled && tagRules.length && defaultRules.length ? ( ) : null} {enabled && tagRules.length ? (

Firewall rules from instance tags

{/* trick H3 margin sibling rule */} {tagRules.map(rule => ( ))}
) : null} {enabled && (tagRules.length || defaultRules.length) ? ( ) : null} );