Skip to content

Commit

Permalink
Adding organizationEndpoint as a property for organizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Scott committed Mar 24, 2021
1 parent 06ce410 commit da572b3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
20 changes: 16 additions & 4 deletions src/components/Organization/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <img alt={name || 'Organization Image'} src={imageUrl} />;
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(() => {
Expand Down Expand Up @@ -69,6 +80,7 @@ Organization.propTypes = {
description: PropTypes.string,
imageUrl: PropTypes.string,
searchUrl: PropTypes.string,
organizationEndpoint: PropTypes.string,
};

export default Organization;
1 change: 0 additions & 1 deletion src/components/PublisherDatasetCountByName/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const PublisherDatasetCountByName = (props) => {
);
};


export default PublisherDatasetCountByName;

PublisherDatasetCountByName.propTypes = {
Expand Down
4 changes: 3 additions & 1 deletion src/components/PublisherList/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Organization from '../Organization';

function PublisherList(props) {
const {
items, className,
items, className, organizationEndpoint
} = props;
let content = (<div />);

Expand All @@ -15,6 +15,7 @@ function PublisherList(props) {
key={item.identifier}
imageUrl={item.imageUrl}
description={item.description}
organizationEndpoint={organizationEndpoint}
searchUrl={item.searchUrl}
alignment={item.alignment}
/>
Expand All @@ -40,6 +41,7 @@ PublisherList.propTypes = {
identifier: PropTypes.string,
imageUrl: PropTypes.string,
searchUrl: PropTypes.string,
organizationEndpoint: PropTypes.string,
})).isRequired,
className: PropTypes.string,
};
Expand Down

0 comments on commit da572b3

Please sign in to comment.