diff --git a/examples/catalog/components/home/Footer.tsx b/examples/catalog/components/home/Footer.tsx index c4a3a43b..9fa74148 100644 --- a/examples/catalog/components/home/Footer.tsx +++ b/examples/catalog/components/home/Footer.tsx @@ -9,10 +9,8 @@ const Footer: React.FC = () => { { name: 'GitHub', href: 'https://github.com/datopian/portal.js', - icon: ( - // eslint-disable-line - props - ) => ( + // eslint-disable-next-line + icon: (props) => ( { + const { loading, error, data } = useQuery(GET_STATS_QUERY, { + variables: {}, + // 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 ; + if (loading) return
Loading
; + + const stats = [ + { name: 'Datasets', stat: data.datasets.result.count }, + { + name: 'Organizations', + stat: data.orgs.result ? data.orgs.result.length : 0, + }, + { + name: 'Groups', + stat: data.groups.result ? data.groups.result.length : 0, + }, + ]; + + return ( +
+

+ DataHub Stats +

+
+ {stats.map((item) => ( +
+
+ {item.name} +
+
+ {item.stat} +
+
+ ))} +
+
+ ); +}; + +export default Stats; diff --git a/examples/catalog/graphql/queries.ts b/examples/catalog/graphql/queries.ts index c3425aa9..6f153260 100644 --- a/examples/catalog/graphql/queries.ts +++ b/examples/catalog/graphql/queries.ts @@ -79,6 +79,22 @@ export const GET_TOTAL_COUNT_QUERY = gql` } `; +export const GET_STATS_QUERY = gql` + query stats { + datasets @rest(type: "Search", path: "package_search?rows=0") { + result { + count + } + } + orgs @rest(type: "Search", path: "organization_list") { + result + } + groups @rest(type: "Search", path: "group_list") { + result + } + } +`; + export const GET_POSTS_QUERY = gql` query posts { posts @rest(type: "Posts", path: "", endpoint: "wordpress-posts") { diff --git a/examples/catalog/pages/index.tsx b/examples/catalog/pages/index.tsx index 118aedab..139a23e3 100644 --- a/examples/catalog/pages/index.tsx +++ b/examples/catalog/pages/index.tsx @@ -8,6 +8,7 @@ import useTranslation from 'next-translate/useTranslation'; import NavBar from '../components/home/Nav'; import Hero from '../components/home/Hero'; import Footer from '../components/home/Footer'; +import Stats from '../components/home/Stats'; const Home: React.FC<{ locale: any; locales: any }> = ({ locale, @@ -23,6 +24,7 @@ const Home: React.FC<{ locale: any; locales: any }> = ({ +