diff --git a/components/resource/About.tsx b/components/resource/About.tsx
index c750e3e7..7caa9765 100644
--- a/components/resource/About.tsx
+++ b/components/resource/About.tsx
@@ -4,18 +4,20 @@ import { NetworkStatus } from 'apollo-client';
import { useQuery } from '@apollo/react-hooks';
import gql from 'graphql-tag';
-export const QUERY = gql`
- query dataset($id: String!) {
- dataset(id: $id) {
+const QUERY = gql`
+ query dataset($id: String) {
+ dataset(id: $id) @rest(type: "Response", path: "package_show?{args}") {
result {
resources {
name
id
- url
- format
title
+ description
+ format
+ size
created
last_modified
+ url
}
}
}
@@ -35,7 +37,9 @@ export default function About({ variables }) {
if (loading) return
Loading
;
const { result } = data.dataset;
- const resource = result.resources[0];
+ const resource = result.resources.find(
+ (item) => item.name === variables.resource
+ );
return (
<>
@@ -61,11 +65,12 @@ export default function About({ variables }) {
| {resource.created} |
{resource.last_modified || ''} |
-
-
- {resource.format}
-
-
+
+ {resource.format}
+
|
diff --git a/components/resource/DataExplorer.tsx b/components/resource/DataExplorer.tsx
index ee35308d..5fdf4363 100644
--- a/components/resource/DataExplorer.tsx
+++ b/components/resource/DataExplorer.tsx
@@ -4,18 +4,20 @@ import { NetworkStatus } from 'apollo-client';
import { useQuery } from '@apollo/react-hooks';
import gql from 'graphql-tag';
-export const QUERY = gql`
- query dataset($id: String!) {
- dataset(id: $id) {
+const QUERY = gql`
+ query dataset($id: String) {
+ dataset(id: $id) @rest(type: "Response", path: "package_show?{args}") {
result {
resources {
name
id
- url
- format
title
+ description
+ format
+ size
created
last_modified
+ url
}
}
}
@@ -35,7 +37,9 @@ export default function DataExplorer({ variables }) {
if (loading) return Loading
;
const { result } = data.dataset;
- const resource = result.resources[0];
+ const resource = result.resources.find(
+ (item) => item.name === variables.resource
+ );
return <>{JSON.stringify(resource)}>;
}
diff --git a/pages/[org]/[dataset]/r/[resource]/index.tsx b/pages/[org]/[dataset]/r/[resource]/index.tsx
index 39b893d5..8fe092db 100644
--- a/pages/[org]/[dataset]/r/[resource]/index.tsx
+++ b/pages/[org]/[dataset]/r/[resource]/index.tsx
@@ -9,12 +9,19 @@ import About from '../../../../../components/resource/About';
import DataExplorer from '../../../../../components/resource/DataExplorer';
const QUERY = gql`
- query dataset($id: String!) {
- dataset(id: $id) {
+ query dataset($id: String) {
+ dataset(id: $id) @rest(type: "Response", path: "package_show?{args}") {
result {
resources {
name
+ id
title
+ description
+ format
+ size
+ created
+ last_modified
+ url
}
}
}
@@ -22,24 +29,24 @@ const QUERY = gql`
`;
function Resource({ variables }) {
- const {
- data: {
- dataset: { result },
- },
- } = useQuery(QUERY, { variables });
+ const { data, loading } = useQuery(QUERY, { variables });
+ if (loading) return Loading
;
+ const result = data.dataset.result;
+ // Find right resource
+ const resource = result.resources.find(
+ (item) => item.name === variables.resource
+ );
return (
<>
-
- Portal | {result.resources[0].title || result.resources[0].name}
-
+ Portal | {resource.title || resource.name}
- {result.resources[0].title || result.resources[0].name}
+ {resource.title || resource.name}
@@ -55,7 +62,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
resource: context.query.resource,
};
- const apolloResponse = await apolloClient.query({
+ await apolloClient.query({
query: QUERY,
variables,
});