2018-01-12 17:25:26 +02:00
|
|
|
import React, { Fragment } from 'react';
|
2018-02-26 17:54:25 +02:00
|
|
|
import styled from 'styled-components';
|
2018-01-12 17:25:26 +02:00
|
|
|
import { Margin } from 'styled-components-spacing';
|
|
|
|
import Flex from 'styled-flex-component';
|
|
|
|
import { Field } from 'redux-form';
|
|
|
|
import titleCase from 'title-case';
|
2018-01-25 19:07:20 +02:00
|
|
|
import remcalc from 'remcalc';
|
2018-01-12 17:25:26 +02:00
|
|
|
|
2018-02-23 19:57:13 +02:00
|
|
|
import { H5, Select, Input, FormGroup, FormMeta } from 'joyent-ui-toolkit';
|
2018-01-12 17:25:26 +02:00
|
|
|
|
2018-02-01 17:33:58 +02:00
|
|
|
const style = {
|
2018-03-01 03:15:16 +02:00
|
|
|
lineHeight: remcalc(48),
|
|
|
|
fontSize: remcalc(18)
|
2018-02-01 17:33:58 +02:00
|
|
|
};
|
|
|
|
|
2018-02-26 17:54:25 +02:00
|
|
|
const Bold = styled.span`
|
|
|
|
font-weight: ${props => props.theme.font.weight.semibold};
|
|
|
|
`;
|
|
|
|
|
2018-01-16 13:23:00 +02:00
|
|
|
const Values = touched => (
|
2018-01-12 17:25:26 +02:00
|
|
|
<Margin right={1}>
|
2018-03-01 03:15:16 +02:00
|
|
|
<Select style={style} touched={touched} width={remcalc(130)} embedded>
|
2018-01-12 17:25:26 +02:00
|
|
|
<option value="equalling">equalling</option>
|
2018-01-12 19:40:23 +02:00
|
|
|
<option value="not-equalling">not equalling</option>
|
2018-01-12 17:25:26 +02:00
|
|
|
<option value="containing">containing</option>
|
|
|
|
<option value="starting">starting with</option>
|
|
|
|
<option value="ending">ending with</option>
|
|
|
|
</Select>
|
|
|
|
</Margin>
|
|
|
|
);
|
|
|
|
|
2018-03-01 03:15:16 +02:00
|
|
|
export const Rule = ({ valid, ...rule }) => (
|
|
|
|
<Margin bottom={valid ? 4 : 8}>
|
2018-01-12 17:25:26 +02:00
|
|
|
<Flex alignCenter wrap>
|
2018-02-01 17:33:58 +02:00
|
|
|
<H5 style={style} inline noMargin>
|
2018-01-12 17:25:26 +02:00
|
|
|
The instance
|
|
|
|
</H5>
|
2018-03-01 03:15:16 +02:00
|
|
|
<FormGroup name="conditional" field={Field}>
|
2018-01-25 19:15:07 +02:00
|
|
|
<Select
|
2018-02-01 17:33:58 +02:00
|
|
|
style={style}
|
2018-03-01 03:15:16 +02:00
|
|
|
touched={rule.conditional}
|
2018-01-25 19:15:07 +02:00
|
|
|
width={remcalc(66)}
|
|
|
|
embedded
|
|
|
|
>
|
2018-01-12 17:25:26 +02:00
|
|
|
<option value="should">should</option>
|
2018-02-22 01:02:44 +02:00
|
|
|
<option value="must">must</option>
|
2018-01-12 17:25:26 +02:00
|
|
|
</Select>
|
|
|
|
</FormGroup>
|
2018-02-01 17:33:58 +02:00
|
|
|
<H5 style={style} inline noMargin>
|
2018-01-12 17:25:26 +02:00
|
|
|
be on
|
|
|
|
</H5>
|
2018-03-01 03:15:16 +02:00
|
|
|
<FormGroup name="placement" field={Field}>
|
2018-01-25 19:15:07 +02:00
|
|
|
<Select
|
2018-02-01 17:33:58 +02:00
|
|
|
style={style}
|
2018-03-01 03:15:16 +02:00
|
|
|
touched={rule.placement}
|
2018-02-22 01:02:44 +02:00
|
|
|
width={remcalc(100)}
|
2018-01-25 19:15:07 +02:00
|
|
|
embedded
|
|
|
|
>
|
2018-01-12 17:25:26 +02:00
|
|
|
<option value="same">the same</option>
|
|
|
|
<option value="different">a different</option>
|
|
|
|
</Select>
|
|
|
|
</FormGroup>
|
2018-02-01 17:33:58 +02:00
|
|
|
<H5 style={style} inline noMargin>
|
2018-01-12 17:25:26 +02:00
|
|
|
node as the instance(s) identified by the
|
|
|
|
</H5>
|
2018-03-01 03:15:16 +02:00
|
|
|
<FormGroup name="type" field={Field}>
|
2018-02-01 17:33:58 +02:00
|
|
|
<Select
|
|
|
|
style={style}
|
2018-03-01 03:15:16 +02:00
|
|
|
touched={rule.type}
|
2018-02-22 01:02:44 +02:00
|
|
|
width={remcalc(135)}
|
2018-02-01 17:33:58 +02:00
|
|
|
embedded
|
|
|
|
left
|
|
|
|
>
|
2018-01-12 17:25:26 +02:00
|
|
|
<option value="name">instance name</option>
|
|
|
|
<option value="tag">tag</option>
|
|
|
|
</Select>
|
|
|
|
</FormGroup>
|
2018-03-01 03:15:16 +02:00
|
|
|
{rule.type === 'tag' ? (
|
2018-01-12 17:25:26 +02:00
|
|
|
<Fragment>
|
2018-03-01 03:15:16 +02:00
|
|
|
<FormGroup name="key" field={Field}>
|
2018-01-18 13:16:56 +02:00
|
|
|
<Input
|
2018-02-01 17:33:58 +02:00
|
|
|
style={style}
|
2018-01-18 13:16:56 +02:00
|
|
|
onBlur={null}
|
2018-03-01 03:15:16 +02:00
|
|
|
type="text"
|
|
|
|
placeholder="key"
|
2018-01-18 13:16:56 +02:00
|
|
|
small
|
|
|
|
embedded
|
|
|
|
required
|
|
|
|
/>
|
2018-03-01 03:15:16 +02:00
|
|
|
<FormMeta small absolute />
|
2018-01-12 17:25:26 +02:00
|
|
|
</FormGroup>
|
2018-02-01 17:33:58 +02:00
|
|
|
<H5 style={style} inline noMargin>
|
2018-01-12 17:25:26 +02:00
|
|
|
and value{' '}
|
|
|
|
</H5>
|
2018-03-01 03:15:16 +02:00
|
|
|
<FormGroup name="pattern" field={Field}>
|
|
|
|
{Values(rule.pattern)}
|
2018-01-12 17:25:26 +02:00
|
|
|
</FormGroup>
|
2018-03-01 03:15:16 +02:00
|
|
|
<FormGroup name="value" field={Field}>
|
2018-01-18 13:16:56 +02:00
|
|
|
<Input
|
2018-02-01 17:33:58 +02:00
|
|
|
style={style}
|
2018-01-18 13:16:56 +02:00
|
|
|
onBlur={null}
|
|
|
|
type="text"
|
|
|
|
placeholder="value"
|
2018-03-01 03:15:16 +02:00
|
|
|
embedded
|
|
|
|
required
|
2018-01-18 13:16:56 +02:00
|
|
|
/>
|
2018-03-01 03:15:16 +02:00
|
|
|
<FormMeta small absolute />
|
2018-01-12 17:25:26 +02:00
|
|
|
</FormGroup>
|
|
|
|
</Fragment>
|
|
|
|
) : (
|
|
|
|
<Fragment>
|
2018-03-01 03:15:16 +02:00
|
|
|
<FormGroup name="pattern" field={Field}>
|
|
|
|
{Values(rule.pattern)}
|
2018-01-12 17:25:26 +02:00
|
|
|
</FormGroup>
|
2018-03-01 03:15:16 +02:00
|
|
|
<FormGroup name="value" field={Field}>
|
2018-01-12 17:25:26 +02:00
|
|
|
<Input
|
2018-01-18 13:16:56 +02:00
|
|
|
onBlur={null}
|
2018-02-01 17:33:58 +02:00
|
|
|
style={style}
|
2018-01-12 17:25:26 +02:00
|
|
|
type="text"
|
|
|
|
placeholder="Example instance name: nginx"
|
2018-03-01 03:15:16 +02:00
|
|
|
embedded
|
|
|
|
required
|
2018-01-12 17:25:26 +02:00
|
|
|
/>
|
2018-03-01 03:15:16 +02:00
|
|
|
<FormMeta absolute />
|
2018-01-12 17:25:26 +02:00
|
|
|
</FormGroup>
|
|
|
|
</Fragment>
|
|
|
|
)}
|
|
|
|
</Flex>
|
|
|
|
</Margin>
|
|
|
|
);
|
|
|
|
|
|
|
|
export const Header = rule => (
|
|
|
|
<Fragment>
|
2018-03-01 03:15:16 +02:00
|
|
|
<Bold>{titleCase(rule.conditional)}:</Bold> be on a {rule.placement} node as
|
|
|
|
the instance(s) identified by the instance {rule.type}
|
|
|
|
{rule.type === 'name' ? (
|
2018-01-12 17:25:26 +02:00
|
|
|
<Fragment>
|
|
|
|
{' '}
|
2018-03-01 03:15:16 +02:00
|
|
|
{rule.pattern} “{rule.value}”
|
2018-01-12 17:25:26 +02:00
|
|
|
</Fragment>
|
|
|
|
) : (
|
|
|
|
<Fragment>
|
|
|
|
{' '}
|
2018-03-01 03:15:16 +02:00
|
|
|
key “{rule.key}" and the instance tag value{' '}
|
|
|
|
{rule.pattern && rule.pattern.split('-').join(' ')} "{rule.value}”
|
2018-01-12 17:25:26 +02:00
|
|
|
</Fragment>
|
|
|
|
)}
|
|
|
|
</Fragment>
|
|
|
|
);
|