From 3e61e3430ebbd7cc3f34ee2861f74cd09eb59207 Mon Sep 17 00:00:00 2001 From: Miu Razvan Date: Tue, 23 Aug 2022 11:39:54 +0300 Subject: [PATCH] feat: allow extra info in statistics block --- src/StatisticBlock/View.jsx | 2 ++ src/StatisticBlock/schema.js | 8 +++++++- src/helpers.js | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/helpers.js diff --git a/src/StatisticBlock/View.jsx b/src/StatisticBlock/View.jsx index 891e444..98a5100 100644 --- a/src/StatisticBlock/View.jsx +++ b/src/StatisticBlock/View.jsx @@ -1,5 +1,6 @@ import React from 'react'; import { Statistic } from 'semantic-ui-react'; +import { serializeText } from '@eeacms/volto-statistic-block/helpers'; const View = ({ data, mode }) => { const { @@ -27,6 +28,7 @@ const View = ({ data, mode }) => { > {item.value} {item.label} + {serializeText(item.info)} ); })} diff --git a/src/StatisticBlock/schema.js b/src/StatisticBlock/schema.js index 632be9a..01b0d04 100644 --- a/src/StatisticBlock/schema.js +++ b/src/StatisticBlock/schema.js @@ -1,6 +1,8 @@ const statisticSchema = { title: 'Statistic item', - fieldsets: [{ id: 'default', title: 'Default', fields: ['value', 'label'] }], + fieldsets: [ + { id: 'default', title: 'Default', fields: ['value', 'label', 'info'] }, + ], properties: { value: { title: 'Value', @@ -8,6 +10,10 @@ const statisticSchema = { label: { title: 'Label', }, + info: { + title: 'Extra info', + widget: 'slate_richtext', + }, }, required: [], }; diff --git a/src/helpers.js b/src/helpers.js new file mode 100644 index 0000000..e809884 --- /dev/null +++ b/src/helpers.js @@ -0,0 +1,6 @@ +import { isArray } from 'lodash'; +import { serializeNodes } from 'volto-slate/editor/render'; + +export const serializeText = (text) => { + return isArray(text) ? serializeNodes(text) : text; +};