Commit 12697948 authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '41-utilities' into 'main'

Utilities: add Number and McpdDate support

Closes #41

See merge request !42
parents 11e53c5d 25572f97
......@@ -15,6 +15,7 @@ import LocationMap from 'map/LocationMap';
import Loading from 'ui/common/Loading';
import PageTitle from 'ui/common/PageTitle';
import Markdown from 'ui/common/Markdown';
import McpdDate from "ui/common/McpdDate";
interface AccessionDetailsPageState {
accession: AccessionDetails;
......@@ -30,7 +31,10 @@ class AccessionDetailsPage extends React.Component<AccessionDetailsPageProps & W
super(props);
}
public state = {
public state: {
accession: AccessionDetails,
cartItems: string[],
} = {
accession: null,
cartItems: LocalStorageCart.getCartItemsLS(),
};
......@@ -160,6 +164,9 @@ class AccessionDetailsPage extends React.Component<AccessionDetailsPageProps & W
<CountryName code3={ details.countryOfOrigin.code3 } /> || details.countryOfOrigin.name
} index={ propertyIndex++ } />
}
{ details.acquisitionDate &&
<Property title={ t('accession.acquisitionDate') } value={<McpdDate value={details.acquisitionDate}/>} index={ propertyIndex++ } />
}
{ details.ancest &&
<Property title={ t('accession.ancest') } value={ details.ancest } index={ propertyIndex++ }/>
}
......@@ -242,7 +249,7 @@ class AccessionDetailsPage extends React.Component<AccessionDetailsPageProps & W
{ details.coll.collSrc &&
<Property title={ t('accession.coll.collSrc') } value={ t(`accession.collectingSource.${details.coll.collSrc}`) } index={ propertyIndex++ }/>
}
<Property title={ t('accession.coll.collDate') } value={ details.coll.collDate } index={ propertyIndex++ }/>
<Property title={ t('accession.coll.collDate') } value={ <McpdDate value={details.coll.collDate}/> } index={ propertyIndex++ }/>
<Property title={ t('accession.coll.collMissId') } value={ details.coll.collMissId } index={ propertyIndex++ }/>
<Property title={ t('accession.coll.collCode') } value={ details.coll.collCode } index={ propertyIndex++ }/>
<Property title={ t('accession.coll.collName') } value={ details.coll.collName } index={ propertyIndex++ }/>
......
......@@ -14,6 +14,8 @@ import Loading from 'ui/common/Loading';
import PageTitle from 'ui/common/PageTitle';
import Markdown from 'ui/common/Markdown';
import AccessionTable from 'accession/c/AccessionTable';
import McpdDate from 'ui/common/McpdDate';
import Number from 'ui/common/Number';
import LocationMap from "map/LocationMap";
interface DatasetDetailsPageProps {
......@@ -123,7 +125,7 @@ const DatasetDetailsPage = ({match}: DatasetDetailsPageProps) => {
{!!dataset.accessionCount &&
<Property
title={t('dataset.accessionCount')} value={ dataset.accessionCount }
title={t('dataset.accessionCount')} value={ <Number value={dataset.accessionCount}/> }
index={propertyIndex++}
/>
}
......@@ -147,14 +149,14 @@ const DatasetDetailsPage = ({match}: DatasetDetailsPageProps) => {
{!!dataset.startDate &&
<Property
title={t('dataset.startDate')} value={ dataset.startDate }
title={t('dataset.startDate')} value={ <McpdDate value={dataset.startDate}/> }
index={propertyIndex++}
/>
}
{!!dataset.endDate &&
<Property
title={t('dataset.endDate')} value={ dataset.endDate }
title={t('dataset.endDate')} value={ <McpdDate value={dataset.endDate}/> }
index={propertyIndex++}
/>
}
......@@ -199,7 +201,7 @@ const DatasetDetailsPage = ({match}: DatasetDetailsPageProps) => {
</>
}
<h2 className="mt-4">{t('dataset.details.accessions')}</h2>
<h2 className="mt-4">{t('dataset.details.accessions')}</h2>
<AccessionTable accessions={accessions} loadData={loadAccessions} noRedirect/>
</>
......
......@@ -19,6 +19,7 @@ import {DatasetFilters} from "dataset/DatasetFilters";
import {parseLocationSearch} from "utilities/filterUtil";
import {useSelector} from "react-redux";
import Markdown from 'ui/common/Markdown';
import Number from "ui/common/Number";
interface IDatasetListPageProps {
location: any;
......@@ -92,7 +93,7 @@ const DatasetListPage = ({location}: IDatasetListPageProps) => {
<tr key={d.id}>
<td><Link to={`/datasets/${d.uuid}`}><Markdown basic source={d.title}/></Link></td>
<td>{d.crops && d.crops.length > 0 && <p>{d.crops.join(', ')}</p>}</td>
<td>{d.accessionCount}</td>
<td>{<Number value={d.accessionCount}/>}</td>
<td><Markdown firstParagraph source={d.description} /></td>
</tr>
))}
......
......@@ -9,7 +9,8 @@
},
"loading": "Loading...",
"label": {
"andMore": "And {{otherMore, number}} more"
"andMore": "And {{otherMore, number}} more",
"dateNotProvided": "Date not provided"
},
"action": {
"submit": "Submit",
......@@ -73,6 +74,7 @@
"instituteCode": "Institute code",
"genus": "Genus",
"countryOfOrigin": "Provenance of material",
"acquisitionDate": "Acquisition date",
"species": "Specific epithet",
"sampStat": "Biological status",
"storageType": "Type of germplasm storage",
......
......@@ -14,6 +14,7 @@ import Loading from 'ui/common/Loading';
import PageTitle from 'ui/common/PageTitle';
import Markdown from 'ui/common/Markdown';
import AccessionTable from 'accession/c/AccessionTable';
import Number from "ui/common/Number";
interface SubsetDetailsPageProps {
match: any;
......@@ -94,7 +95,7 @@ const SubsetDetailsPage = ({match}: SubsetDetailsPageProps) => {
{subset.accessionCount &&
<Property
title={t('subset.accessionCount')} value={ subset.accessionCount }
title={t('subset.accessionCount')} value={ <Number value={subset.accessionCount}/> }
index={propertyIndex++}
/>
}
......@@ -113,7 +114,7 @@ const SubsetDetailsPage = ({match}: SubsetDetailsPageProps) => {
/>
}
<h2 className="mt-4">{t('subset.details.accessions')}</h2>
<h2 className="mt-4">{t('subset.details.accessions')}</h2>
<AccessionTable accessions={accessions} loadData={loadAccessions} noRedirect/>
</>
);
......
import * as React from 'react';
import { WithTranslation, withTranslation } from 'react-i18next';
export default withTranslation()(function McpdDate({ value, locale = 'en-GB', t }: WithTranslation & { value: string, locale?: string }) {
if (!value) {
return (<i>{ t('label.dateNotProvided') }</i>);
}
const year = value.substr(0, 4);
const month = value.substr(4, 2);
const day = value.substr(6, 2);
let mcpdDate;
if (!month || month === '--' || month === '00') {
mcpdDate = year;
} else {
if (!day || day === '--' || day === '00') {
const options = { year: 'numeric', month: 'long' };
mcpdDate = new Date(parseInt(year, 10), parseInt(month, 10) - 1, 1).toLocaleDateString(locale, options);
} else {
const options = { year: 'numeric', month: 'long', day: 'numeric' };
mcpdDate = new Date(parseInt(year, 10), parseInt(month, 10) - 1, parseInt(day, 10)).toLocaleDateString(locale, options);
}
}
return (
<span className="prettydate">
{ mcpdDate }
</span>
);
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment