From f1f894756ac76adfff07280702556ac02687f35f Mon Sep 17 00:00:00 2001 From: Sara Bianchi Date: Thu, 21 Dec 2023 11:46:26 +0100 Subject: [PATCH] chore: updated object type with render component from site configuration --- src/config/italiaConfig.js | 1 + .../components/manage/Contents/Contents.jsx | 53 +++++++++++-------- .../manage/Contents/ContentsItem.jsx | 7 +-- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/config/italiaConfig.js b/src/config/italiaConfig.js index a78586128..d44c15c74 100644 --- a/src/config/italiaConfig.js +++ b/src/config/italiaConfig.js @@ -134,6 +134,7 @@ export default function applyConfig(voltoConfig) { // label: 'Bandi gara - Uff. Resp.', // type: 'object', // sort_on: 'ufficio_responsabile_bando', + // component: (item) => <>{item.ufficio_responsabile_bando.title}, // }, }, diff --git a/src/customizations/volto/components/manage/Contents/Contents.jsx b/src/customizations/volto/components/manage/Contents/Contents.jsx index 38a1a326d..cd998746e 100644 --- a/src/customizations/volto/components/manage/Contents/Contents.jsx +++ b/src/customizations/volto/components/manage/Contents/Contents.jsx @@ -5,8 +5,9 @@ * * CUSTOMIZATIONS: * - Changed Indexes and defaultIndexes with spread between Volto objects and customIndex configured from config.js, * applied in the constructor and changed props with this.Indexes and this.defaultIndexes - * - Commented defaultProps + * - index in defaultProps is redefined in the constructor with the new properties * - Filtered Object.keys(config.settings.customIndexes) in dropdown menu map + * - Updated indexes props passed to ContentsItem component */ import React, { Component } from 'react'; @@ -368,24 +369,24 @@ class Contents extends Component { pathname: PropTypes.string.isRequired, }; - // /** - // * Default properties. - // * @property {Object} defaultProps Default properties. - // * @static - // */ - // static defaultProps = { - // items: [], - // action: null, - // source: null, - // index: { - // order: keys(VoltoIndexes), - // values: mapValues(VoltoIndexes, (value, key) => ({ - // ...value, - // selected: indexOf(DefaultVoltoIndexes, key) !== -1, - // })), - // selectedCount: DefaultVoltoIndexes.length + 1, - // }, - // }; + /** + * Default properties. + * @property {Object} defaultProps Default properties. + * @static + */ + static defaultProps = { + items: [], + action: null, + source: null, + // index: { + // order: keys(VoltoIndexes), + // values: mapValues(VoltoIndexes, (value, key) => ({ + // ...value, + // selected: indexOf(DefaultVoltoIndexes, key) !== -1, + // })), + // selectedCount: DefaultVoltoIndexes.length + 1, + // }, + }; /** * Constructor @@ -436,12 +437,22 @@ class Contents extends Component { this.filterTimeout = null; this.defaultIndexes = [ ...DefaultVoltoIndexes, - ...config.settings.customDefaultIndexes, + ...(config.settings.customDefaultIndexes ?? []), ]; this.Indexes = { ...VoltoIndexes, - ...config.settings.customIndexes, + ...(config.settings.customIndexes ?? {}), }; + if (!this.index) { + this.index = { + order: keys(this.Indexes), + values: mapValues(this.Indexes, (value, key) => ({ + ...value, + selected: indexOf(this.defaultIndexes, key) !== -1, + })), + selectedCount: this.defaultIndexes.length + 1, + }; + } this.state = { selected: [], showDelete: false, diff --git a/src/customizations/volto/components/manage/Contents/ContentsItem.jsx b/src/customizations/volto/components/manage/Contents/ContentsItem.jsx index 70dc6c3f8..2528b2156 100644 --- a/src/customizations/volto/components/manage/Contents/ContentsItem.jsx +++ b/src/customizations/volto/components/manage/Contents/ContentsItem.jsx @@ -218,9 +218,10 @@ export const ContentsItemComponent = ({ {index.type === 'array' && ( {item[index.id]?.join(', ')} )} - {index.type === 'object' && ( - {item[index.id]?.map((obj) => obj.title).join(', ')} - )} + {index.type === 'object' && + (index?.component + ? index.component(item) + : item[index.id]?.map((obj) => obj.title).join(', '))} ))}