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

Timespan facet: convert years to ISO strings

parent 3dcc78e6
No related branches found
No related tags found
No related merge requests found
......@@ -38,7 +38,8 @@ class DateSliderFacet extends Component {
}
handleSliderOnChange = values => {
// console.log(this.YearToISOString(values[0]))
values[0] = this.YearToISOString({ year: values[0], start: true });
values[1] = this.YearToISOString({ year: values[1], start: false });
this.props.updateFacetOption({
facetClass: this.props.facetClass,
facetID: this.props.facetID,
......@@ -57,10 +58,27 @@ class DateSliderFacet extends Component {
return year;
}
// YearToISOString = year => {
// let str = null;
// console.log(year)
// }
YearToISOString = ({ year, start }) => {
const abs = Math.abs(year);
let s = year.toString();
let negative = false;
if (s.charAt(0) == '-') {
s = s.substring(1);
negative = true;
}
if (abs < 10) {
s = '000' + s;
}
if (abs >= 10 && abs < 100) {
s = '00' + s;
}
if (abs >= 100 && abs < 1000) {
s = '0' + s;
s = negative ? s = '-' + s : s;
}
s = start ? s + '-01-01' : s + '-12-31';
return s;
}
render() {
const { classes, someFacetIsFetching } = this.props;
......
......@@ -88,10 +88,10 @@ const ResultTableCell = props => {
target='_blank' rel='noopener noreferrer'
href={item.dataProviderUrl}
>
{item.prefLabel}
{Array.isArray(item.prefLabel) ? item.prefLabel[0] : item.prefLabel}
</a>
}
{!makeLink && item.prefLabel}
{!makeLink && Array.isArray(item.prefLabel) ? item.prefLabel[0] : item.prefLabel}
</li>
);
if (numberedList) {
......@@ -104,13 +104,13 @@ const ResultTableCell = props => {
return (
<React.Fragment>
{!props.expanded && !makeLink &&
<span>{firstValue.prefLabel} ...</span>}
<span>{Array.isArray(firstValue.prefLabel) ? firstValue.prefLabel[0] : firstValue.prefLabel} ...</span>}
{!props.expanded && makeLink &&
<a
target='_blank' rel='noopener noreferrer'
href={firstValue.dataProviderUrl}
>
{firstValue.prefLabel} ...
{Array.isArray(firstValue.prefLabel) ? firstValue.prefLabel[0] : firstValue.prefLabel} ...
</a>
}
<Collapse in={props.expanded} timeout="auto" unmountOnExit>
......@@ -132,7 +132,7 @@ const ResultTableCell = props => {
);
} else {
return (
<span>{cell.prefLabel}</span>
<span>{Array.isArray(cell.prefLabel) ? cell.prefLabel[0] : cell.prefLabel}</span>
);
}
};
......
......@@ -52,26 +52,26 @@ export const INITIAL_STATE = {
spatialFilter: null,
type: 'hierarchical',
},
// productionTimespan: {
// id: 'productionTimespan',
// label: 'Production date',
// //predicate: defined in backend
// distinctValueCount: 0,
// values: [],
// flatValues: [],
// sortBy: null,
// sortDirection: null,
// sortButton: false,
// spatialFilterButton: false,
// isFetching: false,
// searchField: false,
// containerClass: 'three',
// filterType: 'timespanFilter',
// min: null,
// max: null,
// timespanFilter: null,
// type: 'timespan'
// },
productionTimespan: {
id: 'productionTimespan',
label: 'Production date',
//predicate: defined in backend
distinctValueCount: 0,
values: [],
flatValues: [],
sortBy: null,
sortDirection: null,
sortButton: false,
spatialFilterButton: false,
isFetching: false,
searchField: false,
containerClass: 'three',
filterType: 'timespanFilter',
min: null,
max: null,
timespanFilter: null,
type: 'timespan'
},
author: {
id: 'author',
label: 'Author',
......
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