diff --git a/packages/my-joy-beta/src/components/instances/key-value.js b/packages/my-joy-beta/src/components/instances/key-value.js
index 96a44daa..f6c48bda 100644
--- a/packages/my-joy-beta/src/components/instances/key-value.js
+++ b/packages/my-joy-beta/src/components/instances/key-value.js
@@ -1,5 +1,6 @@
import React from 'react';
import { Row, Col } from 'react-styled-flexboxgrid';
+import { Field } from 'redux-form';
import {
FormGroup,
@@ -7,12 +8,46 @@ import {
Button,
BinIcon,
QueryBreakpoints,
- Divider
+ Divider,
+ Editor
} from 'joyent-ui-toolkit';
const { SmallOnly, Small } = QueryBreakpoints;
-export default ({ name, formName, formValue, handleSubmit, onRemove, textarea }) => (
+const TextareaKeyValue = ({ name, formName, formValue, handleSubmit, onRemove, textarea }) => (
+
+);
+
+const InputKeyValue = ({ name, formName, formValue, handleSubmit, onRemove, textarea }) => (
);
+
+export default ({ textarea, ...rest }) => textarea
+ ?
+ : ;
diff --git a/packages/my-joy-beta/src/containers/instances/metadata.js b/packages/my-joy-beta/src/containers/instances/metadata.js
index 6a80391e..71d86e92 100644
--- a/packages/my-joy-beta/src/containers/instances/metadata.js
+++ b/packages/my-joy-beta/src/containers/instances/metadata.js
@@ -12,32 +12,35 @@ 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);
+
+ return (
+ console.log(key, val)}
+ onRemove={key => console.log('remove', key)}
+ textarea
+ />
+ );
+});
+
const Metadata = ({ metadata = [], loading, error }) => {
const _title = Metadata;
const _loading = !(loading && !forceArray(metadata).length) ? null : (
);
- const metadataNames = Object.keys(metadata).map(name => ({
- key: paramCase(name),
- name
- }));
-
- const InstanceMetadataForm = reduxForm({
- form: `instance-tags`,
- initialValues: metadataNames.reduce(
- (all, { key, name }) => ({
- ...all,
- [`${key}-name`]: name,
- [`${key}-value`]: metadata[name]
- }),
- {}
- )
- })(KeyValue);
-
- const _tags = !_loading && (
- key)} />
- );
+ const _metadata = !_loading && MetadataForms(metadata);
const _error = !(error && !_loading) ? null : (
{
{_title}
{_loading}
{_error}
- {_tags}
+ {_metadata}
);
};
@@ -69,14 +72,30 @@ export default compose(
name: get(match, 'params.instance')
}
}),
- props: ({ data: { loading, error, variables, ...rest } }) => ({
- metadata: get(
+ props: ({ data: { loading, error, variables, ...rest } }) => {
+ const values = get(
find(get(rest, 'machines', []), ['name', variables.name]),
'metadata',
[]
- ),
- loading,
- error
- })
+ );
+
+
+ const metadata = Object.keys(values).reduce((all, name) => {
+ const key = paramCase(name);
+
+ return {
+ ...all,
+ [key]: {
+ key,
+ formName: `${key}-name`,
+ formValue: `${key}-value`,
+ value: values[name],
+ name
+ }
+ };
+ }, {});
+
+ return { metadata: Object.values(metadata), loading, error };
+ }
})
)(Metadata);