style: lint and format

This commit is contained in:
Sérgio Ramos 2017-09-27 15:44:57 +01:00 committed by Sérgio Ramos
parent 09ef1cacde
commit b64f345e13
37 changed files with 203 additions and 144 deletions

View File

@ -4,13 +4,7 @@ const url = require('url');
const request = require('./request');
const {
_path,
_getAuthHeaders,
account,
url: host
} = request.client;
const { _path, _getAuthHeaders, account, url: host } = request.client;
const client = request.client;
const getAuthHeaders = awaitify(_getAuthHeaders.bind(client));
@ -36,12 +30,13 @@ const metadata = {
const href = url.format({
protocol: 'https',
host: host.replace(/^https\:\/\//, ''),
host: host.replace(/^https:\/\//, ''),
pathname
});
return fetch(href, { method: 'GET', headers })
.then((response) => response.json());
return fetch(href, { method: 'GET', headers }).then(response =>
response.json()
);
},
get: ctx => {
return request('getMachineMetadata', ctx);

View File

@ -1,7 +1,7 @@
// const argv = require('minimist')(process.argv.slice(2));
// const { makeExecutableSchema, addMockFunctionsToSchema } = require('graphql-tools');
const { query, mutation } = require('./schema');
// const { query, mutation } = require('./schema');
// console.log(new GraphQLSchema({
// query,

View File

@ -49,7 +49,7 @@ module.exports = new GraphQLObjectType({
}
},
rule: {
type: GraphQLString, //FirewallRuleSyntaxType,
type: GraphQLString, // FirewallRuleSyntaxType,
description: 'Firewall rule',
resolve: ({ rule }) => {
return rule;

View File

@ -5,6 +5,7 @@ import remcalc from 'remcalc';
import { H1, P, Button, ViewContainer } from 'joyent-ui-toolkit';
const StyledContainer = styled.div`
/* trick prettier */
margin-top: ${remcalc(60)};
`;

View File

@ -1,5 +1,4 @@
import React from 'react';
import forceArray from 'force-array';
import {
Card,
@ -9,12 +8,18 @@ import {
CardView
} from 'joyent-ui-toolkit';
export default ({ rule = '', global = false, enabled = false, first, last }) => (
export default ({
rule = '',
global = false,
enabled = false,
first,
last
}) => (
<Card collapsed flat={!last} topMargin={first} bottomless={!last} gapless>
<CardView>
<CardMeta>
<CardTitle>{rule}</CardTitle>
<CardLabel icon={global && String.fromCodePoint(0x1F30D)} />
<CardLabel icon={global && String.fromCodePoint(0x1f30d)} />
<CardLabel color={enabled ? 'green' : 'red'} />
</CardMeta>
</CardView>

View File

@ -41,17 +41,21 @@ export default ({ name, state, primaryIp, last, first }) => (
</CardAction>
<CardTitle to={`/instances/${name}`}>{name}</CardTitle>
<Small>
<CardLabel>
{primaryIp}
</CardLabel>
<CardLabel>{primaryIp}</CardLabel>
</Small>
<Small>
<CardLabel color={stateColor[state]} title={`The instance is ${state}`}>
<CardLabel
color={stateColor[state]}
title={`The instance is ${state}`}
>
{titleCase(state)}
</CardLabel>
</Small>
<SmallOnly>
<CardLabel color={stateColor[state]} title={`The instance is ${state}`} />
<CardLabel
color={stateColor[state]}
title={`The instance is ${state}`}
/>
</SmallOnly>
</CardMeta>
</CardView>

View File

@ -14,7 +14,14 @@ import {
const { SmallOnly, Small } = QueryBreakpoints;
const TextareaKeyValue = ({ name, formName, formValue, handleSubmit, onRemove, textarea }) => (
const TextareaKeyValue = ({
name,
formName,
formValue,
handleSubmit,
onRemove,
textarea
}) => (
<form onSubmit={handleSubmit}>
<Row>
<Col xs={12} sm={10}>
@ -23,7 +30,14 @@ const TextareaKeyValue = ({ name, formName, formValue, handleSubmit, onRemove, t
</FormGroup>
</Col>
<Col xs={6} sm={1}>
<Button type="button" onClick={() => onRemove(name)} secondary small icon fluid>
<Button
type="button"
onClick={() => onRemove(name)}
secondary
small
icon
fluid
>
<BinIcon />
</Button>
</Col>
@ -34,7 +48,7 @@ const TextareaKeyValue = ({ name, formName, formValue, handleSubmit, onRemove, t
</Col>
<Col xs={12} sm={12}>
<FormGroup name={formValue} reduxForm>
<Field name={formValue} component={Editor} mode='sh' />
<Field name={formValue} component={Editor} mode="sh" />
</FormGroup>
</Col>
<SmallOnly>
@ -47,7 +61,14 @@ const TextareaKeyValue = ({ name, formName, formValue, handleSubmit, onRemove, t
</form>
);
const InputKeyValue = ({ name, formName, formValue, handleSubmit, onRemove, textarea }) => (
const InputKeyValue = ({
name,
formName,
formValue,
handleSubmit,
onRemove,
textarea
}) => (
<form onSubmit={handleSubmit}>
<Row>
<Col xs={12} sm={5}>
@ -61,7 +82,14 @@ const InputKeyValue = ({ name, formName, formValue, handleSubmit, onRemove, text
</FormGroup>
</Col>
<Col xs={6} sm={1}>
<Button type="button" onClick={() => onRemove(name)} secondary small icon fluid>
<Button
type="button"
onClick={() => onRemove(name)}
secondary
small
icon
fluid
>
<BinIcon />
</Button>
</Col>
@ -77,6 +105,5 @@ const InputKeyValue = ({ name, formName, formValue, handleSubmit, onRemove, text
</form>
);
export default ({ textarea, ...rest }) => textarea
? <TextareaKeyValue {...rest} />
: <InputKeyValue {...rest} />;
export default ({ textarea, ...rest }) =>
textarea ? <TextareaKeyValue {...rest} /> : <InputKeyValue {...rest} />;

View File

@ -1,10 +1,22 @@
import React from 'react';
import forceArray from 'force-array';
import { FormGroup, Input, FormLabel, ViewContainer, StatusLoader } from 'joyent-ui-toolkit';
import {
FormGroup,
Input,
FormLabel,
ViewContainer,
StatusLoader
} from 'joyent-ui-toolkit';
import Item from './item';
export default ({ instances, loading, handleChange = () => null, handleSubmit }) => {
export default ({
instances,
loading,
handleChange = () => null,
handleSubmit
}) => {
const _instances = forceArray(instances);
const items = _instances.map((instance, i, all) => (
@ -16,11 +28,12 @@ export default ({ instances, loading, handleChange = () => null, handleSubmit })
/>
));
const _loading = (!items.length && loading) ? (
<ViewContainer center>
<StatusLoader />
</ViewContainer>
) : null;
const _loading =
!items.length && loading ? (
<ViewContainer center>
<StatusLoader />
</ViewContainer>
) : null;
return (
<form onSubmit={() => handleSubmit(ctx => handleChange(ctx))}>

View File

@ -1,5 +1,4 @@
import React from 'react';
import ReactJson from 'react-json-view';
import PropTypes from 'prop-types';
import forceArray from 'force-array';
import { compose, graphql } from 'react-apollo';
@ -11,7 +10,6 @@ import { ViewContainer, Title, StatusLoader, Message } from 'joyent-ui-toolkit';
import GetFirewallRules from '@graphql/list-firewall-rules.gql';
import { FirewallRule as InstanceFirewallRule } from '@components/instances';
const Firewall = ({
firewallEnabled = false,
firewallRules = [],
@ -20,18 +18,18 @@ const Firewall = ({
}) => {
const values = forceArray(firewallRules);
const _title = <Title>Firewall</Title>;
const _loading = !(loading && !values.length) ? null : (
<StatusLoader />
);
const _loading = !(loading && !values.length) ? null : <StatusLoader />;
const _firewall = !_loading && values.map((rule, i, all) => (
<InstanceFirewallRule
key={rule.id}
{...rule}
last={all.length - 1 === i}
first={!i}
/>
));
const _firewall =
!_loading &&
values.map((rule, i, all) => (
<InstanceFirewallRule
key={rule.id}
{...rule}
last={all.length - 1 === i}
first={!i}
/>
));
const _error = !(error && !_loading) ? null : (
<Message

View File

@ -7,7 +7,7 @@ import forceArray from 'force-array';
import get from 'lodash.get';
import find from 'lodash.find';
import { ViewContainer, Title, StatusLoader, Message } from 'joyent-ui-toolkit';
import { ViewContainer, Title, Message } from 'joyent-ui-toolkit';
import GetInstances from '@graphql/list-instances.gql';
import { List as InstanceList } from '@components/instances';
@ -20,7 +20,7 @@ const InstanceListForm = reduxForm({
const List = ({ instances = [], loading = false, error }) => {
const _title = <Title>Instances</Title>;
const _instances = forceArray(instances);
const _loading = (!instances.length && loading);
const _loading = !instances.length && loading;
const _error = !error ? null : (
<Message

View File

@ -12,27 +12,28 @@ import { ViewContainer, Title, StatusLoader, Message } from 'joyent-ui-toolkit';
import GetMetadata from '@graphql/list-metadata.gql';
import { KeyValue } from '@components/instances';
const MetadataForms = (metadata = []) => metadata.map(({ key, formName, formValue, value, name }) => {
const MetadataForm = reduxForm({
form: `instance-metadata-${key}`,
initialValues: {
[formName]: name,
[formValue]: value
}
})(KeyValue);
const MetadataForms = (metadata = []) =>
metadata.map(({ key, formName, formValue, value, name }) => {
const MetadataForm = reduxForm({
form: `instance-metadata-${key}`,
initialValues: {
[formName]: name,
[formValue]: value
}
})(KeyValue);
return (
<MetadataForm
key={key}
formName={formName}
formValue={formValue}
name={key}
onSubmit={val => console.log(key, val)}
onRemove={key => console.log('remove', key)}
textarea
/>
);
});
return (
<MetadataForm
key={key}
formName={formName}
formValue={formValue}
name={key}
onSubmit={val => console.log(key, val)}
onRemove={key => console.log('remove', key)}
textarea
/>
);
});
const Metadata = ({ metadata = [], loading, error }) => {
const _title = <Title>Metadata</Title>;
@ -79,7 +80,6 @@ export default compose(
[]
);
const metadata = Object.keys(values).reduce((all, name) => {
const key = paramCase(name);

View File

@ -10,22 +10,21 @@ import { ViewContainer, Title, StatusLoader, Message } from 'joyent-ui-toolkit';
import GetNetworks from '@graphql/list-networks.gql';
import { Network as InstanceNetwork } from '@components/instances';
const Networks = ({ networks = [], loading, error }) => {
const values = forceArray(networks);
const _title = <Title>Networks</Title>;
const _loading = !(loading && !values.length) ? null : (
<StatusLoader />
);
const _loading = !(loading && !values.length) ? null : <StatusLoader />;
const _networks = !_loading && values.map((network, i, all) => (
<InstanceNetwork
key={network.id}
{...network}
last={all.length - 1 === i}
first={!i}
/>
));
const _networks =
!_loading &&
values.map((network, i, all) => (
<InstanceNetwork
key={network.id}
{...network}
last={all.length - 1 === i}
first={!i}
/>
));
const _error = !(error && !_loading) ? null : (
<Message

View File

@ -13,26 +13,27 @@ import { KeyValue } from '@components/instances';
import GetTags from '@graphql/list-tags.gql';
import PutTags from '@graphql/add-tags.gql';
const TagForms = (tags = []) => tags.map(({ key, formName, formValue, value, name }) => {
const TagForm = reduxForm({
form: `instance-tags-${key}`,
initialValues: {
[formName]: name,
[formValue]: value
}
})(KeyValue);
const TagForms = (tags = []) =>
tags.map(({ key, formName, formValue, value, name }) => {
const TagForm = reduxForm({
form: `instance-tags-${key}`,
initialValues: {
[formName]: name,
[formValue]: value
}
})(KeyValue);
return (
<TagForm
key={key}
formName={formName}
formValue={formValue}
name={key}
onSubmit={val => console.log(key, val)}
onRemove={key => console.log('remove', key)}
/>
);
});
return (
<TagForm
key={key}
formName={formName}
formValue={formValue}
name={key}
onSubmit={val => console.log(key, val)}
onRemove={key => console.log('remove', key)}
/>
);
});
const Tags = ({ tags = [], loading, error }) => {
const _title = <Title>Tags</Title>;
@ -79,7 +80,6 @@ export default compose(
[]
);
const tags = Object.keys(values).reduce((all, name) => {
const key = paramCase(name);

View File

@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { ThemeProvider, injectGlobal } from 'styled-components';
import React from 'react';
import { ThemeProvider } from 'styled-components';
import { theme, RootContainer } from 'joyent-ui-toolkit';
import { ApolloProvider } from 'react-apollo';

View File

@ -1,6 +1,5 @@
import React from 'react';
import { BrowserRouter, Route, Switch } from 'react-router-dom';
import styled from 'styled-components';
import { PageContainer } from 'joyent-ui-toolkit';

View File

@ -105,4 +105,4 @@ export function unregister() {
registration.unregister();
});
}
}
}

View File

@ -24,7 +24,9 @@ export default ({ theme }) => css`
${unloadedFontFamily};
}
html, body, #root {
html,
body,
#root {
height: 100%;
}
@ -32,7 +34,8 @@ export default ({ theme }) => css`
${loadedFontFamily};
}
.CodeMirror, .ReactCodeMirror {
.CodeMirror,
.ReactCodeMirror {
height: 100% !important;
}

View File

@ -7,10 +7,9 @@ const sides = ['top', 'right', 'bottom', 'left'];
const unitProps = (() => {
const sided = rule => sides.map(side => `${rule}-${side}`);
const measures = ['margin', 'padding'].reduce(
(props, rule) => [...props, rule, ...sided(rule)],
[]
).concat(['height', 'width']);
const measures = ['margin', 'padding']
.reduce((props, rule) => [...props, rule, ...sided(rule)], [])
.concat(['height', 'width']);
return sides.reduce((acc, side) => [...acc, `border-${side}-width`], [
'border',

View File

@ -33,6 +33,7 @@ const Arrow = styled.div`
`;
const Container = styled.div`
/* trick prettier */
display: inline-block;
`;

View File

@ -49,17 +49,21 @@ const breakpoint = label => (...args) => css`
`;
const toQuery = label => ({ children, ...rest }) => (
<MediaQuery query={screens[label]}>
{children}
</MediaQuery>
<MediaQuery query={screens[label]}>{children}</MediaQuery>
);
export const styled = Object.keys(screens).reduce((sum, label) => ({
...sum,
[label]: breakpoint(label)
}), {});
export const styled = Object.keys(screens).reduce(
(sum, label) => ({
...sum,
[label]: breakpoint(label)
}),
{}
);
export const query = Object.keys(screens).reduce((sum, label) => ({
...sum,
[pascalCase(label)]: toQuery(label)
}), {});
export const query = Object.keys(screens).reduce(
(sum, label) => ({
...sum,
[pascalCase(label)]: toQuery(label)
}),
{}
);

View File

@ -89,7 +89,7 @@ const style = css`
background-color: ${props => props.theme.whiteActive};
border-color: ${props => props.theme.grey};
}
`}
`};
${is('tertiary')`
color: ${props => props.theme.tertiary};
@ -106,7 +106,7 @@ const style = css`
background-color: ${props => props.theme.background};
border-color: ${props => props.theme.grey};
}
`}
`};
${is('tertiary', 'selected')`
background-color: ${props => props.theme.tertiaryActive};
@ -145,7 +145,7 @@ const style = css`
background-color: ${props => props.theme.disabled};
border-color: ${props => props.theme.disabled};
}
`}
`};
${is('rect')`
border-radius: 0;

View File

@ -2,7 +2,6 @@ import React from 'react';
import remcalc from 'remcalc';
import styled from 'styled-components';
import is, { isNot } from 'styled-is';
import unitcalc from 'unitcalc';
const Dot = styled.span`
width: ${remcalc(6)};
@ -20,6 +19,7 @@ const Dot = styled.span`
`;
const Icon = styled.span`
/* trick prettier */
background-color: none;
`;

View File

@ -1,5 +1,4 @@
import is from 'styled-is';
import typography from '../typography';
import P from '../text/p';
export default P.extend`

View File

@ -5,7 +5,6 @@ import is from 'styled-is';
import Baseline from '../baseline';
const Divider = styled(Row)`
background-color: ${props => props.theme.grey};

View File

@ -2,7 +2,6 @@ import React from 'react';
import styled from 'styled-components';
import { Input } from 'normalized-styled-components';
import { Broadcast, Subscriber } from 'react-broadcast';
import { border, borderRadius } from '../../boxes';
import BaseInput from './input';
import remcalc from 'remcalc';
import is from 'styled-is';

View File

@ -3,6 +3,7 @@ import Baseline from '../baseline';
import typography from '../typography';
const StyledLegend = Legend.extend`
/* trick prettier */
${typography.semibold};
`;

View File

@ -9,6 +9,7 @@ import unitcalc from 'unitcalc';
import { PlusIcon, MinusIcon } from '../icons';
const StyledContainer = styled.div`
/* trick prettier */
margin-bottom: ${unitcalc(4)};
`;

View File

@ -89,7 +89,8 @@ const style = css`
`;
const StyledButton = NButton.extend`
${style}
/* trick prettier */
${style};
`;
const StyledAnchor = A.extend`

View File

@ -1,4 +1,4 @@
import is, { isNot } from 'styled-is';
import is from 'styled-is';
import { Grid } from 'react-styled-flexboxgrid';
import remcalc from 'remcalc';

View File

@ -54,24 +54,24 @@ const StyledContainer = styled.div`
${isOr('active', 'completed')`
border-top: ${remcalc(1)} solid ${props => props.theme.greenDark};
border-bottom: ${remcalc(1)} solid ${props => props.theme.greenDark};
`}
`};
${is('first')`
border-left: ${remcalc(1)} solid ${props => props.theme.greenDark};
padding-left: ${remcalc(13)};
`}
`};
${isNot('first', 'completed', 'active')`
border-right: ${remcalc(1)} solid ${props => props.theme.grey};
`}
`};
${isOr('active', 'completed')`
border-right: ${remcalc(1)} solid ${props => props.theme.greenDark};
`}
`};
${isNot('last')`
border-right: none;
`}
`};
`;
const StyledArrow = styled.span`

View File

@ -10,11 +10,11 @@ const Tick = styled(TickIcon)`
${is('active')`
fill: ${props => props.theme.secondary};
`}
`};
${is('completed')`
fill: ${props => props.theme.white};
`}
`};
`;
const StyledIndicator = styled.span`
@ -30,11 +30,11 @@ const StyledIndicator = styled.span`
${isOr('completed', 'active')`
border: ${remcalc(1)} solid ${props => props.theme.greenDark};
`}
`};
${is('completed')`
background: ${props => props.theme.green};
`}
`};
`;
const Indicator = ({ first, completed, active, last, ...rest }) => {

View File

@ -34,13 +34,16 @@ const style = css`
`;
export const Anchor = Baseline(A.extend`
/* trick prettier */
${style};
`);
export const NavLink = Baseline(styled(RRNavLink)`
/* trick prettier */
${style};
`);
export const Link = Baseline(styled(RRLink)`
/* trick prettier */
${style};
`);

View File

@ -60,7 +60,7 @@ Slider.propTypes = {
draggableTrack: PropTypes.bool,
onChangeStart: PropTypes.func,
children: PropTypes.node,
greyed: PropTypes.bool,
greyed: PropTypes.bool
};
Slider.defaultProps = {

View File

@ -32,10 +32,12 @@ const StyledFirstRect = styled.rect`
`;
const StyledSecondRect = StyledFirstRect.extend`
/* trick prettier */
animation-delay: 0.5s;
`;
const StyledThirdRect = StyledFirstRect.extend`
/* trick prettier */
animation-delay: 1s;
`;

View File

@ -4,6 +4,7 @@ import theme from '../theme';
import Base, { global } from '../base';
const StyledBase = Base.extend`
/* trick prettier */
background-color: transparent;
`;

View File

@ -32,6 +32,7 @@ const Preview = styled.div`
`;
const Paragraph = P.extend`
/* trick prettier */
margin: 0;
`;

View File

@ -1,5 +1,5 @@
import { css } from 'styled-components';
import theme from '../theme'
import theme from '../theme';
const baseFonts = `
-apple-system,
@ -18,20 +18,24 @@ export const loadedFontFamily = css`
`;
export const unloadedFontFamily = css`
/* trick prettier */
font-family: ${baseFonts};
`;
export const color = theme.text;
export const semibold = css`
/* trick prettier */
font-weight: 600;
`;
export const medium = css`
/* trick prettier */
font-weight: 500;
`;
export const normal = css`
/* trick prettier */
font-weight: 400;
`;