[apollo][xl]: mocked graphql setup + search page working from apollo now.
This commit is contained in:
parent
f0d1bc0d3b
commit
dfd5efa961
@ -35,19 +35,20 @@ export default function Nav() {
|
|||||||
Search
|
Search
|
||||||
</a>
|
</a>
|
||||||
</Link>
|
</Link>
|
||||||
<Link href="http://tech.datopian.com/frontend/">
|
<a
|
||||||
<a
|
href="http://tech.datopian.com/frontend/"
|
||||||
className="block mt-4 lg:inline-block lg:mt-0 text-gray-700 hover:text-black mr-6"
|
className="block mt-4 lg:inline-block lg:mt-0 text-gray-700 hover:text-black mr-6"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
>
|
>
|
||||||
Docs
|
Docs
|
||||||
</a>
|
</a>
|
||||||
</Link>
|
<a
|
||||||
<Link href="https://github.com/datopian/portal">
|
href="https://github.com/datopian/portal"
|
||||||
<a className="inline-block text-sm px-4 py-2 leading-none border rounded text-white bg-black border-black hover:border-gray-700 hover:text-gray-700 hover:bg-white mt-4 lg:mt-0">
|
className="inline-block text-sm px-4 py-2 leading-none border rounded text-white bg-black border-black hover:border-gray-700 hover:text-gray-700 hover:bg-white mt-4 lg:mt-0"
|
||||||
GitHub
|
target="_blank"
|
||||||
</a>
|
>
|
||||||
</Link>
|
GitHub
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
);
|
);
|
||||||
|
|||||||
15
components/search/Error.tsx
Normal file
15
components/search/Error.tsx
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
export default function ErrorMessage({ message }) {
|
||||||
|
return (
|
||||||
|
<aside>
|
||||||
|
{message}
|
||||||
|
<style jsx>{`
|
||||||
|
aside {
|
||||||
|
padding: 1.5em;
|
||||||
|
font-size: 14px;
|
||||||
|
color: white;
|
||||||
|
background-color: red;
|
||||||
|
}
|
||||||
|
`}</style>
|
||||||
|
</aside>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -2,9 +2,9 @@ import { useState } from 'react';
|
|||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
|
||||||
export default function Input({ query }) {
|
export default function Input() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [q, setQ] = useState(query.q);
|
const [q, setQ] = useState(router.query.q);
|
||||||
|
|
||||||
const handleChange = (event) => {
|
const handleChange = (event) => {
|
||||||
setQ(event.target.value);
|
setQ(event.target.value);
|
||||||
|
|||||||
@ -25,7 +25,9 @@ export default function Item({ datapackage }) {
|
|||||||
: 'dataset'}
|
: 'dataset'}
|
||||||
</a>
|
</a>
|
||||||
</Link>
|
</Link>
|
||||||
<div className="leading-relaxed mt-2">{datapackage.description}</div>
|
<div className="leading-relaxed mt-2">
|
||||||
|
{datapackage.description || datapackage.notes}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,19 +1,33 @@
|
|||||||
import Item from './Item';
|
import Item from './Item';
|
||||||
|
import ErrorMessage from './Error';
|
||||||
|
import { NetworkStatus } from 'apollo-client';
|
||||||
import { useQuery } from '@apollo/react-hooks';
|
import { useQuery } from '@apollo/react-hooks';
|
||||||
import gql from 'graphql-tag';
|
import gql from 'graphql-tag';
|
||||||
|
|
||||||
export const DEFAULT_SEARCH_QUERY = gql`
|
export const DEFAULT_SEARCH_QUERY = gql`
|
||||||
search($query: SearchQuery!) {
|
query search($query: SearchQuery!) {
|
||||||
result {
|
search(query: $query) {
|
||||||
results
|
result {
|
||||||
|
results {
|
||||||
|
name
|
||||||
|
title
|
||||||
|
notes
|
||||||
|
organization {
|
||||||
|
name
|
||||||
|
title
|
||||||
|
description
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default function List() {
|
export default function List({ variables }) {
|
||||||
const { loading, error, data, fetchMore, networkStatus } = useQuery(
|
const { loading, error, data, fetchMore, networkStatus } = useQuery(
|
||||||
DEFAULT_SEARCH_QUERY,
|
DEFAULT_SEARCH_QUERY,
|
||||||
{
|
{
|
||||||
|
variables,
|
||||||
// Setting this value to true will make the component rerender when
|
// Setting this value to true will make the component rerender when
|
||||||
// the "networkStatus" changes, so we are able to know if it is fetching
|
// the "networkStatus" changes, so we are able to know if it is fetching
|
||||||
// more data
|
// more data
|
||||||
@ -24,12 +38,11 @@ export default function List() {
|
|||||||
if (error) return <ErrorMessage message="Error loading posts." />;
|
if (error) return <ErrorMessage message="Error loading posts." />;
|
||||||
if (loading) return <div>Loading</div>;
|
if (loading) return <div>Loading</div>;
|
||||||
|
|
||||||
const { result } = data;
|
const { result } = data.search;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ul>
|
<ul>
|
||||||
{result.map((datapackage, index) => (
|
{result.results.map((pkg, index) => (
|
||||||
<Item datapackage={datapackage} key={index} />
|
<Item datapackage={pkg} key={index} />
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,7 +1,32 @@
|
|||||||
export default function Total({ total }) {
|
import { useQuery } from '@apollo/react-hooks';
|
||||||
|
import gql from 'graphql-tag';
|
||||||
|
|
||||||
|
export const GET_NUMBER_OF_DATASETS = gql`
|
||||||
|
query search($query: SearchQuery!) {
|
||||||
|
search(query: $query) {
|
||||||
|
result {
|
||||||
|
count
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default function Total({ variables }) {
|
||||||
|
const { loading, error, data } = useQuery(GET_NUMBER_OF_DATASETS, {
|
||||||
|
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 (loading) return <div>Loading</div>;
|
||||||
|
|
||||||
|
const { result } = data.search;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<h1 className="text-3xl font-semibold text-primary my-6 inline-block">
|
<h1 className="text-3xl font-semibold text-primary my-6 inline-block">
|
||||||
{total} results found
|
{result.count} results found
|
||||||
</h1>
|
</h1>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,154 +1,19 @@
|
|||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
|
import getConfig from 'next/config';
|
||||||
import { ApolloClient } from 'apollo-client';
|
import { ApolloClient } from 'apollo-client';
|
||||||
import { InMemoryCache } from 'apollo-cache-inmemory';
|
import { InMemoryCache } from 'apollo-cache-inmemory';
|
||||||
import { SchemaLink } from 'apollo-link-schema';
|
import { HttpLink } from 'apollo-link-http';
|
||||||
import { makeExecutableSchema } from 'graphql-tools';
|
|
||||||
|
|
||||||
let apolloClient;
|
let apolloClient;
|
||||||
|
|
||||||
const typeDefs = `
|
|
||||||
type Query {
|
|
||||||
search(query: SearchQuery!): Response!
|
|
||||||
}
|
|
||||||
|
|
||||||
type SearchQuery {
|
|
||||||
q: String!
|
|
||||||
fq: String!
|
|
||||||
sort: String!
|
|
||||||
rows: Int!
|
|
||||||
start: Int!
|
|
||||||
facet: String!
|
|
||||||
include_drafts: Boolean!
|
|
||||||
include_private: Boolean!
|
|
||||||
use_default_schema: Boolean!
|
|
||||||
}
|
|
||||||
|
|
||||||
type Response {
|
|
||||||
success: Boolean!
|
|
||||||
result: Result!
|
|
||||||
}
|
|
||||||
|
|
||||||
type Result {
|
|
||||||
count: Int!
|
|
||||||
sort: String!
|
|
||||||
facets: String!
|
|
||||||
search_facets: String!
|
|
||||||
results: [Package!]!
|
|
||||||
}
|
|
||||||
|
|
||||||
type Package {
|
|
||||||
name: String!
|
|
||||||
title: String!
|
|
||||||
notes: String!
|
|
||||||
resources: [Resource!]!
|
|
||||||
organization: Organization!
|
|
||||||
metadata_created: String!
|
|
||||||
metadata_modified: String!
|
|
||||||
}
|
|
||||||
|
|
||||||
type Resource {
|
|
||||||
name: String!
|
|
||||||
id: String!
|
|
||||||
title: String!
|
|
||||||
format: String!
|
|
||||||
created: String!
|
|
||||||
last_modified: String!
|
|
||||||
datastore_active: Boolean!
|
|
||||||
url: String!
|
|
||||||
}
|
|
||||||
|
|
||||||
type Organization {
|
|
||||||
name: String!
|
|
||||||
title: String!
|
|
||||||
description: String!
|
|
||||||
created: String!
|
|
||||||
image_url: String!
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const resolvers = {
|
|
||||||
Query: {
|
|
||||||
search: (parent, { query }) => ({
|
|
||||||
success: true,
|
|
||||||
result: {
|
|
||||||
count: 2,
|
|
||||||
sort: 'score desc, metadata_modified desc',
|
|
||||||
facets: {},
|
|
||||||
results: [
|
|
||||||
{
|
|
||||||
name: 'gdp',
|
|
||||||
title: 'Country, Regional and World GDP (Gross Domestic Product)',
|
|
||||||
notes:
|
|
||||||
'Country, regional and world GDP in current US Dollars ($). Regional means collections of countries e.g. Europe & Central Asia. Data is sourced from the World Bank and turned into a standard normalized CSV.',
|
|
||||||
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: 'http://mock.filestore/gdp.csv',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
organization: {
|
|
||||||
title: 'World Bank',
|
|
||||||
name: 'world-bank',
|
|
||||||
description:
|
|
||||||
'The World Bank is an international financial institution that provides loans and grants to the governments of poorer countries for the purpose of pursuing capital projects.',
|
|
||||||
created: '2019-03-07T11:51:13.758844',
|
|
||||||
image_url:
|
|
||||||
'https://github.com/datahq/frontend/raw/master/public/img/avatars/world-bank.jpg',
|
|
||||||
},
|
|
||||||
metadata_created: '2019-03-07T11:56:19.696257',
|
|
||||||
metadata_modified: '2019-03-07T12:03:58.817280',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'population',
|
|
||||||
title: 'World population data',
|
|
||||||
notes:
|
|
||||||
'Population figures for countries, regions (e.g. Asia) and the world. Data comes originally from World Bank and has been converted into standard CSV.',
|
|
||||||
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: 'http://mock.filestore/population.csv',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
organization: {
|
|
||||||
title: 'World Bank',
|
|
||||||
name: 'world-bank',
|
|
||||||
description:
|
|
||||||
'The World Bank is an international financial institution that provides loans and grants to the governments of poorer countries for the purpose of pursuing capital projects.',
|
|
||||||
created: '2019-03-07T11:51:13.758844',
|
|
||||||
image_url:
|
|
||||||
'https://github.com/datahq/frontend/raw/master/public/img/avatars/world-bank.jpg',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
search_facets: {},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const executableSchema = makeExecutableSchema({
|
|
||||||
typeDefs,
|
|
||||||
resolvers,
|
|
||||||
});
|
|
||||||
|
|
||||||
const link = new SchemaLink({ schema: executableSchema });
|
|
||||||
|
|
||||||
function createApolloClient() {
|
function createApolloClient() {
|
||||||
|
const { publicRuntimeConfig } = getConfig();
|
||||||
return new ApolloClient({
|
return new ApolloClient({
|
||||||
ssrMode: typeof window === 'undefined',
|
ssrMode: typeof window === 'undefined',
|
||||||
link,
|
link: new HttpLink({
|
||||||
|
uri: publicRuntimeConfig.graphqlEndpoint, // Server URL (must be absolute)
|
||||||
|
credentials: 'same-origin', // Additional fetch() options like `credentials` or `headers`
|
||||||
|
}),
|
||||||
cache: new InMemoryCache(),
|
cache: new InMemoryCache(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
30
mock/.gitignore
vendored
Normal file
30
mock/.gitignore
vendored
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
/.pnp
|
||||||
|
.pnp.js
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# next.js
|
||||||
|
/.next/
|
||||||
|
/out/
|
||||||
|
|
||||||
|
# production
|
||||||
|
/build
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# debug
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# local env files
|
||||||
|
.env.local
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
151
mock/index.js
Normal file
151
mock/index.js
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
const { GraphQLScalarType } = require('graphql');
|
||||||
|
const { ApolloServer } = require('apollo-server');
|
||||||
|
const { makeExecutableSchema } = require('graphql-tools');
|
||||||
|
const { importSchema } = require('graphql-import');
|
||||||
|
const typeDefs = `
|
||||||
|
type Query {
|
||||||
|
search(query: SearchQuery!): Response!
|
||||||
|
}
|
||||||
|
|
||||||
|
input SearchQuery {
|
||||||
|
q: String!
|
||||||
|
}
|
||||||
|
|
||||||
|
type Response {
|
||||||
|
success: Boolean!
|
||||||
|
result: Result!
|
||||||
|
}
|
||||||
|
|
||||||
|
type Result {
|
||||||
|
count: Int!
|
||||||
|
sort: String!
|
||||||
|
facets: String!
|
||||||
|
search_facets: String!
|
||||||
|
results: [Package!]!
|
||||||
|
}
|
||||||
|
|
||||||
|
type Package {
|
||||||
|
name: String!
|
||||||
|
title: String!
|
||||||
|
notes: String!
|
||||||
|
resources: [Resource!]!
|
||||||
|
organization: Organization!
|
||||||
|
metadata_created: String!
|
||||||
|
metadata_modified: String!
|
||||||
|
}
|
||||||
|
|
||||||
|
type Resource {
|
||||||
|
name: String!
|
||||||
|
id: String!
|
||||||
|
title: String!
|
||||||
|
format: String!
|
||||||
|
created: String!
|
||||||
|
last_modified: String!
|
||||||
|
datastore_active: Boolean!
|
||||||
|
url: String!
|
||||||
|
}
|
||||||
|
|
||||||
|
type Organization {
|
||||||
|
name: String!
|
||||||
|
title: String!
|
||||||
|
description: String!
|
||||||
|
created: String!
|
||||||
|
image_url: String!
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const resolvers = {
|
||||||
|
Query: {
|
||||||
|
search: (parent, { query }) => ({
|
||||||
|
success: true,
|
||||||
|
result: {
|
||||||
|
count: 2,
|
||||||
|
sort: 'score desc, metadata_modified desc',
|
||||||
|
facets: {},
|
||||||
|
results: [
|
||||||
|
{
|
||||||
|
name: 'gdp',
|
||||||
|
title: 'Country, Regional and World GDP (Gross Domestic Product)',
|
||||||
|
notes:
|
||||||
|
'Country, regional and world GDP in current US Dollars ($). Regional means collections of countries e.g. Europe & Central Asia. Data is sourced from the World Bank and turned into a standard normalized CSV.',
|
||||||
|
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: 'http://mock.filestore/gdp.csv',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
organization: {
|
||||||
|
title: 'World Bank',
|
||||||
|
name: 'world-bank',
|
||||||
|
description:
|
||||||
|
'The World Bank is an international financial institution that provides loans and grants to the governments of poorer countries for the purpose of pursuing capital projects.',
|
||||||
|
created: '2019-03-07T11:51:13.758844',
|
||||||
|
image_url:
|
||||||
|
'https://github.com/datahq/frontend/raw/master/public/img/avatars/world-bank.jpg',
|
||||||
|
},
|
||||||
|
metadata_created: '2019-03-07T11:56:19.696257',
|
||||||
|
metadata_modified: '2019-03-07T12:03:58.817280',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'population',
|
||||||
|
title: 'World population data',
|
||||||
|
notes:
|
||||||
|
'Population figures for countries, regions (e.g. Asia) and the world. Data comes originally from World Bank and has been converted into standard CSV.',
|
||||||
|
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: 'http://mock.filestore/population.csv',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
organization: {
|
||||||
|
title: 'World Bank',
|
||||||
|
name: 'world-bank',
|
||||||
|
description:
|
||||||
|
'The World Bank is an international financial institution that provides loans and grants to the governments of poorer countries for the purpose of pursuing capital projects.',
|
||||||
|
created: '2019-03-07T11:51:13.758844',
|
||||||
|
image_url:
|
||||||
|
'https://github.com/datahq/frontend/raw/master/public/img/avatars/world-bank.jpg',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
search_facets: {},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const schema = makeExecutableSchema({
|
||||||
|
typeDefs,
|
||||||
|
resolvers,
|
||||||
|
});
|
||||||
|
|
||||||
|
const server = new ApolloServer({
|
||||||
|
schema,
|
||||||
|
mocks: {
|
||||||
|
success: () => {
|
||||||
|
return new Date();
|
||||||
|
},
|
||||||
|
result: () => {
|
||||||
|
return {
|
||||||
|
firstName: 'Kouki',
|
||||||
|
lastName: 'Saito',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen().then(({ url }) => {
|
||||||
|
console.log(`🚀 Server ready at ${url}`);
|
||||||
|
});
|
||||||
3089
mock/package-lock.json
generated
Normal file
3089
mock/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
20
mock/package.json
Normal file
20
mock/package.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "mock",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "nodemon index.js",
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"apollo-server": "^2.15.0",
|
||||||
|
"graphql": "^15.1.0",
|
||||||
|
"graphql-import": "^1.0.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"nodemon": "^2.0.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
7
next.config.js
Normal file
7
next.config.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
module.exports = {
|
||||||
|
publicRuntimeConfig: {
|
||||||
|
graphqlEndpoint:
|
||||||
|
process.env.GRAPHQL_ENDPOINT ||
|
||||||
|
'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn',
|
||||||
|
},
|
||||||
|
};
|
||||||
@ -3,6 +3,9 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"mock": "npm start --prefix mock",
|
||||||
|
"dev-mock": "GRAPHQL_ENDPOINT=\"http://localhost:4000/\" run-p dev mock",
|
||||||
|
"postinstall": "npm install --prefix mock",
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
@ -42,6 +45,7 @@
|
|||||||
"lint-staged": ">=10",
|
"lint-staged": ">=10",
|
||||||
"nconf": "^0.10.0",
|
"nconf": "^0.10.0",
|
||||||
"nock": "^12.0.3",
|
"nock": "^12.0.3",
|
||||||
|
"npm-run-all": "^4.1.5",
|
||||||
"postcss-preset-env": "^6.7.0",
|
"postcss-preset-env": "^6.7.0",
|
||||||
"prettier": "2.0.5",
|
"prettier": "2.0.5",
|
||||||
"react-test-renderer": "^16.13.1",
|
"react-test-renderer": "^16.13.1",
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import Sort from '../components/search/Sort';
|
|||||||
import List, { DEFAULT_SEARCH_QUERY } from '../components/search/List';
|
import List, { DEFAULT_SEARCH_QUERY } from '../components/search/List';
|
||||||
import { initializeApollo } from '../lib/apolloClient';
|
import { initializeApollo } from '../lib/apolloClient';
|
||||||
|
|
||||||
function Search({ ckanResult, datapackages, query }) {
|
function Search({ variables }) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Head>
|
<Head>
|
||||||
@ -19,42 +19,35 @@ function Search({ ckanResult, datapackages, query }) {
|
|||||||
</Head>
|
</Head>
|
||||||
<Nav />
|
<Nav />
|
||||||
<main className="p-6">
|
<main className="p-6">
|
||||||
<Input query={query} />
|
<Input />
|
||||||
<Total total={ckanResult.count} />
|
<Total variables={variables} />
|
||||||
<Sort />
|
<Sort />
|
||||||
<List datapackages={datapackages} />
|
<List variables={variables} />
|
||||||
</main>
|
</main>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||||
|
const query = context.query || {};
|
||||||
|
const ckanQuery = utils.convertToCkanSearchQuery(query);
|
||||||
|
|
||||||
const apolloClient = initializeApollo();
|
const apolloClient = initializeApollo();
|
||||||
|
const variables = {
|
||||||
|
query: { q: ckanQuery.q || '' },
|
||||||
|
};
|
||||||
|
|
||||||
await apolloClient.query({
|
await apolloClient.query({
|
||||||
query: DEFAULT_SEARCH_QUERY,
|
query: DEFAULT_SEARCH_QUERY,
|
||||||
|
variables,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
initialApolloState: apolloClient.cache.extract(),
|
initialApolloState: apolloClient.cache.extract(),
|
||||||
|
variables,
|
||||||
},
|
},
|
||||||
unstable_revalidate: 1,
|
|
||||||
};
|
};
|
||||||
//
|
|
||||||
// const query = context.query || {};
|
|
||||||
// const ckanQuery = querystring.stringify(
|
|
||||||
// utils.convertToCkanSearchQuery(query)
|
|
||||||
// );
|
|
||||||
// const res = await fetch(
|
|
||||||
// `${config.get('DMS')}/api/3/action/package_search?${ckanQuery}`
|
|
||||||
// );
|
|
||||||
// const ckanResult = (await res.json()).result;
|
|
||||||
// const datapackages = ckanResult.results.map((item) =>
|
|
||||||
// utils.ckanToDataPackage(item)
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// return { props: { ckanResult, datapackages, query } };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Search;
|
export default Search;
|
||||||
|
|||||||
75
yarn.lock
75
yarn.lock
@ -3281,7 +3281,7 @@ cross-fetch@3.0.4:
|
|||||||
node-fetch "2.6.0"
|
node-fetch "2.6.0"
|
||||||
whatwg-fetch "3.0.0"
|
whatwg-fetch "3.0.0"
|
||||||
|
|
||||||
cross-spawn@^6.0.0:
|
cross-spawn@^6.0.0, cross-spawn@^6.0.5:
|
||||||
version "6.0.5"
|
version "6.0.5"
|
||||||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
|
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
|
||||||
integrity sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==
|
integrity sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==
|
||||||
@ -5859,6 +5859,16 @@ listr2@^2.1.0:
|
|||||||
rxjs "^6.5.5"
|
rxjs "^6.5.5"
|
||||||
through "^2.3.8"
|
through "^2.3.8"
|
||||||
|
|
||||||
|
load-json-file@^4.0.0:
|
||||||
|
version "4.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-4.0.0.tgz#2f5f45ab91e33216234fd53adab668eb4ec0993b"
|
||||||
|
integrity sha1-L19Fq5HjMhYjT9U62rZo607AmTs=
|
||||||
|
dependencies:
|
||||||
|
graceful-fs "^4.1.2"
|
||||||
|
parse-json "^4.0.0"
|
||||||
|
pify "^3.0.0"
|
||||||
|
strip-bom "^3.0.0"
|
||||||
|
|
||||||
loader-runner@^2.4.0:
|
loader-runner@^2.4.0:
|
||||||
version "2.4.0"
|
version "2.4.0"
|
||||||
resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-2.4.0.tgz#ed47066bfe534d7e84c4c7b9998c2a75607d9357"
|
resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-2.4.0.tgz#ed47066bfe534d7e84c4c7b9998c2a75607d9357"
|
||||||
@ -6082,6 +6092,11 @@ memory-fs@^0.5.0:
|
|||||||
errno "^0.1.3"
|
errno "^0.1.3"
|
||||||
readable-stream "^2.0.1"
|
readable-stream "^2.0.1"
|
||||||
|
|
||||||
|
memorystream@^0.3.1:
|
||||||
|
version "0.3.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/memorystream/-/memorystream-0.3.1.tgz#86d7090b30ce455d63fbae12dda51a47ddcaf9b2"
|
||||||
|
integrity sha1-htcJCzDORV1j+64S3aUaR93K+bI=
|
||||||
|
|
||||||
merge-stream@^2.0.0:
|
merge-stream@^2.0.0:
|
||||||
version "2.0.0"
|
version "2.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
|
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
|
||||||
@ -6489,7 +6504,7 @@ normalize-html-whitespace@1.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/normalize-html-whitespace/-/normalize-html-whitespace-1.0.0.tgz#5e3c8e192f1b06c3b9eee4b7e7f28854c7601e34"
|
resolved "https://registry.yarnpkg.com/normalize-html-whitespace/-/normalize-html-whitespace-1.0.0.tgz#5e3c8e192f1b06c3b9eee4b7e7f28854c7601e34"
|
||||||
integrity sha512-9ui7CGtOOlehQu0t/OhhlmDyc71mKVlv+4vF+me4iZLPrNtRL2xoquEdfZxasC/bdQi/Hr3iTrpyRKIG+ocabA==
|
integrity sha512-9ui7CGtOOlehQu0t/OhhlmDyc71mKVlv+4vF+me4iZLPrNtRL2xoquEdfZxasC/bdQi/Hr3iTrpyRKIG+ocabA==
|
||||||
|
|
||||||
normalize-package-data@^2.5.0:
|
normalize-package-data@^2.3.2, normalize-package-data@^2.5.0:
|
||||||
version "2.5.0"
|
version "2.5.0"
|
||||||
resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.5.0.tgz#e66db1838b200c1dfc233225d12cb36520e234a8"
|
resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.5.0.tgz#e66db1838b200c1dfc233225d12cb36520e234a8"
|
||||||
integrity sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==
|
integrity sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==
|
||||||
@ -6536,6 +6551,21 @@ normalize.css@^8.0.1:
|
|||||||
resolved "https://registry.yarnpkg.com/normalize.css/-/normalize.css-8.0.1.tgz#9b98a208738b9cc2634caacbc42d131c97487bf3"
|
resolved "https://registry.yarnpkg.com/normalize.css/-/normalize.css-8.0.1.tgz#9b98a208738b9cc2634caacbc42d131c97487bf3"
|
||||||
integrity sha512-qizSNPO93t1YUuUhP22btGOo3chcvDFqFaj2TRybP0DMxkHOCTYwp3n34fel4a31ORXy4m1Xq0Gyqpb5m33qIg==
|
integrity sha512-qizSNPO93t1YUuUhP22btGOo3chcvDFqFaj2TRybP0DMxkHOCTYwp3n34fel4a31ORXy4m1Xq0Gyqpb5m33qIg==
|
||||||
|
|
||||||
|
npm-run-all@^4.1.5:
|
||||||
|
version "4.1.5"
|
||||||
|
resolved "https://registry.yarnpkg.com/npm-run-all/-/npm-run-all-4.1.5.tgz#04476202a15ee0e2e214080861bff12a51d98fba"
|
||||||
|
integrity sha512-Oo82gJDAVcaMdi3nuoKFavkIHBRVqQ1qvMb+9LHk/cF4P6B2m8aP04hGf7oL6wZ9BuGwX1onlLhpuoofSyoQDQ==
|
||||||
|
dependencies:
|
||||||
|
ansi-styles "^3.2.1"
|
||||||
|
chalk "^2.4.1"
|
||||||
|
cross-spawn "^6.0.5"
|
||||||
|
memorystream "^0.3.1"
|
||||||
|
minimatch "^3.0.4"
|
||||||
|
pidtree "^0.3.0"
|
||||||
|
read-pkg "^3.0.0"
|
||||||
|
shell-quote "^1.6.1"
|
||||||
|
string.prototype.padend "^3.0.0"
|
||||||
|
|
||||||
npm-run-path@^2.0.0:
|
npm-run-path@^2.0.0:
|
||||||
version "2.0.2"
|
version "2.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f"
|
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f"
|
||||||
@ -6888,6 +6918,13 @@ path-parse@^1.0.6:
|
|||||||
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c"
|
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c"
|
||||||
integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==
|
integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==
|
||||||
|
|
||||||
|
path-type@^3.0.0:
|
||||||
|
version "3.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/path-type/-/path-type-3.0.0.tgz#cef31dc8e0a1a3bb0d105c0cd97cf3bf47f4e36f"
|
||||||
|
integrity sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg==
|
||||||
|
dependencies:
|
||||||
|
pify "^3.0.0"
|
||||||
|
|
||||||
path-type@^4.0.0:
|
path-type@^4.0.0:
|
||||||
version "4.0.0"
|
version "4.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
|
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
|
||||||
@ -6914,6 +6951,16 @@ picomatch@^2.0.4, picomatch@^2.0.5, picomatch@^2.2.1:
|
|||||||
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.2.2.tgz#21f333e9b6b8eaff02468f5146ea406d345f4dad"
|
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.2.2.tgz#21f333e9b6b8eaff02468f5146ea406d345f4dad"
|
||||||
integrity sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==
|
integrity sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==
|
||||||
|
|
||||||
|
pidtree@^0.3.0:
|
||||||
|
version "0.3.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/pidtree/-/pidtree-0.3.1.tgz#ef09ac2cc0533df1f3250ccf2c4d366b0d12114a"
|
||||||
|
integrity sha512-qQbW94hLHEqCg7nhby4yRC7G2+jYHY4Rguc2bjw7Uug4GIJuu1tvf2uHaZv5Q8zdt+WKJ6qK1FOI6amaWUo5FA==
|
||||||
|
|
||||||
|
pify@^3.0.0:
|
||||||
|
version "3.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/pify/-/pify-3.0.0.tgz#e5a4acd2c101fdf3d9a4d07f0dbc4db49dd28176"
|
||||||
|
integrity sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=
|
||||||
|
|
||||||
pify@^4.0.1:
|
pify@^4.0.1:
|
||||||
version "4.0.1"
|
version "4.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/pify/-/pify-4.0.1.tgz#4b2cd25c50d598735c50292224fd8c6df41e3231"
|
resolved "https://registry.yarnpkg.com/pify/-/pify-4.0.1.tgz#4b2cd25c50d598735c50292224fd8c6df41e3231"
|
||||||
@ -7903,6 +7950,15 @@ read-pkg-up@^7.0.1:
|
|||||||
read-pkg "^5.2.0"
|
read-pkg "^5.2.0"
|
||||||
type-fest "^0.8.1"
|
type-fest "^0.8.1"
|
||||||
|
|
||||||
|
read-pkg@^3.0.0:
|
||||||
|
version "3.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-3.0.0.tgz#9cbc686978fee65d16c00e2b19c237fcf6e38389"
|
||||||
|
integrity sha1-nLxoaXj+5l0WwA4rGcI3/Pbjg4k=
|
||||||
|
dependencies:
|
||||||
|
load-json-file "^4.0.0"
|
||||||
|
normalize-package-data "^2.3.2"
|
||||||
|
path-type "^3.0.0"
|
||||||
|
|
||||||
read-pkg@^5.2.0:
|
read-pkg@^5.2.0:
|
||||||
version "5.2.0"
|
version "5.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-5.2.0.tgz#7bf295438ca5a33e56cd30e053b34ee7250c93cc"
|
resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-5.2.0.tgz#7bf295438ca5a33e56cd30e053b34ee7250c93cc"
|
||||||
@ -8463,7 +8519,7 @@ shebang-regex@^3.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
|
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
|
||||||
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
|
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
|
||||||
|
|
||||||
shell-quote@1.7.2:
|
shell-quote@1.7.2, shell-quote@^1.6.1:
|
||||||
version "1.7.2"
|
version "1.7.2"
|
||||||
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.7.2.tgz#67a7d02c76c9da24f99d20808fcaded0e0e04be2"
|
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.7.2.tgz#67a7d02c76c9da24f99d20808fcaded0e0e04be2"
|
||||||
integrity sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg==
|
integrity sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg==
|
||||||
@ -8798,6 +8854,14 @@ string-width@^4.1.0, string-width@^4.2.0:
|
|||||||
is-fullwidth-code-point "^3.0.0"
|
is-fullwidth-code-point "^3.0.0"
|
||||||
strip-ansi "^6.0.0"
|
strip-ansi "^6.0.0"
|
||||||
|
|
||||||
|
string.prototype.padend@^3.0.0:
|
||||||
|
version "3.1.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/string.prototype.padend/-/string.prototype.padend-3.1.0.tgz#dc08f57a8010dc5c153550318f67e13adbb72ac3"
|
||||||
|
integrity sha512-3aIv8Ffdp8EZj8iLwREGpQaUZiPyrWrpzMBHvkiSW/bK/EGve9np07Vwy7IJ5waydpGXzQZu/F8Oze2/IWkBaA==
|
||||||
|
dependencies:
|
||||||
|
define-properties "^1.1.3"
|
||||||
|
es-abstract "^1.17.0-next.1"
|
||||||
|
|
||||||
string.prototype.trimend@^1.0.0:
|
string.prototype.trimend@^1.0.0:
|
||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.1.tgz#85812a6b847ac002270f5808146064c995fb6913"
|
resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.1.tgz#85812a6b847ac002270f5808146064c995fb6913"
|
||||||
@ -8876,6 +8940,11 @@ strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
ansi-regex "^4.1.0"
|
ansi-regex "^4.1.0"
|
||||||
|
|
||||||
|
strip-bom@^3.0.0:
|
||||||
|
version "3.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
|
||||||
|
integrity sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=
|
||||||
|
|
||||||
strip-bom@^4.0.0:
|
strip-bom@^4.0.0:
|
||||||
version "4.0.0"
|
version "4.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-4.0.0.tgz#9c3505c1db45bcedca3d9cf7a16f5c5aa3901878"
|
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-4.0.0.tgz#9c3505c1db45bcedca3d9cf7a16f5c5aa3901878"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user