fix missing ids

This commit is contained in:
Sérgio Ramos 2018-03-21 16:38:50 +00:00
parent 1bd682a403
commit e2db11e29a
40 changed files with 173 additions and 223 deletions

View File

@ -17,7 +17,7 @@
},
"dependencies": {
"brule": "^3.1.0",
"cloudapi-gql": "^7.1.1",
"cloudapi-gql": "^7.1.3",
"hapi": "^17.2.0",
"hapi-triton-auth": "^2.0.0",
"inert": "^5.1.0",

View File

@ -1,10 +1,10 @@
import React, { Fragment } from 'react';
import { Link } from 'react-router-dom';
import styled from 'styled-components';
import remcalc from 'remcalc';
import { Field } from 'redux-form';
import Flex from 'styled-flex-component';
import { Padding, Margin } from 'styled-components-spacing';
import remcalc from 'remcalc';
import {
Card,
@ -50,7 +50,7 @@ const Type = styled(Margin)`
`;
const Content = styled(Padding)`
max-width: calc(100% - 48px);
max-width: calc(100% - ${remcalc(48)});
overflow: hidden;
`;
@ -64,14 +64,14 @@ const DividerContainer = styled(Margin)`
`;
const Actions = styled(Flex)`
width: 48px;
height: 48px;
min-width: 48px;
width: ${remcalc(48)};
height: ${remcalc(48)};
min-width: ${remcalc(48)};
`;
const ActionsWrapper = styled(Flex)`
height: 100%;
border-left: 1px solid ${props => props.theme.grey};
border-left: ${remcalc(1)} solid ${props => props.theme.grey};
`;
export const Image = ({
@ -85,7 +85,7 @@ export const Image = ({
onCreateInstance
}) => (
<Margin bottom={3}>
<CardAnchor to={`/images/${name}`} component={Link}>
<CardAnchor to={`/images/${id}`} component={Link}>
<Card radius>
{removing ? (
<Padding all={2}>

View File

@ -117,7 +117,7 @@ export default withTheme(({ theme = {}, onRemove, removing, ...image }) => (
<Button
type="button"
href={`${GLOBAL.origin}/instances/~create/?image=${
image.name
image.id
}`}
target="__blank"
rel="noopener noreferrer"

View File

@ -97,20 +97,15 @@ export default compose(
options: ({ match }) => ({
ssr: false,
variables: {
name: get(match, 'params.instance')
id: get(match, 'params.instance')
}
}),
props: ({ data: { loading, error, variables, ...rest } }) => {
props: ({ data: { loading, error, machine, variables, ...rest } }) => {
const notFoundMsg = `Instance "${variables.name}" not found!`;
const inst = find(get(rest, 'machines.results', []), [
'name',
variables.name
]);
const notFound = !loading && !inst ? notFoundMsg : false;
const notFound = !loading && !machine ? notFoundMsg : false;
return {
instance: inst,
instance: machine,
loadingError: error ? parseError(error) : notFound,
loading
};
@ -190,7 +185,7 @@ export default compose(
const { data } = res;
const { createImageFromMachine } = data;
history.push(`/images/${createImageFromMachine.name}`);
history.push(`/images/${createImageFromMachine.id}`);
}
};
})

View File

@ -9,12 +9,12 @@ const SECTIONS = [
];
export default ({ match }) => {
const imageSlug = get(match, 'params.image');
const sections = imageSlug !== '~create' ? SECTIONS : [];
const imageId = get(match, 'params.image');
const sections = imageId !== '~create' ? SECTIONS : [];
const links = sections.map(({ name, pathname }) => ({
name,
pathname: `/images/${imageSlug}/${pathname}`
pathname: `/images/${imageId}/${pathname}`
}));
return <Menu links={links} />;

View File

@ -72,13 +72,14 @@ export default compose(
id: get(match, 'params.image')
}
}),
props: ({
data: { loading = false, error = null, variables, ...rest }
}) => ({
image: find(get(rest, 'images', []), ['id', variables.id]),
loading,
error
})
props: ({ data }) => {
const { loading = false, error = null, image } = data;
return {
image,
loading,
error
};
}
}),
connect(
({ values }, ownProps) => {

View File

@ -133,15 +133,8 @@ export default compose(
}
}),
props: ({ data }) => {
const {
loading = false,
error = null,
variables,
refetch,
...rest
} = data;
const { loading = false, error = null, image, refetch, ...rest } = data;
const image = find(get(rest, 'images', []), ['id', variables.id]);
const tags = get(image || {}, 'tags', []);
const index = new Fuse(tags, {
keys: ['name', 'value']
@ -203,34 +196,33 @@ export default compose(
dispatch(set({ name: `${image.id}-mutating`, value: false }));
},
handleAddTag: async ({ name, value }) => {
console.log(name, value);
dispatch(set({ name: `${image.id}-mutating`, value: true }));
// const [err] = await intercept(
// updateTags({
// variables: {
// id: image.id,
// tags: tags
// .map(({ name, value }) => ({ name, value }))
// .concat([{ name, value }])
// }
// })
// );
const [err] = await intercept(
updateTags({
variables: {
id: image.id,
tags: tags
.map(({ name, value }) => ({ name, value }))
.concat([{ name, value }])
}
})
);
// if (err) {
// dispatch([
// set({ name: `${image.id}-mutation-error`, value: parseError(err) }),
// set({ name: `${image.id}-mutating`, value: false })
// ]);
// }
if (err) {
dispatch([
set({ name: `${image.id}-mutation-error`, value: parseError(err) }),
set({ name: `${image.id}-mutating`, value: false })
]);
}
// await refetch();
await refetch();
// dispatch([
// set({ name: `${image.id}-mutating`, value: false }),
// dispatch(set({ name: `${image.id}-add-open`, value: false })),
// destroy(TAGS_ADD_FORM)
// ]);
dispatch([
set({ name: `${image.id}-mutating`, value: false }),
dispatch(set({ name: `${image.id}-add-open`, value: false })),
destroy(TAGS_ADD_FORM)
]);
}
})
)

View File

@ -1,5 +1,5 @@
query image($id: ID) {
images(id: $id) {
image(id: $id) {
id
name
os

View File

@ -1,8 +1,6 @@
query instance($id: ID) {
machines(id: $id) {
results {
id
name
}
machine(id: $id) {
id
name
}
}

View File

@ -1,5 +1,5 @@
query image($id: ID) {
images(id: $id) {
image(id: $id) {
id
name
tags {

View File

@ -3569,7 +3569,7 @@ exports[`renders <Summary instance /> without throwing 1`] = `
<a
className="c18 c19 c20 c21"
data-ui-button="true"
href="http://localhost/images/~create/undefined"
href="http://localhost/images/~create/2252839a-e698-ceec-afac-9549ad0c6624"
icon={true}
rel="noopener noreferrer"
target="__blank"
@ -5975,7 +5975,7 @@ exports[`renders <Summary instance /> without throwing 2`] = `
<a
className="c18 c19 c20 c21"
data-ui-button="true"
href="http://localhost/images/~create/undefined"
href="http://localhost/images/~create/2252839a-e698-ceec-afac-9549ad0c6624"
icon={true}
rel="noopener noreferrer"
target="__blank"

View File

@ -132,7 +132,7 @@ export const Item = ({
<PopoverDivider />
<PopoverItem disabled={false} onClick={onCreateImage}>
<ItemAnchor
href={`${GLOBAL.origin}/images/~create/${name}`}
href={`${GLOBAL.origin}/images/~create/${id}`}
target="__blank"
rel="noopener noreferrer"
>

View File

@ -142,7 +142,7 @@ export default withTheme(
<Row between="xs">
<Col xs={9}>
<Button
href={`${GLOBAL.origin}/images/~create/${instance.name}`}
href={`${GLOBAL.origin}/images/~create/${instance.id}`}
target="__blank"
rel="noopener noreferrer"
secondary

View File

@ -74,7 +74,7 @@ exports[`renders <Menu links /> without throwing 1`] = `
list-style-type: none;
padding: 0.8125rem 0rem;
margin: 1.125rem 0 0 0;
max-height: 50px;
max-height: 3.125rem;
overflow-x: auto;
overflow-y: hidden;
box-sizing: border-box;

View File

@ -169,9 +169,9 @@ export default compose(
})
),
graphql(GetImages, {
options: () => ({
options: ({ query }) => ({
ssr: false,
variables: { public: true }
variables: { public: !query.image }
}),
props: ({ ownProps, data }) => {
const { image = '', query } = ownProps;
@ -180,7 +180,7 @@ export default compose(
if (query.image) {
return {
loading,
image: find(images, ['name', query.image], {}),
image: find(images, ['id', query.image], {}),
hardcoded: true
};
}

View File

@ -367,7 +367,7 @@ export default compose(
}
dispatch([destroyAll(), forms.map(name => destroy(name))]);
history.push(`/instances/${res.data.createMachine.name}`);
history.push(`/instances/${res.data.createMachine.id}`);
}
};
})

View File

@ -2485,7 +2485,7 @@ exports[`renders <Summary starting stopping rebooting removing /> without throwi
<a
className="c19 c20 c21 c22"
data-ui-button="true"
href="http://localhost/images/~create/undefined"
href="http://localhost/images/~create/2252839a-e698-ceec-afac-9549ad0c6624"
icon={true}
rel="noopener noreferrer"
target="__blank"
@ -4929,7 +4929,7 @@ exports[`renders <Summary starting stopping rebooting removing /> without throwi
<a
className="c19 c20 c21 c22"
data-ui-button="true"
href="http://localhost/images/~create/undefined"
href="http://localhost/images/~create/2252839a-e698-ceec-afac-9549ad0c6624"
icon={true}
rel="noopener noreferrer"
target="__blank"

View File

@ -151,15 +151,12 @@ export default compose(
}
}),
props: ({ data }) => {
const { loading, error, variables, refetch, ...rest } = data;
const { id } = variables;
const instance = find(get(rest, 'machines.results', []), ['id', id]);
const tags = get(instance, 'tags', []);
const { loading, error, machine, refetch } = data;
const tags = get(machine, 'tags', []);
return {
tags,
instance,
instance: machine,
loading,
loadingError: error,
refetch

View File

@ -8,7 +8,6 @@ import { SubmissionError } from 'redux-form';
import { Margin } from 'styled-components-spacing';
import remcalc from 'remcalc';
import isBoolean from 'lodash.isboolean';
import find from 'lodash.find';
import get from 'lodash.get';
import {
@ -142,18 +141,16 @@ export default compose(
}
}),
props: ({ data }) => {
const { loading, error, variables, refetch, ...rest } = data;
const { id } = variables;
const { loading, error, machine } = data;
const instance = find(get(rest, 'machines.results', []), ['id', id]);
const enabled = get(instance, 'firewall_enabled');
const rules = get(instance, 'firewall_rules', []);
const enabled = get(machine, 'firewall_enabled');
const rules = get(machine, 'firewall_rules', []);
return {
enabled,
defaultRules: rules.filter(({ rule_obj = {} }) => rule_obj.isWildcard),
tagRules: rules.filter(({ rule_obj = {} }) => rule_obj.tags.length),
instance,
instance: machine,
loading,
loadingError: error
};

View File

@ -121,17 +121,15 @@ export const List = ({
total={total}
>
{fetching ? <InstanceListFetchingItem /> : null}
{(!fetching ? _instances : []).map(({ name, id, ...rest }) => (
{(!fetching ? _instances : []).map(instance => (
<InstanceListItem
key={id}
id={id}
name={name}
{...rest}
onCreateImage={() => handleCreateImage(rest)}
onStart={() => handleStart([{ id }])}
onStop={() => handleStop([{ id }])}
onReboot={() => handleReboot([{ id }])}
onRemove={() => handleRemove([{ id }])}
key={instance.id}
{...instance}
onCreateImage={() => handleCreateImage(instance)}
onStart={() => handleStart([instance])}
onStop={() => handleStop([instance])}
onReboot={() => handleReboot([instance])}
onRemove={() => handleRemove([instance])}
/>
))}
</InstanceList>
@ -299,9 +297,9 @@ export default compose(
};
},
(dispatch, { refetch, ...ownProps }) => ({
handleCreateImage: ({ name }) => {
handleCreateImage: ({ id }) => {
return window
.open(`${GLOBAL.origin}/images/~create/${name}`, '_blank')
.open(`${GLOBAL.origin}/images/~create/${id}`, '_blank')
.focus();
},
handleSortBy: ({ sortBy: currentSortBy, sortOrder }) => newSortBy => {

View File

@ -164,11 +164,8 @@ export default compose(
id: get(match, 'params.instance')
}
}),
props: ({ data: { loading, error, variables, refetch, ...rest } }) => {
const { id } = variables;
const instance = find(get(rest, 'machines.results', []), ['id', id]);
const values = get(instance, 'metadata', []).filter(
props: ({ data: { loading, error, machine, refetch, ...rest } }) => {
const values = get(machine, 'metadata', []).filter(
({ name = '' }) => name !== 'user-script'
);
@ -188,7 +185,7 @@ export default compose(
return {
index,
metadata,
instance,
instance: machine,
loading,
error,
refetch

View File

@ -174,10 +174,8 @@ export default compose(
id: get(match, 'params.instance')
}
}),
props: ({ data: { loading, error, variables, refetch, ...rest } }) => {
const { id } = variables;
const instance = find(get(rest, 'machines.results', []), ['id', id]);
const snapshots = get(instance, 'snapshots', []);
props: ({ data: { loading, error, machine, refetch, ...rest } }) => {
const snapshots = get(machine, 'snapshots', []);
const index = new Fuse(snapshots, {
keys: ['name', 'status', 'created']
@ -186,7 +184,7 @@ export default compose(
return {
index,
snapshots,
instance,
instance: machine,
loading,
error,
refetch

View File

@ -4,7 +4,6 @@ import { connect } from 'react-redux';
import { set } from 'react-redux-values';
import { Margin } from 'styled-components-spacing';
import intercept from 'apr-intercept';
import find from 'lodash.find';
import isArray from 'lodash.isarray';
import some from 'lodash.some';
import isInteger from 'lodash.isinteger';
@ -38,7 +37,6 @@ export const Summary = ({
rebooting,
removing
}) => {
console.log(instance);
const _loading = loading || !instance ? <StatusLoader /> : null;
const _summary = !_loading &&
instance && (
@ -146,14 +144,9 @@ export default compose(
id: get(match, 'params.instance')
}
}),
props: ({ data: { loading, error, variables, ...rest } }) => {
let instance = find(get(rest, 'machines.results', []), [
'id',
variables.id
]);
if (instance) {
const { ips } = instance;
props: ({ data: { loading, error, machine, ...rest } }) => {
if (machine) {
const { ips } = machine;
const grupedIps = ips
.map(ip => ({ ip, openness: isPrivate(ip) ? 'private' : 'public' }))
@ -165,11 +158,11 @@ export default compose(
{}
);
instance = Object.assign({}, instance, { ips: grupedIps });
machine = Object.assign({}, machine, { ips: grupedIps });
}
return {
instance,
instance: machine,
loading,
loadingError: error
};

View File

@ -155,11 +155,8 @@ export default compose(
id: get(match, 'params.instance')
}
}),
props: ({ data: { loading, error, variables, refetch, ...rest } }) => {
const { id } = variables;
const instance = find(get(rest, 'machines.results', []), ['id', id]);
const tags = get(instance, 'tags', []).filter(
props: ({ data: { loading, error, machine, refetch, ...rest } }) => {
const tags = get(machine, 'tags', []).filter(
({ name = '' }) => !/^triton\.cns\./i.test(name)
);
@ -169,7 +166,7 @@ export default compose(
return {
tags,
instance,
instance: machine,
index,
loading,
error,

View File

@ -1,7 +1,6 @@
import React from 'react';
import { compose, graphql } from 'react-apollo';
import { Margin } from 'styled-components-spacing';
import find from 'lodash.find';
import get from 'lodash.get';
import {
@ -61,17 +60,15 @@ export default compose(
}
}),
props: ({ data }) => {
const { loading, error, variables, refetch, ...rest } = data;
const { id } = variables;
const { loading, error, machine } = data;
const instance = find(get(rest, 'machines.results', []), ['id', id]);
const metadata = get(instance, 'metadata', [])
const metadata = get(machine, 'metadata', [])
.filter(({ name = '' }) => name === 'user-script')
.shift();
return {
metadata,
instance,
instance: machine,
loading,
error
};

View File

@ -103,7 +103,7 @@ exports[`renders <Breadcrumb /> without throwing 1`] = `
}
.c0 {
border-bottom: 1px solid rgb(216,216,216);
border-bottom: 0.0625rem solid rgb(216,216,216);
}
@media only screen and (min-width:48em) {
@ -322,7 +322,7 @@ exports[`renders <Breadcrumb match /> without throwing 1`] = `
}
.c0 {
border-bottom: 1px solid rgb(216,216,216);
border-bottom: 0.0625rem solid rgb(216,216,216);
}
@media only screen and (min-width:48em) {

View File

@ -4,13 +4,13 @@ import get from 'lodash.get';
import { Menu } from '@components/navigation';
export default connect((state, { match }) => {
const instanceSlug = get(match, 'params.instance');
const instanceId = get(match, 'params.instance');
const allSections = get(state, 'ui.sections');
const sections = instanceSlug ? allSections.instances : [];
const sections = instanceId ? allSections.instances : [];
const links = sections.map(({ name, pathname }) => ({
name,
pathname: `/instances/${instanceSlug}/${pathname}`
pathname: `/instances/${instanceId}/${pathname}`
}));
return {

View File

@ -1,25 +1,23 @@
query instance($id: ID) {
machines(id: $id) {
results {
machine(id: $id) {
id
state
brand
name
created
updated
primary_ip
ips
docker
dns_names
compute_node
image {
id
name
}
package {
id
state
brand
name
created
updated
primary_ip
ips
docker
dns_names
compute_node
image {
id
name
}
package {
id
name
}
}
}
}

View File

@ -1,17 +1,15 @@
query instance($id: ID!) {
machines(id: $id) {
results {
machine(id: $id) {
id
name
firewall_enabled
firewall_rules {
id
name
firewall_enabled
firewall_rules {
id
enabled
rule_str
rule_obj
global
description
}
enabled
rule_str
rule_obj
global
description
}
}
}

View File

@ -1,24 +1,22 @@
query instance($id: ID!) {
machines(id: $id) {
results {
machine(id: $id) {
id
name
networks {
id
name
networks {
public
fabric
description
subnet
provision_start_ip
provision_end_ip
gateway
resolvers
internet_nat
machines {
id
name
public
fabric
description
subnet
provision_start_ip
provision_end_ip
gateway
resolvers
internet_nat
machines {
id
name
}
}
}
}

View File

@ -1,13 +1,11 @@
query instance($id: ID!) {
machines(id: $id) {
results {
query metadata($id: ID!) {
machine(id: $id) {
id
name
metadata {
id
name
metadata {
id
name
value
}
value
}
}
}

View File

@ -1,15 +1,13 @@
query instance($id: ID!) {
machines(id: $id) {
results {
machine(id: $id) {
id
name
snapshots {
id
name
snapshots {
id
name
state
created
updated
}
state
created
updated
}
}
}

View File

@ -1,13 +1,11 @@
query instance($id: ID!) {
machines(id: $id) {
results {
machine(id: $id) {
id
name
tags {
id
name
tags {
id
name
value
}
value
}
}
}

View File

@ -49,7 +49,7 @@ export default ({ theme }) => css`
}
.CodeMirror {
border: solid 1px ${theme.grey};
border: solid ${remcalc(1)} ${theme.grey};
margin: ${remcalc(8)} 0 ${remcalc(8)} 0;
font-family: "Roboto Mono", monospace !important;
}

View File

@ -103,7 +103,7 @@ exports[`Breadcrumb Default Breadcrumb 1`] = `
}
.c0 {
border-bottom: 1px solid rgb(216,216,216);
border-bottom: 0.0625rem solid rgb(216,216,216);
}
@media only screen and (min-width:48em) {

View File

@ -2,11 +2,12 @@ import React from 'react';
import styled from 'styled-components';
import { Row, Col } from 'joyent-react-styled-flexboxgrid';
import { Padding } from 'styled-components-spacing';
import remcalc from 'remcalc';
import Container from '../layout/view-container';
const BreadcrumContianer = styled(Container)`
border-bottom: 1px solid ${props => props.theme.grey};
border-bottom: ${remcalc(1)} solid ${props => props.theme.grey};
`;
/**

View File

@ -1,4 +1,5 @@
import styled from 'styled-components';
import remcalc from 'remcalc';
export default styled.span`
display: inline-block;
@ -15,6 +16,6 @@ export default styled.span`
& [data-ui-button='true']:not(:last-child) {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
margin-right: -1px;
margin-right: ${remcalc(-1)};
}
`;

View File

@ -275,7 +275,7 @@ exports[`SectionList SectionList 1`] = `
list-style-type: none;
padding: 0.8125rem 0rem;
margin: 1.125rem 0 0 0;
max-height: 50px;
max-height: 3.125rem;
overflow-x: auto;
overflow-y: hidden;
box-sizing: border-box;

View File

@ -9,7 +9,7 @@ const UnorderedList = styled.ul`
list-style-type: none;
padding: ${remcalc(13)} ${remcalc(0)};
margin: ${remcalc(18)} 0 0 0;
max-height: 50px;
max-height: ${remcalc(50)};
overflow-x: auto;
overflow-y: hidden;
box-sizing: border-box;

View File

@ -2517,9 +2517,9 @@ clone@^1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.3.tgz#298d7e2231660f40c003c2ed3140decf3f53085f"
cloudapi-gql@^7.1.1:
version "7.1.2"
resolved "https://registry.yarnpkg.com/cloudapi-gql/-/cloudapi-gql-7.1.2.tgz#9087a60a5e95de259f62f2495744c526ec55a76c"
cloudapi-gql@^7.1.3:
version "7.1.3"
resolved "https://registry.yarnpkg.com/cloudapi-gql/-/cloudapi-gql-7.1.3.tgz#bb963454dd68f6e36e2a44302456faecf97831aa"
dependencies:
apr-map "3.x.x"
boom "7.x.x"