-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(metadata): create an isolated component (#1071)
- Loading branch information
1 parent
2da67d2
commit c123cf7
Showing
8 changed files
with
109 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
|
||
import Form from "../Form.jsx"; | ||
import { convertLegacyValues } from "./MetadataValues.js"; | ||
|
||
/** | ||
* @param data Values in JSON format | ||
* @param templates List of template names | ||
* @param onChange Function that return the values in YAML format | ||
* @returns {Element} | ||
* @constructor | ||
*/ | ||
export default function MetadataForm({ data, templates, onChange }) { | ||
const formData = convertLegacyValues(data) | ||
const basicMode = templates.includes('basic') | ||
return <Form formData={formData} basicMode={basicMode} onChange={onChange}/> | ||
} | ||
|
||
MetadataForm.propTypes = { | ||
data: PropTypes.object, | ||
templates: PropTypes.array, | ||
onChange: PropTypes.func, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Convert legacy values. | ||
* @param {object} data | ||
* @returns {*} | ||
*/ | ||
export function convertLegacyValues(data) { | ||
// we convert YYYY/MM/DD dates into ISO YYYY-MM-DD | ||
if (data.date) { | ||
data.date = data.date.replace(/\//g, '-') | ||
} | ||
|
||
// we array-ify legacy string keywords | ||
if (data.keywords) { | ||
data.keywords = data.keywords.map(block => { | ||
if (typeof block.list_f === 'string') { | ||
block.list_f = block.list_f.split(',').map(word => word.trim()) | ||
} | ||
return block | ||
}) | ||
} | ||
|
||
return data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"$id": "https://stylo.huma-num.fr/schemas/corpus-journal-metadata.schema.json", | ||
"title": "Journal metadata", | ||
"type": "object", | ||
"properties": { | ||
"type": { | ||
"type": "string", | ||
"const": "journal" | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"issue": { | ||
"type": "object", | ||
"properties": { | ||
"title": { | ||
"type": "string" | ||
}, | ||
"identifier": { | ||
"type": "string" | ||
}, | ||
"number": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,4 +61,4 @@ | |
"node": "18.20.4", | ||
"npm": "10.9.0" | ||
} | ||
} | ||
} |