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

Add more formatting options for result table cells

parent 5c8bc5d1
No related branches found
No related tags found
No related merge requests found
...@@ -112,6 +112,8 @@ class ResultTable extends React.Component { ...@@ -112,6 +112,8 @@ class ResultTable extends React.Component {
valueType={column.valueType} valueType={column.valueType}
makeLink={column.makeLink} makeLink={column.makeLink}
sortValues={column.sortValues} sortValues={column.sortValues}
numberedList={column.numberedList}
minWidth={column.minWidth}
/> />
); );
})} })}
......
...@@ -27,12 +27,6 @@ const styles = () => ({ ...@@ -27,12 +27,6 @@ const styles = () => ({
listStyle: 'none', listStyle: 'none',
paddingLeft: 0 paddingLeft: 0
}, },
withFilter: {
//minWidth: 170
},
wideColumn: {
minWidth: 170
},
infoIcon: { infoIcon: {
paddingTop: 15 paddingTop: 15
}, },
...@@ -69,12 +63,13 @@ const ResultTableCell = props => { ...@@ -69,12 +63,13 @@ const ResultTableCell = props => {
} }
}; };
const objectListRenderer = (cell, makeLink, ordered) => { const objectListRenderer = (cell, makeLink, sortValues, numberedList) => {
if (cell == null || cell === '-'){ if (cell == null || cell === '-'){
return '-'; return '-';
} }
else if (Array.isArray(cell)) { else if (Array.isArray(cell)) {
cell = orderBy(cell, 'prefLabel'); cell = sortValues ? orderBy(cell, 'prefLabel') : cell;
const listItems = cell.map((item, i) => const listItems = cell.map((item, i) =>
<li key={i}> <li key={i}>
{makeLink && {makeLink &&
...@@ -88,7 +83,7 @@ const ResultTableCell = props => { ...@@ -88,7 +83,7 @@ const ResultTableCell = props => {
{!makeLink && item.prefLabel} {!makeLink && item.prefLabel}
</li> </li>
); );
if (ordered) { if (numberedList) {
return ( return (
<ol className={props.classes.valueList}> <ol className={props.classes.valueList}>
{listItems} {listItems}
...@@ -159,13 +154,13 @@ const ResultTableCell = props => { ...@@ -159,13 +154,13 @@ const ResultTableCell = props => {
} }
}; };
const ownerRenderer = cell => { const ownerRenderer = (cell, makeLink, sortValues, numberedList) => {
if (cell == null || cell === '-'){ if (cell == null || cell === '-'){
return '-'; return '-';
} }
if (Array.isArray(cell)) { if (Array.isArray(cell)) {
if (!has(cell[0], 'order')) { if (!has(cell[0], 'order')) {
return objectListRenderer(cell, true, false); return objectListRenderer(cell, makeLink, sortValues, numberedList);
} }
cell.map(item => { cell.map(item => {
Array.isArray(item.order) ? item.earliestOrder = item.order[0] : item.earliestOrder = item.order; Array.isArray(item.order) ? item.earliestOrder = item.order[0] : item.earliestOrder = item.order;
...@@ -192,7 +187,7 @@ const ResultTableCell = props => { ...@@ -192,7 +187,7 @@ const ResultTableCell = props => {
); );
} else { } else {
if (!has(cell, 'order')) { if (!has(cell, 'order')) {
return objectListRenderer(cell, true, false); return objectListRenderer(cell, makeLink, sortValues, numberedList);
} }
return ( return (
<span>{cell.date}<br />{cell.location}</span> <span>{cell.date}<br />{cell.location}</span>
...@@ -200,8 +195,9 @@ const ResultTableCell = props => { ...@@ -200,8 +195,9 @@ const ResultTableCell = props => {
} }
}; };
const { data, valueType, makeLink, sortValues } = props; const { data, valueType, makeLink, sortValues, numberedList, minWidth } = props;
let renderer = null; let renderer = null;
let cellStyle = minWidth == null ? {} : { minWidth: minWidth };
switch (valueType) { switch (valueType) {
case 'object': case 'object':
renderer = objectListRenderer; renderer = objectListRenderer;
...@@ -218,8 +214,8 @@ const ResultTableCell = props => { ...@@ -218,8 +214,8 @@ const ResultTableCell = props => {
} }
return( return(
<TableCell> <TableCell style={cellStyle}>
{renderer(data, makeLink, sortValues)} {renderer(data, makeLink, sortValues, numberedList)}
</TableCell> </TableCell>
); );
}; };
...@@ -230,6 +226,8 @@ ResultTableCell.propTypes = { ...@@ -230,6 +226,8 @@ ResultTableCell.propTypes = {
valueType: PropTypes.string.isRequired, valueType: PropTypes.string.isRequired,
makeLink: PropTypes.bool.isRequired, makeLink: PropTypes.bool.isRequired,
sortValues: PropTypes.bool.isRequired, sortValues: PropTypes.bool.isRequired,
numberedList: PropTypes.bool.isRequired,
minWidth: PropTypes.number
}; };
export default withStyles(styles)(ResultTableCell); export default withStyles(styles)(ResultTableCell);
...@@ -17,55 +17,68 @@ export const INITIAL_STATE = { ...@@ -17,55 +17,68 @@ export const INITIAL_STATE = {
id: 'source', id: 'source',
valueType: 'object', valueType: 'object',
makeLink: true, makeLink: true,
sortValues: false sortValues: true,
numberedList: false
}, },
{ {
id: 'prefLabel', id: 'prefLabel',
valueType: 'string', valueType: 'string',
makeLink: false, makeLink: false,
sortValues: true sortValues: true,
numberedList: false
}, },
{ {
id: 'author', id: 'author',
valueType: 'object', valueType: 'object',
makeLink: true, makeLink: true,
sortValues: true sortValues: true,
numberedList: false,
minWidth: 170
}, },
{ {
id: 'productionPlace', id: 'productionPlace',
valueType: 'object', valueType: 'object',
makeLink: true, makeLink: true,
sortValues: true sortValues: true,
numberedList: false,
minWidth: 170,
}, },
{ {
id: 'timespan', id: 'timespan',
valueType: 'object', valueType: 'object',
makeLink: true, makeLink: false,
sortValues: false sortValues: true,
numberedList: false
}, },
{ {
id: 'language', id: 'language',
valueType: 'string', valueType: 'string',
makeLink: true, makeLink: false,
sortValues: true sortValues: true,
numberedList: false
}, },
// { // {
// id: 'material', // id: 'material',
// valueType: 'string', // valueType: 'string',
// makeLink: true, // makeLink: true,
// sortValues: true // sortValues: true
// numberedList: false
// }, // },
{ {
id: 'event', id: 'event',
valueType: 'event', valueType: 'event',
makeLink: true, makeLink: true,
sortValues: true sortValues: true,
numberedList: false,
minWidth: 170,
}, },
{ {
id: 'owner', id: 'owner',
valueType: 'owner', valueType: 'owner',
makeLink: true, makeLink: true,
sortValues: true sortValues: true,
numberedList: false,
minWidth: 170
} }
], ],
places: [], places: [],
......
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