diff --git a/front/src/components/Form.jsx b/front/src/components/Form.jsx index 4e97a913f..0cf2831f9 100644 --- a/front/src/components/Form.jsx +++ b/front/src/components/Form.jsx @@ -7,7 +7,6 @@ import { Translation } from 'react-i18next' import basicUiSchema from '../schemas/ui-schema-basic-override.json' import defaultUiSchema from '../schemas/ui-schema-editor.json' import defaultSchema from '../schemas/data-schema.json' -import { toYaml } from './Write/metadata/yaml' // REMIND: use a custom SelectWidget to support "ui:emptyValue" // remove once fixed in https://github.com/rjsf-team/react-jsonschema-form/issues/1041 @@ -256,7 +255,7 @@ export default function SchemaForm ({ const path = id.replace('root_', '').replace('_', '.') setFormData((state) => { const newFormData = set(state, path, value) - onChange(toYaml(newFormData)) + onChange(newFormData) return newFormData }) }, @@ -282,7 +281,7 @@ export default function SchemaForm ({ const handleUpdate = useCallback((event) => { const formData = event.formData setFormData(formData) - onChange(toYaml(formData)) + onChange(formData) }, [setFormData, onChange]) // noinspection JSValidateTypes diff --git a/front/src/components/Write/yamleditor/YamlEditor.jsx b/front/src/components/Write/yamleditor/YamlEditor.jsx index 2ed7e56e5..ac64b8978 100644 --- a/front/src/components/Write/yamleditor/YamlEditor.jsx +++ b/front/src/components/Write/yamleditor/YamlEditor.jsx @@ -1,28 +1,15 @@ -import React from 'react' +import React, { useCallback } from 'react' import PropTypes from 'prop-types' import YAML from 'js-yaml' import Form from '../../Form' +import { toYaml } from "../metadata/yaml.js"; +import { convertLegacyValues } from "../../metadata/MetadataValues.js"; -export default function YamlEditor ({ yaml = '', basicMode = false, onChange }) { +export default function YamlEditor({ yaml = '', basicMode = false, onChange = () => {} }) { const [parsed = {}] = YAML.loadAll(yaml) - - // we convert YYYY/MM/DD dates into ISO YYYY-MM-DD - if (parsed.date) { - parsed.date = parsed.date.replace(/\//g, '-') - } - - // we array-ify legacy string keywords - if (parsed.keywords) { - parsed.keywords = parsed.keywords.map(block => { - if (typeof block.list_f === 'string') { - block.list_f = block.list_f.split(',').map(word => word.trim()) - } - - return block - }) - } - - return
+ const formData = convertLegacyValues(parsed) + const handleChange = useCallback((newFormData) => onChange(toYaml(newFormData)), [onChange]) + return