[lint][lg]: fix lint errors
This commit is contained in:
@@ -25,6 +25,7 @@ module.exports = {
|
|||||||
'react/react-in-jsx-scope': 'off',
|
'react/react-in-jsx-scope': 'off',
|
||||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||||
'@typescript-eslint/ban-ts-ignore': 'off',
|
'@typescript-eslint/ban-ts-ignore': 'off',
|
||||||
|
'@typescript-eslint/no-var-requires': 'off',
|
||||||
'jsx-a11y/label-has-associated-control': [
|
'jsx-a11y/label-has-associated-control': [
|
||||||
'error',
|
'error',
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render } from '@testing-library/react';
|
import { render } from '@testing-library/react';
|
||||||
import renderer from 'react-test-renderer';
|
|
||||||
import Form from '../../../components/search/Form';
|
import Form from '../../../components/search/Form';
|
||||||
|
|
||||||
const useRouter = jest.spyOn(require('next/router'), 'useRouter');
|
const useRouter = jest.spyOn(require('next/router'), 'useRouter');
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render } from '@testing-library/react';
|
|
||||||
import renderer from 'react-test-renderer';
|
import renderer from 'react-test-renderer';
|
||||||
import Item from '../../../components/search/Item';
|
import Item from '../../../components/search/Item';
|
||||||
|
|
||||||
@@ -10,6 +9,8 @@ test('📸 of Input component with empty', () => {
|
|||||||
organization: null,
|
organization: null,
|
||||||
__typename: 'Package',
|
__typename: 'Package',
|
||||||
};
|
};
|
||||||
const tree = renderer.create(<Item datapackage={fixture} key={0} />).toJSON();
|
const tree = renderer
|
||||||
|
.create(<Item datapackage={fixture} key={0} />)
|
||||||
|
.toJSON();
|
||||||
expect(tree).toMatchSnapshot();
|
expect(tree).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|||||||
15
components/_shared/CustomLink.tsx
Normal file
15
components/_shared/CustomLink.tsx
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
type LinkProps = {
|
||||||
|
url: string;
|
||||||
|
format: any;
|
||||||
|
};
|
||||||
|
|
||||||
|
const CustomLink: React.FC<LinkProps> = ({ url, format }: LinkProps) => (
|
||||||
|
<a
|
||||||
|
href={url}
|
||||||
|
className="bg-white hover:bg-gray-200 border text-black font-semibold py-2 px-4 rounded"
|
||||||
|
>
|
||||||
|
{format}
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default CustomLink;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
export default function ErrorMessage({ message }) {
|
const ErrorMessage: React.FC<{ message: any }> = ({ message }) => {
|
||||||
return (
|
return (
|
||||||
<aside>
|
<aside>
|
||||||
{message}
|
{message}
|
||||||
@@ -12,4 +12,6 @@ export default function ErrorMessage({ message }) {
|
|||||||
`}</style>
|
`}</style>
|
||||||
</aside>
|
</aside>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default ErrorMessage;
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import React from 'react';
|
|
||||||
|
|
||||||
interface TableProps {
|
interface TableProps {
|
||||||
columns: Array<any>;
|
columns: Array<any>;
|
||||||
data: Array<any>;
|
data: Array<any>;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import Table from './Table';
|
import Table from './Table';
|
||||||
import ErrorMessage from './Error';
|
import ErrorMessage from './Error';
|
||||||
|
import CustomLink from './CustomLink';
|
||||||
|
|
||||||
export { Table, ErrorMessage };
|
export { Table, ErrorMessage, CustomLink };
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ const columns = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export default function About({ variables }) {
|
const About: React.FC<{ variables: any }> = ({ variables }) => {
|
||||||
const { loading, error, data } = useQuery(GET_DATAPACKAGE_QUERY, {
|
const { loading, error, data } = useQuery(GET_DATAPACKAGE_QUERY, {
|
||||||
variables,
|
variables,
|
||||||
// Setting this value to true will make the component rerender when
|
// Setting this value to true will make the component rerender when
|
||||||
@@ -48,4 +48,6 @@ export default function About({ variables }) {
|
|||||||
|
|
||||||
const { result } = data.dataset;
|
const { result } = data.dataset;
|
||||||
return <Table columns={columns} data={[result]} />;
|
return <Table columns={columns} data={[result]} />;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default About;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { useQuery } from '@apollo/react-hooks';
|
|||||||
import { ErrorMessage } from '../_shared';
|
import { ErrorMessage } from '../_shared';
|
||||||
import { GET_ORG_QUERY } from '../../graphql/queries';
|
import { GET_ORG_QUERY } from '../../graphql/queries';
|
||||||
|
|
||||||
export default function Org({ variables }) {
|
const Org: React.FC<{ variables: any }> = ({ variables }) => {
|
||||||
const { loading, error, data } = useQuery(GET_ORG_QUERY, {
|
const { loading, error, data } = useQuery(GET_ORG_QUERY, {
|
||||||
variables,
|
variables,
|
||||||
// Setting this value to true will make the component rerender when
|
// Setting this value to true will make the component rerender when
|
||||||
@@ -26,8 +26,10 @@ export default function Org({ variables }) {
|
|||||||
'https://datahub.io/static/img/datahub-cube-edited.svg'
|
'https://datahub.io/static/img/datahub-cube-edited.svg'
|
||||||
}
|
}
|
||||||
className="h-5 w-5 mr-2 inline-block"
|
className="h-5 w-5 mr-2 inline-block"
|
||||||
|
alt="org_img"
|
||||||
/>
|
/>
|
||||||
<Link href={`/@${organization.name}`}>
|
<Link href={`/@${organization.name}`}>
|
||||||
|
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
|
||||||
<a className="font-semibold text-primary underline">
|
<a className="font-semibold text-primary underline">
|
||||||
{organization.title || organization.name}
|
{organization.title || organization.name}
|
||||||
</a>
|
</a>
|
||||||
@@ -38,4 +40,6 @@ export default function Org({ variables }) {
|
|||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default Org;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
/* eslint-disable jsx-a11y/anchor-is-valid */
|
||||||
|
/* eslint-disable react/display-name */
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { useQuery } from '@apollo/react-hooks';
|
import { useQuery } from '@apollo/react-hooks';
|
||||||
import { Table, ErrorMessage } from '../_shared';
|
import { Table, ErrorMessage } from '../_shared';
|
||||||
@@ -36,7 +38,7 @@ const columns = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export default function Resources({ variables }) {
|
const Resources: React.FC<{ variables: any }> = ({ variables }) => {
|
||||||
const { loading, error, data } = useQuery(GET_RESOURCES_QUERY, {
|
const { loading, error, data } = useQuery(GET_RESOURCES_QUERY, {
|
||||||
variables,
|
variables,
|
||||||
// Setting this value to true will make the component rerender when
|
// Setting this value to true will make the component rerender when
|
||||||
@@ -62,4 +64,6 @@ export default function Resources({ variables }) {
|
|||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default Resources;
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
/* eslint-disable jsx-a11y/anchor-is-valid */
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import React, { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
export default function Nav() {
|
const Nav: React.FC = () => {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
const handleClick = (event) => {
|
const handleClick = (event) => {
|
||||||
@@ -44,6 +45,7 @@ export default function Nav() {
|
|||||||
href="http://tech.datopian.com/frontend/"
|
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"
|
||||||
|
rel="noreferrer"
|
||||||
>
|
>
|
||||||
Docs
|
Docs
|
||||||
</a>
|
</a>
|
||||||
@@ -51,10 +53,13 @@ export default function Nav() {
|
|||||||
href="https://github.com/datopian/portal"
|
href="https://github.com/datopian/portal"
|
||||||
className="inline-block text-tiny px-4 py-2 leading-none border rounded text-primary bg-primary-background border-black hover:border-gray-700 hover:text-gray-700 hover:bg-white mt-4 lg:mt-0"
|
className="inline-block text-tiny px-4 py-2 leading-none border rounded text-primary bg-primary-background border-black hover:border-gray-700 hover:text-gray-700 hover:bg-white mt-4 lg:mt-0"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
>
|
>
|
||||||
GitHub
|
GitHub
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default Nav;
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
|
/* eslint-disable jsx-a11y/anchor-is-valid */
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { useQuery } from '@apollo/react-hooks';
|
import { useQuery } from '@apollo/react-hooks';
|
||||||
import { ErrorMessage } from '../_shared';
|
import { ErrorMessage } from '../_shared';
|
||||||
import { SEARCH_QUERY } from '../../graphql/queries';
|
import { SEARCH_QUERY } from '../../graphql/queries';
|
||||||
|
|
||||||
function Recent() {
|
const Recent: React.FC = () => {
|
||||||
const { loading, error, data } = useQuery(SEARCH_QUERY, {
|
const { loading, error, data } = useQuery(SEARCH_QUERY, {
|
||||||
variables: {
|
variables: {
|
||||||
sort: 'metadata_created desc',
|
sort: 'metadata_created desc',
|
||||||
@@ -47,6 +48,6 @@ function Recent() {
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
export default Recent;
|
export default Recent;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable react/display-name */
|
||||||
import { useQuery } from '@apollo/react-hooks';
|
import { useQuery } from '@apollo/react-hooks';
|
||||||
import { Table, ErrorMessage } from '../_shared';
|
import { Table, ErrorMessage } from '../_shared';
|
||||||
import { GET_RESOURCES_QUERY } from '../../graphql/queries';
|
import { GET_RESOURCES_QUERY } from '../../graphql/queries';
|
||||||
@@ -46,7 +47,7 @@ const columns = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export default function About({ variables }) {
|
const About: React.FC<{ variables: any }> = ({ variables }) => {
|
||||||
const { loading, error, data } = useQuery(GET_RESOURCES_QUERY, {
|
const { loading, error, data } = useQuery(GET_RESOURCES_QUERY, {
|
||||||
variables,
|
variables,
|
||||||
// Setting this value to true will make the component rerender when
|
// Setting this value to true will make the component rerender when
|
||||||
@@ -63,4 +64,6 @@ export default function About({ variables }) {
|
|||||||
(item) => item.name === variables.resource
|
(item) => item.name === variables.resource
|
||||||
);
|
);
|
||||||
return <Table columns={columns} data={[resource]} />;
|
return <Table columns={columns} data={[resource]} />;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default About;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { useQuery } from '@apollo/react-hooks';
|
|||||||
import { ErrorMessage } from '../_shared';
|
import { ErrorMessage } from '../_shared';
|
||||||
import { GET_RESOURCES_QUERY } from '../../graphql/queries';
|
import { GET_RESOURCES_QUERY } from '../../graphql/queries';
|
||||||
|
|
||||||
export default function DataExplorer({ variables }) {
|
const DataExplorer: React.FC<{ variables: any }> = ({ variables }) => {
|
||||||
const { loading, error, data } = useQuery(GET_RESOURCES_QUERY, {
|
const { loading, error, data } = useQuery(GET_RESOURCES_QUERY, {
|
||||||
variables,
|
variables,
|
||||||
// Setting this value to true will make the component rerender when
|
// Setting this value to true will make the component rerender when
|
||||||
@@ -20,4 +20,6 @@ export default function DataExplorer({ variables }) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return <>{JSON.stringify(resource)}</>;
|
return <>{JSON.stringify(resource)}</>;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default DataExplorer;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
|
|
||||||
export default function Form() {
|
const Form: React.FC = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [q, setQ] = useState(router.query.q);
|
const [q, setQ] = useState(router.query.q);
|
||||||
const [sort, setSort] = useState(router.query.sort);
|
const [sort, setSort] = useState(router.query.sort);
|
||||||
@@ -48,6 +48,7 @@ export default function Form() {
|
|||||||
id="field-order-by"
|
id="field-order-by"
|
||||||
name="sort"
|
name="sort"
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
|
onBlur={handleChange}
|
||||||
value={sort}
|
value={sort}
|
||||||
>
|
>
|
||||||
<option value="score:desc">Relevance</option>
|
<option value="score:desc">Relevance</option>
|
||||||
@@ -59,4 +60,6 @@ export default function Form() {
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default Form;
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
|
/* eslint-disable jsx-a11y/anchor-is-valid */
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
|
||||||
export default function Item({ datapackage }) {
|
const Item: React.FC<{ datapackage: any }> = ({ datapackage }) => {
|
||||||
return (
|
return (
|
||||||
<div className="mb-6">
|
<div className="mb-6">
|
||||||
<h3 className="text-xl font-semibold">
|
<h3 className="text-xl font-semibold">
|
||||||
<Link
|
<Link
|
||||||
href={`/@${
|
href={`/@${
|
||||||
datapackage.organization ? datapackage.organization.name : 'dataset'
|
datapackage.organization
|
||||||
|
? datapackage.organization.name
|
||||||
|
: 'dataset'
|
||||||
}/${datapackage.name}`}
|
}/${datapackage.name}`}
|
||||||
>
|
>
|
||||||
<a className="text-primary">
|
<a className="text-primary">
|
||||||
@@ -30,4 +33,6 @@ export default function Item({ datapackage }) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default Item;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import Item from './Item';
|
|||||||
import { ErrorMessage } from '../_shared';
|
import { ErrorMessage } from '../_shared';
|
||||||
import { SEARCH_QUERY } from '../../graphql/queries';
|
import { SEARCH_QUERY } from '../../graphql/queries';
|
||||||
|
|
||||||
export default function List({ variables }) {
|
const List: React.FC<{ variables: any }> = ({ variables }) => {
|
||||||
const { loading, error, data } = useQuery(SEARCH_QUERY, {
|
const { loading, error, data } = useQuery(SEARCH_QUERY, {
|
||||||
variables,
|
variables,
|
||||||
// Setting this value to true will make the component rerender when
|
// Setting this value to true will make the component rerender when
|
||||||
@@ -22,4 +22,6 @@ export default function List({ variables }) {
|
|||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default List;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { useQuery } from '@apollo/react-hooks';
|
|||||||
import { ErrorMessage } from '../_shared';
|
import { ErrorMessage } from '../_shared';
|
||||||
import { GET_TOTAL_COUNT_QUERY } from '../../graphql/queries';
|
import { GET_TOTAL_COUNT_QUERY } from '../../graphql/queries';
|
||||||
|
|
||||||
export default function Total({ variables }) {
|
const Total: React.FC<{ variables: any }> = ({ variables }) => {
|
||||||
const { loading, error, data } = useQuery(GET_TOTAL_COUNT_QUERY, {
|
const { loading, error, data } = useQuery(GET_TOTAL_COUNT_QUERY, {
|
||||||
variables,
|
variables,
|
||||||
// Setting this value to true will make the component rerender when
|
// Setting this value to true will make the component rerender when
|
||||||
@@ -21,4 +21,6 @@ export default function Total({ variables }) {
|
|||||||
{result.count} results found
|
{result.count} results found
|
||||||
</h1>
|
</h1>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default Total;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { useQuery } from '@apollo/react-hooks';
|
|||||||
import { ErrorMessage } from '../_shared';
|
import { ErrorMessage } from '../_shared';
|
||||||
import { GET_POSTS_QUERY } from '../../graphql/queries';
|
import { GET_POSTS_QUERY } from '../../graphql/queries';
|
||||||
|
|
||||||
export default function List() {
|
const List: React.FC = () => {
|
||||||
const { loading, error, data } = useQuery(GET_POSTS_QUERY, {
|
const { loading, error, data } = useQuery(GET_POSTS_QUERY, {
|
||||||
// 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
|
||||||
@@ -34,4 +34,6 @@ export default function List() {
|
|||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default List;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { useQuery } from '@apollo/react-hooks';
|
|||||||
import { ErrorMessage } from '../_shared';
|
import { ErrorMessage } from '../_shared';
|
||||||
import { GET_PAGE_QUERY } from '../../graphql/queries';
|
import { GET_PAGE_QUERY } from '../../graphql/queries';
|
||||||
|
|
||||||
export default function Page({ variables }) {
|
const Page: React.FC<{ variables: any }> = ({ variables }) => {
|
||||||
const { loading, error, data } = useQuery(GET_PAGE_QUERY, {
|
const { loading, error, data } = useQuery(GET_PAGE_QUERY, {
|
||||||
variables,
|
variables,
|
||||||
// Setting this value to true will make the component rerender when
|
// Setting this value to true will make the component rerender when
|
||||||
@@ -23,8 +23,10 @@ export default function Page({ variables }) {
|
|||||||
{title}
|
{title}
|
||||||
</h1>
|
</h1>
|
||||||
<p className="mb-6">Edited: {modified}</p>
|
<p className="mb-6">Edited: {modified}</p>
|
||||||
<img src={featured_image} className="mb-6" />
|
<img src={featured_image} className="mb-6" alt="featured_img" />
|
||||||
<div>{parse(content)}</div>
|
<div>{parse(content)}</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default Page;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { useQuery } from '@apollo/react-hooks';
|
|||||||
import { ErrorMessage } from '../_shared';
|
import { ErrorMessage } from '../_shared';
|
||||||
import { GET_PAGE_QUERY } from '../../graphql/queries';
|
import { GET_PAGE_QUERY } from '../../graphql/queries';
|
||||||
|
|
||||||
export default function Post({ variables }) {
|
const Post: React.FC<{ variables: any }> = ({ variables }) => {
|
||||||
const { loading, error, data } = useQuery(GET_PAGE_QUERY, {
|
const { loading, error, data } = useQuery(GET_PAGE_QUERY, {
|
||||||
variables,
|
variables,
|
||||||
// Setting this value to true will make the component rerender when
|
// Setting this value to true will make the component rerender when
|
||||||
@@ -23,8 +23,10 @@ export default function Post({ variables }) {
|
|||||||
{title}
|
{title}
|
||||||
</h1>
|
</h1>
|
||||||
<p className="mb-6">Edited: {modified}</p>
|
<p className="mb-6">Edited: {modified}</p>
|
||||||
<img src={featured_image} className="mb-6" />
|
<img src={featured_image} className="mb-6" alt="featured_img" />
|
||||||
<div>{parse(content)}</div>
|
<div>{parse(content)}</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default Post;
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import getConfig from 'next/config';
|
import getConfig from 'next/config';
|
||||||
import { ApolloClient } from 'apollo-client';
|
import { ApolloClient } from 'apollo-client';
|
||||||
import { InMemoryCache } from 'apollo-cache-inmemory';
|
import {
|
||||||
|
InMemoryCache,
|
||||||
|
NormalizedCache,
|
||||||
|
NormalizedCacheObject,
|
||||||
|
} from 'apollo-cache-inmemory';
|
||||||
import { RestLink } from 'apollo-link-rest';
|
import { RestLink } from 'apollo-link-rest';
|
||||||
|
|
||||||
let apolloClient;
|
let apolloClient:
|
||||||
|
| ApolloClient<NormalizedCache>
|
||||||
|
| ApolloClient<NormalizedCacheObject>;
|
||||||
|
|
||||||
const restLink = new RestLink({
|
const restLink = new RestLink({
|
||||||
uri: getConfig().publicRuntimeConfig.DMS + '/api/3/action/',
|
uri: getConfig().publicRuntimeConfig.DMS + '/api/3/action/',
|
||||||
@@ -17,11 +23,7 @@ const restLink = new RestLink({
|
|||||||
}/posts/`,
|
}/posts/`,
|
||||||
},
|
},
|
||||||
typePatcher: {
|
typePatcher: {
|
||||||
Search: (
|
Search: (data: any): any => {
|
||||||
data: any,
|
|
||||||
outerType: string,
|
|
||||||
patchDeeper: RestLink.FunctionalTypePatcher
|
|
||||||
): any => {
|
|
||||||
if (data.result != null) {
|
if (data.result != null) {
|
||||||
data.result.__typename = 'SearchResponse';
|
data.result.__typename = 'SearchResponse';
|
||||||
|
|
||||||
@@ -36,11 +38,7 @@ const restLink = new RestLink({
|
|||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
Response: (
|
Response: (data: any): any => {
|
||||||
data: any,
|
|
||||||
outerType: string,
|
|
||||||
patchDeeper: RestLink.FunctionalTypePatcher
|
|
||||||
): any => {
|
|
||||||
if (data.result != null) {
|
if (data.result != null) {
|
||||||
data.result.__typename = 'Package';
|
data.result.__typename = 'Package';
|
||||||
if (data.result.organization != null) {
|
if (data.result.organization != null) {
|
||||||
@@ -65,8 +63,13 @@ function createApolloClient() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initializeApollo(initialState = null) {
|
export function initializeApollo(
|
||||||
const _apolloClient = apolloClient ?? createApolloClient();
|
initialState = null
|
||||||
|
): ApolloClient<NormalizedCache> | ApolloClient<NormalizedCacheObject> {
|
||||||
|
const _apolloClient:
|
||||||
|
| ApolloClient<NormalizedCache>
|
||||||
|
| ApolloClient<NormalizedCacheObject> =
|
||||||
|
apolloClient ?? createApolloClient();
|
||||||
|
|
||||||
// If your page has Next.js data fetching methods that use Apollo Client, the initial state
|
// If your page has Next.js data fetching methods that use Apollo Client, the initial state
|
||||||
// gets hydrated here
|
// gets hydrated here
|
||||||
@@ -81,7 +84,9 @@ export function initializeApollo(initialState = null) {
|
|||||||
return _apolloClient;
|
return _apolloClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useApollo(initialState) {
|
export function useApollo(
|
||||||
|
initialState = null
|
||||||
|
): ApolloClient<NormalizedCache> | ApolloClient<NormalizedCacheObject> {
|
||||||
const store = useMemo(() => initializeApollo(initialState), [initialState]);
|
const store = useMemo(() => initializeApollo(initialState), [initialState]);
|
||||||
return store;
|
return store;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
"format": "prettier --single-quote --write .",
|
"format": "prettier --single-quote --write .",
|
||||||
"pre-commit": "yarn lint:fix && prettier --single-quote --write",
|
"pre-commit": "yarn lint:fix && prettier --single-quote --write",
|
||||||
"lint": "eslint . --ext .ts,.tsx",
|
"lint": "eslint . --ext .ts,.tsx",
|
||||||
"lint:fix": "yarn lint -- --fix"
|
"lint:fix": "yarn lint --fix"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apollo/client": "^3.0.2",
|
"@apollo/client": "^3.0.2",
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import Org from '../../../components/dataset/Org';
|
|||||||
import Resources from '../../../components/dataset/Resources';
|
import Resources from '../../../components/dataset/Resources';
|
||||||
import { GET_DATASET_QUERY } from '../../../graphql/queries';
|
import { GET_DATASET_QUERY } from '../../../graphql/queries';
|
||||||
|
|
||||||
function Dataset({ variables }) {
|
const Dataset: React.FC<{ variables: any }> = ({ variables }) => {
|
||||||
const { data, loading } = useQuery(GET_DATASET_QUERY, { variables });
|
const { data, loading } = useQuery(GET_DATASET_QUERY, { variables });
|
||||||
|
|
||||||
if (loading) return <div>Loading</div>;
|
if (loading) return <div>Loading</div>;
|
||||||
@@ -31,7 +31,7 @@ function Dataset({ variables }) {
|
|||||||
</main>
|
</main>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||||
const apolloClient = initializeApollo();
|
const apolloClient = initializeApollo();
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import About from '../../../../../components/resource/About';
|
|||||||
import DataExplorer from '../../../../../components/resource/DataExplorer';
|
import DataExplorer from '../../../../../components/resource/DataExplorer';
|
||||||
import { GET_RESOURCES_QUERY } from '../../../../../graphql/queries';
|
import { GET_RESOURCES_QUERY } from '../../../../../graphql/queries';
|
||||||
|
|
||||||
function Resource({ variables }) {
|
const Resource: React.FC<{ variables: any }> = ({ variables }) => {
|
||||||
const { data, loading } = useQuery(GET_RESOURCES_QUERY, { variables });
|
const { data, loading } = useQuery(GET_RESOURCES_QUERY, { variables });
|
||||||
|
|
||||||
if (loading) return <div>Loading</div>;
|
if (loading) return <div>Loading</div>;
|
||||||
@@ -32,7 +32,7 @@ function Resource({ variables }) {
|
|||||||
</main>
|
</main>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||||
const apolloClient = initializeApollo();
|
const apolloClient = initializeApollo();
|
||||||
|
|||||||
@@ -6,9 +6,14 @@ import { applyTheme } from '../themes/utils';
|
|||||||
|
|
||||||
import '../styles/app.css';
|
import '../styles/app.css';
|
||||||
|
|
||||||
export default function MyApp({ Component, pageProps }) {
|
type Props = {
|
||||||
|
Component: any;
|
||||||
|
pageProps: any;
|
||||||
|
};
|
||||||
|
|
||||||
|
const MyApp: React.FC<Props> = ({ Component, pageProps }) => {
|
||||||
const apolloClient = useApollo(pageProps.initialApolloState);
|
const apolloClient = useApollo(pageProps.initialApolloState);
|
||||||
const [theme, setTheme] = useState(DEFAULT_THEME);
|
const [theme] = useState(DEFAULT_THEME); // setTheme
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
/**
|
/**
|
||||||
@@ -24,4 +29,6 @@ export default function MyApp({ Component, pageProps }) {
|
|||||||
<Component {...pageProps} />
|
<Component {...pageProps} />
|
||||||
</ApolloProvider>
|
</ApolloProvider>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default MyApp;
|
||||||
|
|||||||
@@ -5,8 +5,11 @@ import Nav from '../../../components/home/Nav';
|
|||||||
import Post from '../../../components/static/Post';
|
import Post from '../../../components/static/Post';
|
||||||
import { GET_POST_QUERY } from '../../../graphql/queries';
|
import { GET_POST_QUERY } from '../../../graphql/queries';
|
||||||
|
|
||||||
function PostItem({ variables }) {
|
type Props = {
|
||||||
return (
|
variables: any;
|
||||||
|
};
|
||||||
|
|
||||||
|
const PostItem: React.FC<Props> = ({ variables }) => (
|
||||||
<>
|
<>
|
||||||
<Head>
|
<Head>
|
||||||
<title>Portal | {variables.slug}</title>
|
<title>Portal | {variables.slug}</title>
|
||||||
@@ -18,7 +21,6 @@ function PostItem({ variables }) {
|
|||||||
</main>
|
</main>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||||
const variables = {
|
const variables = {
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import Nav from '../../components/home/Nav';
|
|||||||
import List from '../../components/static/List';
|
import List from '../../components/static/List';
|
||||||
import { GET_POSTS_QUERY } from '../../graphql/queries';
|
import { GET_POSTS_QUERY } from '../../graphql/queries';
|
||||||
|
|
||||||
function PostList() {
|
const PostList: React.FC = () => (
|
||||||
return (
|
|
||||||
<>
|
<>
|
||||||
<Head>
|
<Head>
|
||||||
<title>Portal | Blog</title>
|
<title>Portal | Blog</title>
|
||||||
@@ -18,9 +17,8 @@ function PostList() {
|
|||||||
</main>
|
</main>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
export const getServerSideProps: GetServerSideProps = async () => {
|
||||||
const apolloClient = initializeApollo();
|
const apolloClient = initializeApollo();
|
||||||
|
|
||||||
await apolloClient.query({
|
await apolloClient.query({
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ import Recent from '../components/home/Recent';
|
|||||||
import Form from '../components/search/Form';
|
import Form from '../components/search/Form';
|
||||||
import { SEARCH_QUERY } from '../graphql/queries';
|
import { SEARCH_QUERY } from '../graphql/queries';
|
||||||
|
|
||||||
function Home() {
|
const Home: React.FC = () => (
|
||||||
return (
|
|
||||||
<div className="container mx-auto">
|
<div className="container mx-auto">
|
||||||
<Head>
|
<Head>
|
||||||
<title>Portal</title>
|
<title>Portal</title>
|
||||||
@@ -21,22 +20,21 @@ function Home() {
|
|||||||
<span className="text-orange-500">Datahub</span>
|
<span className="text-orange-500">Datahub</span>
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-md font-light mb-3 w-4/5">
|
<p className="text-md font-light mb-3 w-4/5">
|
||||||
At Datahub, we have over thousands of datasets for free and a
|
At Datahub, we have over thousands of datasets for free and a Premium
|
||||||
Premium Data Service for additional or customised data with
|
Data Service for additional or customised data with guaranteed
|
||||||
guaranteed updates.
|
updates.
|
||||||
</p>
|
</p>
|
||||||
<Form />
|
<Form />
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-4">
|
<div className="mt-4">
|
||||||
<img src="/images/banner.svg" className="w-4/5" />
|
<img src="/images/banner.svg" className="w-4/5" alt="banner_img" />
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<Recent />
|
<Recent />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
export const getServerSideProps: GetServerSideProps = async () => {
|
||||||
const apolloClient = initializeApollo();
|
const apolloClient = initializeApollo();
|
||||||
|
|
||||||
await apolloClient.query({
|
await apolloClient.query({
|
||||||
|
|||||||
@@ -5,8 +5,11 @@ import Nav from '../../../components/home/Nav';
|
|||||||
import Page from '../../../components/static/Page';
|
import Page from '../../../components/static/Page';
|
||||||
import { GET_PAGE_QUERY } from '../../../graphql/queries';
|
import { GET_PAGE_QUERY } from '../../../graphql/queries';
|
||||||
|
|
||||||
function PageItem({ variables }) {
|
type Props = {
|
||||||
return (
|
variables: any;
|
||||||
|
};
|
||||||
|
|
||||||
|
const PageItem: React.FC<Props> = ({ variables }) => (
|
||||||
<>
|
<>
|
||||||
<Head>
|
<Head>
|
||||||
<title>Portal | {variables.slug}</title>
|
<title>Portal | {variables.slug}</title>
|
||||||
@@ -18,7 +21,6 @@ function PageItem({ variables }) {
|
|||||||
</main>
|
</main>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||||
const variables = {
|
const variables = {
|
||||||
|
|||||||
@@ -8,8 +8,11 @@ import Total from '../components/search/Total';
|
|||||||
import List from '../components/search/List';
|
import List from '../components/search/List';
|
||||||
import { SEARCH_QUERY } from '../graphql/queries';
|
import { SEARCH_QUERY } from '../graphql/queries';
|
||||||
|
|
||||||
function Search({ variables }) {
|
type Props = {
|
||||||
return (
|
variables: any;
|
||||||
|
};
|
||||||
|
|
||||||
|
const Search: React.FC<Props> = ({ variables }) => (
|
||||||
<>
|
<>
|
||||||
<Head>
|
<Head>
|
||||||
<title>Portal | Search</title>
|
<title>Portal | Search</title>
|
||||||
@@ -23,7 +26,6 @@ function Search({ variables }) {
|
|||||||
</main>
|
</main>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||||
const query = context.query || {};
|
const query = context.query || {};
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { IThemes } from './utils';
|
|||||||
/**
|
/**
|
||||||
* The default theme to load
|
* The default theme to load
|
||||||
*/
|
*/
|
||||||
export const DEFAULT_THEME: string = 'base';
|
export const DEFAULT_THEME = 'base';
|
||||||
|
|
||||||
export const themes: IThemes = {
|
export const themes: IThemes = {
|
||||||
base,
|
base,
|
||||||
|
|||||||
Reference in New Issue
Block a user