From d0d2c0a72d4d35e1d1ea0d7a6dd0d8df1ce5e8f7 Mon Sep 17 00:00:00 2001 From: Alex Scott Date: Mon, 22 Mar 2021 19:30:46 +0100 Subject: [PATCH] Adding organizationEndpoint as a property for organizations. --- src/components/Organization/index.jsx | 20 +++++++++++++++---- .../PublisherDatasetCountByName/index.jsx | 1 - src/components/PublisherList/index.jsx | 4 +++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/components/Organization/index.jsx b/src/components/Organization/index.jsx index 35b67b99..ff78568b 100644 --- a/src/components/Organization/index.jsx +++ b/src/components/Organization/index.jsx @@ -5,15 +5,26 @@ import PublisherDatasetCountByName from "../PublisherDatasetCountByName"; import axios from 'axios'; function Organization(props) { - const { name, description, imageUrl, searchUrl, alignment} = props; + const { name, + description, + imageUrl, + searchUrl, + alignment, + organizationEndpoint} = props; + const image = {name; const link = searchUrl ? searchUrl : `search/?publisher__name=${name}`; const [dataObj, setDataObj] = useState(); const fetchData = async () => { - axios.get('http://demo.getdkan.org/data.json') - .then(res => (setDataObj(res.data))) - .catch(err => (console.log("Error, check URL/Cors.", err))); + const endpoint = organizationEndpoint ? organizationEndpoint.replace("api/1", "data.json") : null; + if (endpoint) { + axios.get(endpoint) + .then(res => (setDataObj(res.data))) + .catch(err => (console.log("Error, check URL/Cors.", err))); + } else { + console.log("No search endpoint defined for Organization/s, so no dataset info available."); + } }; useEffect(() => { @@ -69,6 +80,7 @@ Organization.propTypes = { description: PropTypes.string, imageUrl: PropTypes.string, searchUrl: PropTypes.string, + organizationEndpoint: PropTypes.string, }; export default Organization; diff --git a/src/components/PublisherDatasetCountByName/index.jsx b/src/components/PublisherDatasetCountByName/index.jsx index 27a87db7..8626eae6 100644 --- a/src/components/PublisherDatasetCountByName/index.jsx +++ b/src/components/PublisherDatasetCountByName/index.jsx @@ -18,7 +18,6 @@ const PublisherDatasetCountByName = (props) => { ); }; - export default PublisherDatasetCountByName; PublisherDatasetCountByName.propTypes = { diff --git a/src/components/PublisherList/index.jsx b/src/components/PublisherList/index.jsx index c7b12146..0e2ae376 100644 --- a/src/components/PublisherList/index.jsx +++ b/src/components/PublisherList/index.jsx @@ -4,7 +4,7 @@ import Organization from '../Organization'; function PublisherList(props) { const { - items, className, + items, className, organizationEndpoint } = props; let content = (
); @@ -15,6 +15,7 @@ function PublisherList(props) { key={item.identifier} imageUrl={item.imageUrl} description={item.description} + organizationEndpoint={organizationEndpoint} searchUrl={item.searchUrl} alignment={item.alignment} /> @@ -40,6 +41,7 @@ PublisherList.propTypes = { identifier: PropTypes.string, imageUrl: PropTypes.string, searchUrl: PropTypes.string, + organizationEndpoint: PropTypes.string, })).isRequired, className: PropTypes.string, };