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 is from 'styled-is'; import { H3, FormGroup, FormLabel, Toggle, Divider, Row, Col, TagList, P } from 'joyent-ui-toolkit'; import Tag from '@components/tags'; import Empty from '@components/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%; ${is('disabled')` color: ${props => props.theme.greyDark} `}; `; 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 const Rules = ({ rules = [] }) => ( {rules.map(rule => ( ))} ); export const DefaultRules = ({ rules = [] }) => (

Default firewall rules

); export const TagRules = ({ rules = [] }) => (

Firewall rules from instance tags

); export const ToggleFirewallForm = ({ handleSubmit, submitting }) => (
setTimeout(() => handleSubmit(...args), 16)}> Enable Firewall
); export const ToggleInactiveForm = () => (
Show inactive rules
); export default ({ defaultRules = [], tagRules = [], enabled = false, handleSubmit }) => (
Enable firewall rules {enabled ? ( Show inactive rules ) : null} {enabled ? : null} {enabled && !tagRules.length && !defaultRules.length ? ( Sorry, but we weren’t able to find any firewall rules. ) : null} {enabled && tagRules.length && defaultRules.length ? ( ) : null} {enabled && tagRules.length ? : 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} );