Commit e2e67b03 authored by Matija Obreza's avatar Matija Obreza

Fix: Partner, Descriptor list and Vocabulary are double-loaded (onClick)

parent 749ddc98
import * as React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { log } from 'utilities/debug';
import Dataset from 'model/catalog/Dataset';
import Descriptor from 'model/catalog/Descriptor';
import DescriptorList from 'model/catalog/DescriptorList';
import { loadDescriptorList } from 'descriptorlists/actions/editor';
import Partner from 'model/genesys/Partner';
import { loadPartner } from 'partners/actions/dashboard';
import Vocabulary from 'model/vocabulary/Vocabulary';
import { loadVocabulary } from 'vocabulary/actions/public';
import Crop from 'model/genesys/Crop';
......@@ -85,28 +79,21 @@ function DescriptorLink({
interface IDescriptorListLink extends React.Props<any> {
to: DescriptorList;
edit?: boolean;
loadDescriptorList: any;
}
const DescriptorListLink_ = ({ to: descriptorList, edit = false, children, loadDescriptorList }: IDescriptorListLink) => {
const clickMe = (e) => {
log('You clicked me!', descriptorList);
loadDescriptorList(descriptorList.uuid);
};
const DescriptorListLink = ({ to: descriptorList, edit = false, children }: IDescriptorListLink) => {
if (edit) {
return (
<Link to={ `/dashboard/descriptorlists/${descriptorList.uuid}/edit` } onClick={ clickMe }>{ children || <Markdown basic source={ descriptorList.title } /> }</Link>
<Link to={ `/dashboard/descriptorlists/${descriptorList.uuid}/edit` }>{ children || <Markdown basic source={ descriptorList.title } /> }</Link>
);
} else {
return (
<Link to={ `/descriptorlists/${descriptorList.uuid}` } onClick={ clickMe }>{ children || <Markdown basic source={ descriptorList.title } /> }</Link>
<Link to={ `/descriptorlists/${descriptorList.uuid}` }>{ children || <Markdown basic source={ descriptorList.title } /> }</Link>
);
}
};
const DescriptorListLink = connect(({}) => ({}), (dispatch) => bindActionCreators({loadDescriptorList}, dispatch)) (DescriptorListLink_);
interface IAccessionLinkProps extends React.Props<any> {
apiUrl: string;
accessionRef: AccessionRef;
......@@ -141,43 +128,31 @@ const ServerLink = ({link, children, classes = ''}) =>
const FaoWiewsLink = ({wiewsCode, children}) =>
<ExternalLink link={ `http://www.fao.org/wiews/data/organizations/en/?instcode=${wiewsCode}` }>{ children ? children : wiewsCode }</ExternalLink>;
const PartnerLink_ = ({ to: partner, edit = false, children, loadPartner }: { to: Partner, edit?: boolean, children?: any } & any) => {
const clickMe = (e) => {
log('You clicked me!', partner);
loadPartner(partner.uuid);
};
const PartnerLink = ({ to: partner, edit = false, children }: { to: Partner, edit?: boolean, children?: any } & any) => {
if (edit) {
return (
<Link to={ `/dashboard/partners/${partner.uuid}/edit` } onClick={ clickMe }>{ children || partner.name }</Link>
<Link to={ `/dashboard/partners/${partner.uuid}/edit` }>{ children || partner.name }</Link>
);
} else {
return (
<Link to={ `/partners/${partner.uuid}` } onClick={ clickMe }>{ children || partner.name }</Link>
<Link to={ `/partners/${partner.uuid}` }>{ children || partner.name }</Link>
);
}
};
const PartnerLink = connect(({}) => ({}), (dispatch) => bindActionCreators({loadPartner}, dispatch)) (PartnerLink_);
const VocabularyLink_ = ({ to: vocabulary, edit = false, children, loadVocabulary }: { to: Vocabulary, edit?: boolean, loadVocabulary: (uuid: string) => Promise<Vocabulary>, children?: any } & any) => {
const clickMe = (e) => {
log('You clicked me!', vocabulary);
loadVocabulary(vocabulary.uuid);
};
const VocabularyLink = ({ to: vocabulary, edit = false, children }: { to: Vocabulary, edit?: boolean, children?: any } & any) => {
if (edit) {
return (
<Link to={ `/dashboard/vocabulary/${vocabulary.uuid}/edit` } onClick={ clickMe }>{ children || vocabulary.name }</Link>
<Link to={ `/dashboard/vocabulary/${vocabulary.uuid}/edit` }>{ children || vocabulary.name }</Link>
);
} else {
return (
<Link to={ `/vocabulary/${vocabulary.uuid}` } onClick={ clickMe }>{ children || vocabulary.name }</Link>
<Link to={ `/vocabulary/${vocabulary.uuid}` }>{ children || vocabulary.name }</Link>
);
}
};
const VocabularyLink = connect(({}) => ({}), (dispatch) => bindActionCreators({loadVocabulary}, dispatch)) (VocabularyLink_);
interface ICropLinkProps extends React.Props<any> {
code: string;
......@@ -192,14 +167,10 @@ class CropLink1 extends React.Component<ICropLinkProps, any> {
const crop: Crop = crops ? crops.get(code) : null;
const clickMe = (e) => {
log('You clicked me!', crop);
};
if (crop) {
if (edit) {
return (
<Link to={ `/dashboard/crops/${crop.shortName}/edit` } onClick={ clickMe }>{ children || crop.name }</Link>
<Link to={ `/dashboard/crops/${crop.shortName}/edit` }>{ children || crop.name }</Link>
);
} else {
return (
......
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