Skip to content

Commit

Permalink
chore: updated object type with render component from site configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
SaraBianchi committed Dec 21, 2023
1 parent 94a8ff4 commit f1f8947
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/config/italiaConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}</>,
// },
},

Expand Down
53 changes: 32 additions & 21 deletions src/customizations/volto/components/manage/Contents/Contents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,10 @@ export const ContentsItemComponent = ({
{index.type === 'array' && (
<span>{item[index.id]?.join(', ')}</span>
)}
{index.type === 'object' && (
<span>{item[index.id]?.map((obj) => obj.title).join(', ')}</span>
)}
{index.type === 'object' &&
(index?.component
? index.component(item)
: item[index.id]?.map((obj) => obj.title).join(', '))}
</Table.Cell>
))}
<Table.Cell
Expand Down

0 comments on commit f1f8947

Please sign in to comment.