From bb22cac6964777aecdc8ee263c0d263999b1540b Mon Sep 17 00:00:00 2001 From: anuveyatsu Date: Mon, 15 Jun 2020 15:53:12 +0600 Subject: [PATCH] [resource page][m]: initially working resource page with support of datastore and non-datastore resources. --- components/resource/About.tsx | 38 +++ components/resource/DataExplorer.tsx | 9 + components/resource/DataView.tsx | 9 + mocks/index.js | 42 +++- package.json | 4 +- pages/[org]/[dataset]/r/[resource]/index.tsx | 58 +++++ yarn.lock | 252 ++++++++++++++++++- 7 files changed, 402 insertions(+), 10 deletions(-) create mode 100644 components/resource/About.tsx create mode 100644 components/resource/DataExplorer.tsx create mode 100644 components/resource/DataView.tsx create mode 100644 pages/[org]/[dataset]/r/[resource]/index.tsx diff --git a/components/resource/About.tsx b/components/resource/About.tsx new file mode 100644 index 00000000..a0b8ea53 --- /dev/null +++ b/components/resource/About.tsx @@ -0,0 +1,38 @@ +import Link from 'next/link' + +export default function About({ resource }) { + return ( + <> + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTitleDescriptionFormatSizeCreatedUpdatedDownload
{ resource.name || resource.id }{ resource.title || '' }{ resource.description || '' }{ resource.format }{ resource.size }{ resource.created }{ resource.last_modified || '' } + + { resource.format } + +
+ + ) +} diff --git a/components/resource/DataExplorer.tsx b/components/resource/DataExplorer.tsx new file mode 100644 index 00000000..df921824 --- /dev/null +++ b/components/resource/DataExplorer.tsx @@ -0,0 +1,9 @@ +import Link from 'next/link' + +export default function DataExplorer({ resource }) { + return ( + <> + {JSON.stringify(resource, null, 2)} + + ) +} diff --git a/components/resource/DataView.tsx b/components/resource/DataView.tsx new file mode 100644 index 00000000..660b8b1d --- /dev/null +++ b/components/resource/DataView.tsx @@ -0,0 +1,9 @@ +import Link from 'next/link' + +export default function DataView({ resource }) { + return ( + <> + {JSON.stringify(resource, null, 2)} + + ) +} diff --git a/mocks/index.js b/mocks/index.js index 1fcddbdf..9202ea0c 100644 --- a/mocks/index.js +++ b/mocks/index.js @@ -7,12 +7,13 @@ const gdp = { "resources": [ { "name": "gdp", + "id": "gdp", "title": "GDP data", "format": "csv", "created": "2019-03-07T12:00:36.273495", "last_modified": "2020-05-07T12:00:36.273495", "datastore_active": false, - "url": "https://raw.githubusercontent.com/datasets/gdp/master/data/gdp.csv" + "url": "http://mock.filestore/gdp.csv" } ], "organization": { @@ -33,12 +34,13 @@ const population = { "resources": [ { "name": "population", + "id": "population", "title": "Population data", "format": "csv", "created": "2019-03-07T12:00:36.273495", "last_modified": "2020-05-07T12:00:36.273495", "datastore_active": true, - "url": "https://raw.githubusercontent.com/datasets/gdp/master/data/gdp.csv" + "url": "http://mock.filestore/population.csv" } ], "organization": { @@ -101,4 +103,40 @@ module.exports.initMocks = function() { "success": true, "result": population }) + + // "datastore_search" mocks + nock('http://mock.ckan/api/3/action', {'encodedQueryParams':true}) + .persist() + .get('/datastore_search?resource_id=population') + .reply(200, { + "success": true, + "result": { + "records": [ + { + "Country Code": "ARB", + "Country Name": "Arab World", + "Value": 92197753, + "Year": 1960 + }, + { + "Country Code": "ARB", + "Country Name": "Arab World", + "Value": 94724510, + "Year": 1961 + }, + { + "Country Code": "ARB", + "Country Name": "Arab World", + "Value": 97334442, + "Year": 1962 + } + ] + } + }) + + // Filestore mocks + nock('http://mock.filestore', {'encodedQueryParams':true}) + .persist() + .get('/gdp.csv') + .reply(200, 'a,b,c\n1,2,3\n4,5,6\n') } diff --git a/package.json b/package.json index c71b615c..05c75eee 100644 --- a/package.json +++ b/package.json @@ -12,12 +12,14 @@ }, "dependencies": { "bytes": "^3.1.0", + "data.js": "^0.12.11", "markdown-it": "^11.0.0", "next": "9.4.2", "querystring": "^0.2.0", "react": "16.13.1", "react-dom": "16.13.1", - "slugify": "^1.4.0" + "slugify": "^1.4.0", + "stream-to-array": "^2.3.0" }, "devDependencies": { "@testing-library/jest-dom": "^5.8.0", diff --git a/pages/[org]/[dataset]/r/[resource]/index.tsx b/pages/[org]/[dataset]/r/[resource]/index.tsx new file mode 100644 index 00000000..0105196f --- /dev/null +++ b/pages/[org]/[dataset]/r/[resource]/index.tsx @@ -0,0 +1,58 @@ +import { GetServerSideProps } from 'next' +import { open } from 'data.js' +const toArray = require('stream-to-array') +import config from '../../../../../config' +import utils from '../../../../../utils' +import Head from 'next/head' +import Nav from '../../../../../components/Nav' +import About from '../../../../../components/resource/About' +import DataExplorer from '../../../../../components/resource/DataExplorer' +import DataView from '../../../../../components/resource/DataView' + +function Resource({ resource }) { + return ( + <> + + Portal | {resource.title || resource.name} + + +