datahub/components/home/Recent.tsx
Gift Egwuenu d9b5c4ddbd
[tests][m]: Setup Integration Tests with Cypress (#26).
* [cypress][s]-setup-integration=with-cypress
* [fix][s]- fix typescript bug 'All files must be modules when the '--isolatedModules' flag is provided' by adding an 'export {}' to all test files
* Fixes of cypress tests
* Use yarn everywhere not npm

Co-authored-by: Abhishek Gahlot <me@abhishek.it>
2020-07-17 17:16:26 +02:00

72 lines
1.9 KiB
TypeScript

import Link from 'next/link';
import ErrorMessage from '../Error';
import { useQuery } from '@apollo/react-hooks';
import gql from 'graphql-tag';
export const QUERY = gql`
query search($q: String, $sort: String, $rows: Int) {
search(q: $q, sort: $sort, rows: $rows)
@rest(type: "Search", path: "package_search?{args}") {
result {
results {
name
title
organization {
name
title
description
}
}
}
}
}
`;
function Recent() {
const { loading, error, data } = useQuery(QUERY, {
variables: {
sort: 'metadata_created desc',
rows: 3,
},
// Setting this value to true will make the component rerender when
// the "networkStatus" changes, so we are able to know if it is fetching
// more data
notifyOnNetworkStatusChange: true,
});
if (error) return <ErrorMessage message="Error loading search results." />;
if (loading) return <div>Loading</div>;
const { result } = data.search;
return (
<section className="my-10 mx-4 lg:my-20">
<h1 className="text-2xl font-thin mb-4">Recent Datasets</h1>
<div className="recent flex flex-col lg:flex-row">
{result.results.map((dataset, index) => (
<div
key={index}
className="border px-4 mb-4 mr-3 border-gray-100 w-5/6 shadow-sm"
>
<h1 className="text-2xl font-thin">{dataset.title}</h1>
<p className="text-gray-500">
{dataset.organization && dataset.organization.description}
</p>
<Link
href={`/@${
dataset.organization ? dataset.organization.name : 'dataset'
}/${dataset.name}`}
>
<a className="pt-3 flex justify-end text-orange-500">
View Dataset
</a>
</Link>
</div>
))}
</div>
</section>
);
}
export default Recent;