Commit cea40daa authored by Maksym Tishchenko's avatar Maksym Tishchenko
Browse files

Merge branch '28-irgc-accessions-all-unavailable' into 'master'

Resolve "IRGC accessions all unavailable?"

Closes #28

See merge request !24
parents dc44824c 8a800702
...@@ -5,7 +5,7 @@ import { AccessionService } from '@genesys/client/service'; ...@@ -5,7 +5,7 @@ import { AccessionService } from '@genesys/client/service';
import { Property } from 'ui/common/Property'; import { Property } from 'ui/common/Property';
import AccessionDetails from '@genesys/client/model/accession/AccessionDetails'; import AccessionDetails from '@genesys/client/model/accession/AccessionDetails';
import { WithTranslation, withTranslation } from 'react-i18next'; import { WithTranslation, withTranslation } from 'react-i18next';
import { LocalStorageCart } from 'utilities'; import { canAddToCart, LocalStorageCart } from 'utilities';
import { WithConfig } from 'config/config'; import { WithConfig } from 'config/config';
import { CountryName } from 'ui/common/CountryName'; import { CountryName } from 'ui/common/CountryName';
import GrinSpecies from 'ui/common/GrinSpecies'; import GrinSpecies from 'ui/common/GrinSpecies';
...@@ -81,7 +81,7 @@ class AccessionDetailsPage extends React.Component<IAccessionDetailsPage & WithT ...@@ -81,7 +81,7 @@ class AccessionDetailsPage extends React.Component<IAccessionDetailsPage & WithT
const { accession } = this.state; const { accession } = this.state;
const { t } = this.props; const { t } = this.props;
const canAddToCart = !(accession.details.historic === true || accession.details.available === false || accession.details.institute.allowMaterialRequests === true); const canAdd = canAddToCart(accession.details);
return <button return <button
type="button" type="button"
...@@ -91,7 +91,7 @@ class AccessionDetailsPage extends React.Component<IAccessionDetailsPage & WithT ...@@ -91,7 +91,7 @@ class AccessionDetailsPage extends React.Component<IAccessionDetailsPage & WithT
className="btn btn-primary" className="btn btn-primary"
onClick={ this.addToCart } onClick={ this.addToCart }
> >
{ canAddToCart ? t('cart.addToCart') : t('list.notAvailable') } { canAdd ? t('cart.addToCart') : t('list.notAvailable') }
</button> </button>
} }
......
...@@ -10,7 +10,7 @@ import FilteredPage, { IPageRequest } from '@genesys/client/model/FilteredPage'; ...@@ -10,7 +10,7 @@ import FilteredPage, { IPageRequest } from '@genesys/client/model/FilteredPage';
import Pagination from 'ui/common/Pagination'; import Pagination from 'ui/common/Pagination';
import { AccessionFilters } from './AccessionFilters'; import { AccessionFilters } from './AccessionFilters';
import { withTranslation, WithTranslation } from 'react-i18next'; import { withTranslation, WithTranslation } from 'react-i18next';
import { LocalStorageCart } from 'utilities'; import { canAddToCart, LocalStorageCart } from 'utilities';
import { WithConfig } from 'config/config'; import { WithConfig } from 'config/config';
import Loading from 'ui/common/Loading'; import Loading from 'ui/common/Loading';
import PageTitle from 'ui/common/PageTitle'; import PageTitle from 'ui/common/PageTitle';
...@@ -126,14 +126,10 @@ class AccessionListPage extends React.Component<IAccessionListPageProps & WithTr ...@@ -126,14 +126,10 @@ class AccessionListPage extends React.Component<IAccessionListPageProps & WithTr
this.setState( { cartItems: LocalStorageCart.getCartItemsLS() } ) this.setState( { cartItems: LocalStorageCart.getCartItemsLS() } )
} }
private canAddToCart = (accession) => {
return !(accession.historic === true || accession.available === false || accession.institute.allowMaterialRequests === true);
}
private renderCartButton = (accession, i) => { private renderCartButton = (accession, i) => {
const { t } = this.props; const { t } = this.props;
const { cartItems } = this.state; const { cartItems } = this.state;
if (!this.canAddToCart(accession)) { if (!canAddToCart(accession)) {
return <span>{t('list.notAvailable')}</span> return <span>{t('list.notAvailable')}</span>
} }
if ( cartItems.includes(accession.uuid)) { if ( cartItems.includes(accession.uuid)) {
...@@ -161,7 +157,7 @@ class AccessionListPage extends React.Component<IAccessionListPageProps & WithTr ...@@ -161,7 +157,7 @@ class AccessionListPage extends React.Component<IAccessionListPageProps & WithTr
private onToggleAll = () => { private onToggleAll = () => {
this.setState((prevState) => ({ this.setState((prevState) => ({
isAllSelected: !prevState.isAllSelected, isAllSelected: !prevState.isAllSelected,
selected: !prevState.isAllSelected ? prevState.accessions.content.map((acc) => this.canAddToCart(acc) && acc.uuid) : [], selected: !prevState.isAllSelected ? prevState.accessions.content.map((acc) => canAddToCart(acc) && acc.uuid) : [],
})); }));
}; };
...@@ -220,7 +216,7 @@ class AccessionListPage extends React.Component<IAccessionListPageProps & WithTr ...@@ -220,7 +216,7 @@ class AccessionListPage extends React.Component<IAccessionListPageProps & WithTr
<tr key={ a.id } className={ selectedUUIDs.has(a.uuid) ? 'table-primary' : '' }> <tr key={ a.id } className={ selectedUUIDs.has(a.uuid) ? 'table-primary' : '' }>
{ shoppingCart.enabled && ( { shoppingCart.enabled && (
<td> <td>
{ this.canAddToCart(a) && { canAddToCart(a) &&
<input <input
type="checkbox" type="checkbox"
name={ `checkbox-${a.uuid}-${i}` } name={ `checkbox-${a.uuid}-${i}` }
......
...@@ -2,6 +2,7 @@ import * as cookies from 'es-cookie'; ...@@ -2,6 +2,7 @@ import * as cookies from 'es-cookie';
import { LoginService, reconfigureServiceAxios } from '@genesys/client/service'; import { LoginService, reconfigureServiceAxios } from '@genesys/client/service';
import { clearCookies, saveCookies } from '@genesys/client/utilities'; import { clearCookies, saveCookies } from '@genesys/client/utilities';
import { log } from '@genesys/client/utilities/debug'; import { log } from '@genesys/client/utilities/debug';
import Accession from '@genesys/client/model/accession/Accession';
export function checkAccessTokens(apiUrl: string, clientId: string, clientSecret: string) { export function checkAccessTokens(apiUrl: string, clientId: string, clientSecret: string) {
...@@ -76,3 +77,7 @@ export class LocalStorageCart { ...@@ -76,3 +77,7 @@ export class LocalStorageCart {
localStorage.setItem(LocalStorageCart.LS_KEY, JSON.stringify(updatedCartItems)); localStorage.setItem(LocalStorageCart.LS_KEY, JSON.stringify(updatedCartItems));
} }
} }
export const canAddToCart = (accession: Accession) => {
return accession.historic !== true && accession.available !== false && accession.institute.allowMaterialRequests === true;
}
Markdown is supported
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