diff --git a/src/components/Card.jsx b/src/components/Card.jsx
index eca86a9..ef7f984 100644
--- a/src/components/Card.jsx
+++ b/src/components/Card.jsx
@@ -1,6 +1,7 @@
import copy from '../common/data/copy.json'
import React from 'react'
+import CardCustomField from './presentational/Card/CustomField'
import CardTime from './presentational/Card/Time'
import CardLocation from './presentational/Card/Location'
import CardCaret from './presentational/Card/Caret'
@@ -132,6 +133,16 @@ class Card extends React.Component {
}
}
+ renderCustomFields () {
+ return this.props.features.CUSTOM_EVENT_FIELDS
+ .map(field => {
+ const value = this.props.event[field.key]
+ return value ? (
+
+ ) : null
+ })
+ }
+
renderMain () {
return (
@@ -140,6 +151,7 @@ class Card extends React.Component {
{this.renderLocation()}
{this.renderSummary()}
+ {this.renderCustomFields()}
)
}
diff --git a/src/components/presentational/Card/CustomField.js b/src/components/presentational/Card/CustomField.js
new file mode 100644
index 0000000..cb54f46
--- /dev/null
+++ b/src/components/presentational/Card/CustomField.js
@@ -0,0 +1,14 @@
+import React from 'react'
+import marked from 'marked'
+
+const CardCustomField = ({ field, value }) => (
+
+
+ {field.icon}
+ {field.title ? `${field.title}: ` : '- '}
+ {field.kind === 'text' ? value : marked(`[${value}](${field.value})`)}
+
+
+)
+
+export default CardCustomField
diff --git a/src/reducers/validate/eventSchema.js b/src/reducers/validate/eventSchema.js
index 7eeb4c5..6b7cb64 100644
--- a/src/reducers/validate/eventSchema.js
+++ b/src/reducers/validate/eventSchema.js
@@ -1,30 +1,42 @@
import Joi from 'joi'
-const eventSchema = Joi.object().keys({
- id: Joi.string().allow(''),
- description: Joi.string().allow('').required(),
- date: Joi.string().allow(''),
- time: Joi.string().allow(''),
- time_precision: Joi.string().allow(''),
- location: Joi.string().allow(''),
- latitude: Joi.string().allow(''),
- longitude: Joi.string().allow(''),
- type: Joi.string().allow(''),
- category: Joi.string().allow(''),
- category_full: Joi.string().allow(''),
- narratives: Joi.array(),
- sources: Joi.array(),
- filters: Joi.array().allow(''),
- tags: Joi.array().allow(''),
- comments: Joi.string().allow(''),
- time_display: Joi.string().allow(''),
+function joiFromCustom (custom) {
+ const output = {}
+ custom.forEach(field => {
+ if (field.kind === 'text' || field.kind === 'link') {
+ output[field.key] = Joi.string().allow('')
+ }
+ })
+ return output
+}
- // nested
- narrative___stepStyles: Joi.array(),
- shape: Joi.string().allow(''),
- colour: Joi.string().allow('')
-})
- .and('latitude', 'longitude')
- .or('date', 'latitude')
+function createEventSchema (custom) {
+ return Joi.object().keys({
+ id: Joi.string().allow(''),
+ description: Joi.string().allow('').required(),
+ date: Joi.string().allow(''),
+ time: Joi.string().allow(''),
+ time_precision: Joi.string().allow(''),
+ location: Joi.string().allow(''),
+ latitude: Joi.string().allow(''),
+ longitude: Joi.string().allow(''),
+ type: Joi.string().allow(''),
+ category: Joi.string().allow(''),
+ category_full: Joi.string().allow(''),
+ narratives: Joi.array(),
+ sources: Joi.array(),
+ filters: Joi.array().allow(''),
+ tags: Joi.array().allow(''),
+ comments: Joi.string().allow(''),
+ time_display: Joi.string().allow(''),
+ // nested
+ narrative___stepStyles: Joi.array(),
+ shape: Joi.string().allow(''),
+ colour: Joi.string().allow(''),
+ ...joiFromCustom(custom)
+ })
+ .and('latitude', 'longitude')
+ .or('date', 'latitude')
+}
-export default eventSchema
+export default createEventSchema
diff --git a/src/reducers/validate/validators.js b/src/reducers/validate/validators.js
index bbf82b7..05e6dbb 100644
--- a/src/reducers/validate/validators.js
+++ b/src/reducers/validate/validators.js
@@ -1,6 +1,6 @@
import Joi from 'joi'
-import eventSchema from './eventSchema'
+import createEventSchema from './eventSchema'
import categorySchema from './categorySchema'
import siteSchema from './siteSchema'
import narrativeSchema from './narrativeSchema'
@@ -141,6 +141,11 @@ export function validateDomain (domain, features) {
})
}
+ if (!Array.isArray(features.CUSTOM_EVENT_FIELDS)) {
+ features.CUSTOM_EVENT_FIELDS = []
+ }
+
+ const eventSchema = createEventSchema(features.CUSTOM_EVENT_FIELDS)
validateArray(domain.events, 'events', eventSchema)
validateArray(domain.categories, 'categories', categorySchema)
validateArray(domain.sites, 'sites', siteSchema)