Skip to content
Snippets Groups Projects
Commit 1ee2c49d authored by esikkala's avatar esikkala
Browse files

ResultTableCell: improve label handling

parent 2889db43
No related branches found
No related tags found
No related merge requests found
...@@ -53,7 +53,7 @@ const ObjectList = props => { ...@@ -53,7 +53,7 @@ const ObjectList = props => {
return data return data
} }
const renderItem = ({ collapsed, itemData, isFirstValue = false }) => { const renderItem = ({ addThreeDots, itemData, isFirstValue = false }) => {
if (columnId === 'event') { if (columnId === 'event') {
return ( return (
<> <>
...@@ -61,7 +61,7 @@ const ObjectList = props => { ...@@ -61,7 +61,7 @@ const ObjectList = props => {
data={itemData} data={itemData}
isFirstValue={isFirstValue} isFirstValue={isFirstValue}
/> />
{collapsed && <span> ...</span>} {addThreeDots && <span> ...</span>}
</> </>
) )
} else { } else {
...@@ -75,7 +75,7 @@ const ObjectList = props => { ...@@ -75,7 +75,7 @@ const ObjectList = props => {
isFirstValue={isFirstValue} isFirstValue={isFirstValue}
collapsedMaxWords={collapsedMaxWords} collapsedMaxWords={collapsedMaxWords}
/> />
{collapsed && <span> ...</span>} {addThreeDots && <span> ...</span>}
{showSource && itemData.source && {showSource && itemData.source &&
<ObjectListItemSources <ObjectListItemSources
data={itemData.source} data={itemData.source}
...@@ -111,14 +111,14 @@ const ObjectList = props => { ...@@ -111,14 +111,14 @@ const ObjectList = props => {
data = sortValues ? sortList(data) : data data = sortValues ? sortList(data) : data
return ( return (
<> <>
{!props.expanded && renderItem({ collapsed: true, itemData: data[0], isFirstValue: true })} {!props.expanded && renderItem({ addThreeDots: true, itemData: data[0], isFirstValue: true })}
<Collapse in={props.expanded} timeout='auto' unmountOnExit> <Collapse in={props.expanded} timeout='auto' unmountOnExit>
{numberedList ? renderNumberedList(data) : renderBulletedList(data)} {numberedList ? renderNumberedList(data) : renderBulletedList(data)}
</Collapse> </Collapse>
</> </>
) )
} else { } else {
return renderItem({ collapsed: false, itemData: data, isFirstValue: true }) return renderItem({ addThreeDots: data.shortenLabel, itemData: data })
} }
} }
......
...@@ -5,7 +5,7 @@ import ObjectListItemLink from './ObjectListItemLink' ...@@ -5,7 +5,7 @@ import ObjectListItemLink from './ObjectListItemLink'
const ObjectListItem = props => { const ObjectListItem = props => {
const { data, makeLink, externalLink, linkAsButton, isFirstValue, collapsedMaxWords } = props const { data, makeLink, externalLink, linkAsButton, isFirstValue, collapsedMaxWords } = props
let label = Array.isArray(data.prefLabel) ? data.prefLabel[0] : data.prefLabel let label = Array.isArray(data.prefLabel) ? data.prefLabel[0] : data.prefLabel
if (isFirstValue && collapsedMaxWords) { if ((isFirstValue || data.shortenLabel) && collapsedMaxWords) {
const wordCount = label.split(' ').length const wordCount = label.split(' ').length
if (wordCount > collapsedMaxWords) { if (wordCount > collapsedMaxWords) {
label = label.trim().split(' ').splice(0, props.collapsedMaxWords).join(' ') label = label.trim().split(' ').splice(0, props.collapsedMaxWords).join(' ')
......
...@@ -203,13 +203,16 @@ class ResultTable extends React.Component { ...@@ -203,13 +203,16 @@ class ResultTable extends React.Component {
if (column.valueType === 'image' && Array.isArray(columnData)) { if (column.valueType === 'image' && Array.isArray(columnData)) {
hasExpandableContent = false hasExpandableContent = false
} }
if (!isArray && // check if label should be shortened in ResultTableCell
columnData !== '-' && if (!isArray && column.collapsedMaxWords && columnData !== '-') {
column.valueType === 'string' && if (column.valueType === 'string' && columnData.split(' ').length > column.collapsedMaxWords) {
column.collapsedMaxWords && hasExpandableContent = true
columnData.split(' ').length > column.collapsedMaxWords columnData.shortenLabel = !expanded // shorten label only if the cell is not expanded
) { }
hasExpandableContent = true if (column.valueType === 'object' && columnData.prefLabel.split(' ').length > column.collapsedMaxWords) {
hasExpandableContent = true
columnData.shortenLabel = !expanded // shorten label only if the cell is not expanded
}
} }
return ( return (
<ResultTableCell <ResultTableCell
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment