Skip to content

Commit

Permalink
Update an Organization so that it will accept a component with a
Browse files Browse the repository at this point in the history
dataset count, and query and endpoint for count data.
  • Loading branch information
Alex Scott committed Mar 22, 2021
1 parent fbaf6d9 commit 052a3bd
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/components/Organization/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ import PublisherDatasetCountByName from "../PublisherDatasetCountByName";
import axios from 'axios';

function Organization(props) {
const { name, description, imageUrl, searchUrl, alignment, datasetCount } = props;
const { name, description, imageUrl, searchUrl, alignment} = props;
const image = <img alt={name || 'Organization Image'} src={imageUrl} />;
const link = searchUrl ? searchUrl : `search/?publisher__name=${name}`;

const [posts, setPosts] = useState();
const [dataObj, setDataObj] = useState();

const fetchData = async () => {
const { data } = await axios.get('http://demo.getdkan.org/data.json');
console.log(data);
console.log("Name", name);
setPosts(data);
axios.get('http://demo.getdkan.org/data.json')
.then(res => (setDataObj(res.data)))
.catch(err => (console.log("Error, check URL/Cors.", err)));
};

useEffect(() => {
Expand All @@ -36,21 +34,24 @@ function Organization(props) {
</div>
)}

{posts && posts.dataset !== 'undefined' ? countDatasetsByName("State Economic Council", posts.dataset) : null}

<PublisherDatasetCountByName datasetCount={datasetCount} />
{dataObj && dataObj.dataset !== 'undefined' ?
<PublisherDatasetCountByName
name={name}
datasetCount={
countDatasetsByName(name, dataObj.dataset)
} /> :
<PublisherDatasetCountByName name={name} />
}
</div>
);
}

export const countDatasetsByName = (publisher, datasets) => {
// console.log("datasets", datasets);
// return "foobar";
const publishers = datasets.map((data, index, arr) => {return data.publisher; });
const result = publishers.filter((p) => {return p.name === publisher;})
console.log("RES: ", result);
const result = publishers.filter((p) => {return p.name === publisher;});
if (typeof result !== 'undefined' && result.length) {
return result.length;

}
return null;
};
Expand All @@ -64,7 +65,6 @@ Organization.defaultProps = {

Organization.propTypes = {
alignment: PropTypes.string,
datasetCount: PropTypes.string,
name: PropTypes.string,
description: PropTypes.string,
imageUrl: PropTypes.string,
Expand Down

0 comments on commit 052a3bd

Please sign in to comment.