Skip to content

Commit 3770029

Browse files
committed
Use json widget for whole document edition
1 parent cf190af commit 3770029

File tree

1 file changed

+11
-10
lines changed
  • packages/client/src/pages/CollectionForm

1 file changed

+11
-10
lines changed

packages/client/src/pages/CollectionForm/index.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import { Box, Button, Flex, Heading, Textarea } from '@chakra-ui/react';
99
import useUpdateCollection from './useUpdateCollection';
1010
import { Field, FieldProps, Formik } from 'formik';
11+
import { WidgetJSON } from '@stac-manager/data-widgets';
1112

1213
interface CollectionFormProps {}
1314

@@ -30,8 +31,8 @@ export function CollectionForm(props: CollectionFormProps) {
3031
console.log('🚀 ~ onSubmit ~ exitData:', exitData);
3132
} else if (action === 'switch-view') {
3233
if (view === 'json') {
33-
console.log('JSON.parse(data.jsonData)', JSON.parse(data.jsonData));
34-
setStacData(JSON.parse(data.jsonData));
34+
console.log('data.jsonData', data.jsonData);
35+
setStacData(data.jsonData);
3536
setView('fields');
3637
} else {
3738
const d = toOutData(data);
@@ -45,7 +46,8 @@ export function CollectionForm(props: CollectionFormProps) {
4546
const editorData = useMemo(
4647
() =>
4748
view === 'json'
48-
? { jsonData: JSON.stringify(stacData, null, 2) }
49+
? // ? { jsonData: JSON.stringify(stacData, null, 2) }
50+
{ jsonData: stacData }
4951
: formData,
5052
[view, formData]
5153
);
@@ -108,14 +110,13 @@ export function EditForm({ plugins, data, onAction, view }: EditFormProps) {
108110
});
109111
}}
110112
>
111-
{view}
113+
{view === 'json' ? 'Switch to Form view' : 'Switch to JSON view'}
112114
</Button>
113115
{view === 'json' ? (
114-
<Field name='jsonData'>
115-
{(props: FieldProps) => (
116-
<Textarea {...props.field} minH='20rem' />
117-
)}
118-
</Field>
116+
<WidgetJSON
117+
field={{ type: 'json', label: 'Json Document' }}
118+
pointer='jsonData'
119+
/>
119120
) : (
120121
plugins.map((pl) => (
121122
<PluginBox key={pl.name} plugin={pl}>
@@ -140,4 +141,4 @@ export function EditForm({ plugins, data, onAction, view }: EditFormProps) {
140141
</Formik>
141142
</Flex>
142143
);
143-
}
144+
}

0 commit comments

Comments
 (0)