diff --git a/src/api/web/index.js b/src/api/web/index.js index 71bbfe863..5ff2891aa 100644 --- a/src/api/web/index.js +++ b/src/api/web/index.js @@ -9,7 +9,7 @@ import VError from 'verror'; import chalk from 'chalk'; import express from 'express'; -import { combineBaseUrl, getWebProtocol } from '../../lib/utils'; +import { combineBaseUrl, getWebProtocol, spliceURL } from '../../lib/utils'; import Search from '../../lib/search'; import { HEADERS, HTTP_STATUS, WEB_TITLE } from '../../lib/constants'; import { spliceURL } from '../../utils/string'; diff --git a/src/webui/components/Developers/index.js b/src/webui/components/Developers/index.js index 27c8d89c5..d311bc248 100644 --- a/src/webui/components/Developers/index.js +++ b/src/webui/components/Developers/index.js @@ -17,8 +17,6 @@ class Developers extends Component { }; render() { - const { visibleDevs } = this.state; - console.log('aqui', visibleDevs); return ( {({ packageMeta }) => { diff --git a/src/webui/components/Layout/index.js b/src/webui/components/Layout/index.js index f33d8ea06..94e3a6cb4 100644 --- a/src/webui/components/Layout/index.js +++ b/src/webui/components/Layout/index.js @@ -9,7 +9,9 @@ export const Content = styled.div` && { background-color: #ffffff; flex: 1; + display: flex; position: relative; + flex-direction: column; } `; diff --git a/src/webui/components/NotFound/img/package.svg b/src/webui/components/NotFound/img/package.svg new file mode 100644 index 000000000..3b2653549 --- /dev/null +++ b/src/webui/components/NotFound/img/package.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/webui/components/NotFound/index.js b/src/webui/components/NotFound/index.js index d540293ff..2d7b82ade 100644 --- a/src/webui/components/NotFound/index.js +++ b/src/webui/components/NotFound/index.js @@ -1,21 +1,53 @@ /** * @prettier - * @flow */ import React from 'react'; -import { Wrapper } from './styles'; -import { IProps } from './types'; +import { withRouter } from 'react-router-dom'; +import withWidth, { isWidthUp } from '@material-ui/core/withWidth/index'; +import ListItem from '@material-ui/core/ListItem/index'; +import Typography from '@material-ui/core/Typography/index'; +import { Wrapper, Inner, EmptyPackage, Heading, Card, List } from './styles'; +import PackageImg from './img/package.svg'; -const NotFound = ({ pkg }: IProps) => ( - -

- {'Error 404 - '} - {pkg} -

-
-

{'Oops, The package you are trying to access does not exist.'}

-
-); +// eslint-disable-next-line react/prop-types +const NotFound = ({ history, width }) => { + const handleGoTo = to => () => { + history.push(to); + }; -export default NotFound; + const handleGoBack = () => () => { + history.goBack(); + }; + + const renderList = () => ( + + + {'Home'} + + + {'Back'} + + + ); + + const renderSubTitle = () => ( + +
{"The page you're looking for doesn't exist."}
+
{'Perhaps these links will help find what you are looking for:'}
+
+ ); + + return ( + + + + {"Sorry, we couldn't find it..."} + {renderSubTitle()} + {renderList()} + + + ); +}; + +export default withRouter(withWidth()(NotFound)); diff --git a/src/webui/components/NotFound/styles.js b/src/webui/components/NotFound/styles.js index cca55ec7a..818a43df3 100644 --- a/src/webui/components/NotFound/styles.js +++ b/src/webui/components/NotFound/styles.js @@ -4,16 +4,43 @@ */ import styled from 'react-emotion'; +import Typography from '@material-ui/core/Typography/index'; +import { default as MuiList } from '@material-ui/core/List/index'; +import { default as MuiCard } from '@material-ui/core/Card/index'; -import { fontSize, lineHeight } from '../../utils/styles/sizes'; +export const Wrapper = styled('div')` + display: flex; + align-items: center; + flex-direction: column; + justify-content: center; + flex: 1; + padding: 16px; +`; -export const Wrapper = styled.div` +export const Inner = styled('div')` + max-width: 650px; + display: flex; + flex-direction: column; +`; + +export const EmptyPackage = styled('img')` + width: 150px; + margin: 0 auto; +`; + +export const Heading = styled(Typography)` && { - font-size: ${fontSize.md}; - line-height: ${lineHeight.xl}; - border: none; - outline: none; - flex-direction: column; - align-items: center; + color: #4b5e40; } `; + +export const List = styled(MuiList)` + && { + padding: 0; + color: #4b5e40; + } +`; + +export const Card = styled(MuiCard)` + margin-top: 24px; +`; diff --git a/src/webui/components/NotFound/types.js b/src/webui/components/NotFound/types.js deleted file mode 100644 index c353bac2c..000000000 --- a/src/webui/components/NotFound/types.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * @prettier - * @flow - */ - -export interface IProps { - pkg: string; -} diff --git a/src/webui/router.js b/src/webui/router.js index 51c2db51d..6f8e5ab62 100644 --- a/src/webui/router.js +++ b/src/webui/router.js @@ -13,6 +13,7 @@ import { asyncComponent } from './utils/asyncComponent'; import history from './history'; import Header from './components/Header'; +const NotFound = asyncComponent(() => import('./components/NotFound')); const DetailPackage = asyncComponent(() => import('./pages/detail')); const VersionPackage = asyncComponent(() => import('./pages/version')); const HomePage = asyncComponent(() => import('./pages/home')); @@ -29,6 +30,7 @@ class RouterApp extends Component { + diff --git a/test/unit/webui/components/__snapshots__/notfound.spec.js.snap b/test/unit/webui/components/__snapshots__/notfound.spec.js.snap index 0f9b3cd0c..1adcfb9b7 100644 --- a/test/unit/webui/components/__snapshots__/notfound.spec.js.snap +++ b/test/unit/webui/components/__snapshots__/notfound.spec.js.snap @@ -1,5 +1,163 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` component should load the component in default state 1`] = `"

Error 404 - test


Oops, The package you are trying to access does not exist.

"`; - -exports[` component should set html from props 1`] = `"

Error 404 - verdaccio


Oops, The package you are trying to access does not exist.

"`; +exports[` component should load the component in default state 1`] = ` +ShallowWrapper { + Symbol(enzyme.__root__): ShallowWrapper { + Symbol(enzyme.__root__): [Circular], + Symbol(enzyme.__unrendered__): + + , + Symbol(enzyme.__renderer__): Object { + "batchedUpdates": [Function], + "getNode": [Function], + "render": [Function], + "simulateError": [Function], + "simulateEvent": [Function], + "unmount": [Function], + }, + Symbol(enzyme.__node__): Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "children": , + "history": Object { + "action": "POP", + "block": [Function], + "createHref": [Function], + "go": [Function], + "goBack": [Function], + "goForward": [Function], + "length": 1, + "listen": [Function], + "location": Object { + "hash": "", + "pathname": "/", + "search": "", + "state": undefined, + }, + "push": [Function], + "replace": [Function], + }, + }, + "ref": null, + "rendered": Object { + "instance": null, + "key": undefined, + "nodeType": "function", + "props": Object {}, + "ref": null, + "rendered": null, + "type": [Function], + }, + "type": [Function], + }, + Symbol(enzyme.__nodes__): Array [ + Object { + "instance": null, + "key": undefined, + "nodeType": "class", + "props": Object { + "children": , + "history": Object { + "action": "POP", + "block": [Function], + "createHref": [Function], + "go": [Function], + "goBack": [Function], + "goForward": [Function], + "length": 1, + "listen": [Function], + "location": Object { + "hash": "", + "pathname": "/", + "search": "", + "state": undefined, + }, + "push": [Function], + "replace": [Function], + }, + }, + "ref": null, + "rendered": Object { + "instance": null, + "key": undefined, + "nodeType": "function", + "props": Object {}, + "ref": null, + "rendered": null, + "type": [Function], + }, + "type": [Function], + }, + ], + Symbol(enzyme.__options__): Object { + "adapter": ReactSixteenAdapter { + "options": Object { + "enableComponentDidUpdateOnSetState": true, + "lifecycles": Object { + "componentDidUpdate": Object { + "onSetState": true, + }, + "getDerivedStateFromProps": true, + "getSnapshotBeforeUpdate": true, + "setState": Object { + "skipsComponentDidUpdateOnNullish": true, + }, + }, + }, + }, + "attachTo": undefined, + "hydrateIn": undefined, + }, + }, + Symbol(enzyme.__unrendered__): null, + Symbol(enzyme.__renderer__): Object { + "batchedUpdates": [Function], + "getNode": [Function], + "render": [Function], + "simulateError": [Function], + "simulateEvent": [Function], + "unmount": [Function], + }, + Symbol(enzyme.__node__): Object { + "instance": null, + "key": undefined, + "nodeType": "function", + "props": Object {}, + "ref": null, + "rendered": null, + "type": [Function], + }, + Symbol(enzyme.__nodes__): Array [ + Object { + "instance": null, + "key": undefined, + "nodeType": "function", + "props": Object {}, + "ref": null, + "rendered": null, + "type": [Function], + }, + ], + Symbol(enzyme.__options__): Object { + "adapter": ReactSixteenAdapter { + "options": Object { + "enableComponentDidUpdateOnSetState": true, + "lifecycles": Object { + "componentDidUpdate": Object { + "onSetState": true, + }, + "getDerivedStateFromProps": true, + "getSnapshotBeforeUpdate": true, + "setState": Object { + "skipsComponentDidUpdateOnNullish": true, + }, + }, + }, + }, + "attachTo": undefined, + "hydrateIn": undefined, + }, +} +`; diff --git a/test/unit/webui/components/notfound.spec.js b/test/unit/webui/components/notfound.spec.js index 65933a21f..b8d6851f3 100644 --- a/test/unit/webui/components/notfound.spec.js +++ b/test/unit/webui/components/notfound.spec.js @@ -3,26 +3,25 @@ */ import React from 'react'; -import { shallow, mount } from 'enzyme'; +import { BrowserRouter as Router } from 'react-router-dom'; +import { shallow } from 'enzyme'; import NotFound from '../../../../src/webui/components/NotFound/index'; console.error = jest.fn(); describe(' component', () => { - test('should load the component in default state', () => { - const wrapper = mount(); - expect(wrapper.html()).toMatchSnapshot(); + let routerWrapper; + beforeEach(() => { + routerWrapper = shallow( + + + + ); }); - test('should set html from props', () => { - const props = { - pkg: 'verdaccio' - }; - const wrapper = shallow(); - expect(wrapper.find('h1').text()).toEqual('Error 404 - verdaccio'); - expect(wrapper.find('p').text()).toEqual( - 'Oops, The package you are trying to access does not exist.' - ); - expect(wrapper.html()).toMatchSnapshot(); + + test('should load the component in default state', () => { + expect(routerWrapper.find(NotFound)).toMatchSnapshot(); }); + });