Simplify routing, redirect to default (#228)

* Simplify routing, redirect to default

* Allow subroutes

* Cleanup unused scripts

* Pass through basePath (router prop)
This commit is contained in:
Jaco Greeff 2018-08-16 10:40:56 +02:00 committed by GitHub
parent 6183cc27d6
commit 8155e94d05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 78 additions and 167 deletions

View File

@ -9,11 +9,6 @@
],
"contributors": [],
"license": "ISC",
"scripts": {
"build": "polkadot-dev-build-babel",
"check": "stylelint 'src/**/*.css' && eslint src && flow check",
"test": "jest --coverage"
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/ui-app": "^0.19.33"

View File

@ -17,7 +17,9 @@ import Creator from './Creator';
import Editor from './Editor';
import translate from './translate';
type Props = I18nProps & {};
type Props = I18nProps & {
basePath: string
};
type Actions = 'create' | 'edit';

View File

@ -9,11 +9,6 @@
],
"contributors": [],
"license": "ISC",
"scripts": {
"build": "polkadot-dev-build-babel",
"check": "stylelint 'src/**/*.css' && eslint src && flow check",
"test": "jest --coverage"
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/ui-app": "^0.19.33"

View File

@ -18,7 +18,9 @@ import Creator from './Creator';
import Editor from './Editor';
import translate from './translate';
type Props = I18nProps & {};
type Props = I18nProps & {
basePath: string
};
type Actions = 'create' | 'edit';

View File

@ -13,7 +13,9 @@ import Proposals from './Proposals';
import Referendums from './Referendums';
import Summary from './Summary';
type Props = BareProps & {};
type Props = BareProps & {
basePath: string
};
export default class App extends React.PureComponent<Props> {
render () {

View File

@ -2,6 +2,8 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { BareProps } from '@polkadot/ui-app/types';
import React from 'react';
import Navigation from '@polkadot/ui-app/Navigation';
import Page from '@polkadot/ui-app/Page';
@ -19,12 +21,16 @@ const Components: { [index: string]: React.ComponentType<any> } = {
Tut002, Tut003, Tut004, Tut005, Tut006, Tut007
};
type Props = BareProps & {
basePath: string
};
type State = {
Component: React.ComponentType<any>
};
export default class App extends React.PureComponent<any, State> {
constructor (props: any) {
export default class App extends React.PureComponent<Props, State> {
constructor (props: Props) {
super(props);
this.state = {

View File

@ -9,11 +9,6 @@
],
"contributors": [],
"license": "ISC",
"scripts": {
"build": "polkadot-dev-build-babel",
"check": "stylelint 'src/**/*.css' && eslint src && flow check",
"test": "jest --coverage"
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/primitives": "^0.28.14",

View File

@ -13,7 +13,9 @@ import classes from '@polkadot/ui-app/util/classes';
import Summary from './Summary';
import BlockHeaders from './BlockHeaders';
type Props = BareProps & {};
type Props = BareProps & {
basePath: string
};
export default class ExplorerApp extends React.PureComponent<Props> {
render () {

View File

@ -9,11 +9,6 @@
],
"contributors": [],
"license": "ISC",
"scripts": {
"build": "polkadot-dev-build-babel",
"check": "stylelint 'src/**/*.css' && eslint src && flow check",
"test": "jest --coverage"
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/extrinsics": "^0.28.14",

View File

@ -14,7 +14,9 @@ import { QueueConsumer } from '@polkadot/ui-signer/Context';
import Selection from './Selection';
type Props = BareProps;
type Props = BareProps & {
basePath: string
};
export default class ExtrinsicsApp extends React.PureComponent<Props> {
render () {

View File

@ -9,11 +9,6 @@
],
"contributors": [],
"license": "ISC",
"scripts": {
"build": "polkadot-dev-build-babel",
"check": "stylelint 'src/**/*.css' && eslint src && flow check",
"test": "jest --coverage"
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/ui-app": "^0.19.33",

View File

@ -15,7 +15,9 @@ import { QueueConsumer } from '@polkadot/ui-signer/Context';
import Results from './Results';
import Selection from './Selection';
type Props = BareProps & {};
type Props = BareProps & {
basePath: string
};
export default class RpcApp extends React.PureComponent<Props> {
render () {

View File

@ -17,6 +17,7 @@ import StakeList from './StakeList';
import Summary from './Summary';
type Props = BareProps & {
basePath: string,
validatingBalances?: RxBalanceMap,
stakingIntentions?: Array<string>,
sessionValidators?: Array<string>

View File

@ -9,11 +9,6 @@
],
"contributors": [],
"license": "ISC",
"scripts": {
"build": "polkadot-dev-build-babel",
"check": "stylelint 'src/**/*.css' && eslint src && flow check",
"test": "jest --coverage"
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/ui-app": "^0.19.33"

View File

@ -15,7 +15,9 @@ import Queries from './Queries';
import Selection from './Selection';
import translate from './translate';
type Props = I18nProps & {};
type Props = I18nProps & {
basePath: string
};
type State = {
queue: Array<StorageQuery>

View File

@ -9,11 +9,6 @@
],
"contributors": [],
"license": "ISC",
"scripts": {
"build": "polkadot-dev-build-babel",
"check": "stylelint 'src/**/*.css' && eslint src && flow check",
"test": "jest --coverage"
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/ui-app": "^0.19.33",

View File

@ -19,7 +19,9 @@ import translate from './translate';
type Actions = 'hash' | 'sign' | 'verify';
type Props = I18nProps & {};
type Props = I18nProps & {
basePath: string
};
type State = {
action: Actions

View File

@ -9,11 +9,6 @@
],
"contributors": [],
"license": "ISC",
"scripts": {
"build": "polkadot-dev-build-babel",
"check": "stylelint 'src/**/*.css' && eslint src && flow check",
"test": "jest --coverage"
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/ui-app": "^0.19.33",

View File

@ -21,7 +21,9 @@ import matchRegex from './generator/regex';
import generatorSort from './generator/sort';
import translate from './translate';
type Props = I18nProps & {};
type Props = I18nProps & {
basePath: string
};
type State = {
elapsed: number,

View File

@ -11,10 +11,6 @@
],
"contributors": [],
"license": "ISC",
"scripts": {
"build": "polkadot-dev-build-babel",
"check": "stylelint 'src/**/*.css' && eslint src && flow check"
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/app-accounts": "^0.19.33",

View File

@ -0,0 +1,20 @@
// Copyright 2017-2018 @polkadot/apps authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import React from 'react';
import { Redirect } from 'react-router';
import routing from '../routing';
type Props = {};
const defaultTo = `/${routing.default}`;
export default class NotFound extends React.PureComponent<Props> {
render () {
return (
<Redirect to={defaultTo} />
);
}
}

View File

@ -3,7 +3,6 @@
// of the ISC license. See the LICENSE file for details.
import { I18nProps } from '@polkadot/ui-app/types';
import { Route } from '../types';
import './Content.css';
@ -13,28 +12,32 @@ import { withRouter } from 'react-router';
import classes from '@polkadot/ui-app/util/classes';
import routing from '../routing';
import NotFound from './NotFound';
type Props = I18nProps & {
location: Location
};
const unknown = {
Component: NotFound,
name: ''
};
class Content extends React.PureComponent<Props> {
render () {
const { className, location, style } = this.props;
const app = location.pathname.slice(1) || routing.default;
const { Component } = routing.routes.find((route: Route | null) =>
route
? route.name === app
: false
) || routing.unknown;
const app = location.pathname.slice(1) || '';
const { Component, name } = routing.routes.find((route) =>
!!(route && app.indexOf(route.name) === 0)
) || unknown;
return (
<div
className={classes('apps--Content', className)}
style={style}
>
<Component />
<Component basePath={`/${name}`} />
</div>
);
}

View File

@ -1,7 +0,0 @@
/* Copyright 2017-2018 @polkadot/apps authors & contributors
/* This software may be modified and distributed under the terms
/* of the ISC license. See the LICENSE file for details. */
.apps--NotFound {
color: red;
}

View File

@ -1,34 +0,0 @@
// Copyright 2017-2018 @polkadot/apps authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { I18nProps } from '@polkadot/ui-app/types';
import './NotFound.css';
import React from 'react';
import classes from '@polkadot/ui-app/util/classes';
import translate from '../translate';
type Props = I18nProps & {};
class NotFound extends React.PureComponent<Props> {
render () {
const { className, style, t } = this.props;
return (
<div
className={classes('apps--NotFound', className)}
style={style}
>
{t('notfound.error', {
defaultValue: 'ERROR: You have tried to access an application that does not exist'
})}
</div>
);
}
}
export default translate(NotFound);

View File

@ -20,15 +20,14 @@ type Props = I18nProps & {
class Item extends React.PureComponent<Props> {
render () {
const { route: { i18n, icon, isExact, name, path = '' }, t } = this.props;
const { route: { i18n, icon, name }, t } = this.props;
return (
<Menu.Item className='apps--SideBar-Item'>
<NavLink
activeClassName='apps--SideBar-Item-NavLink-active'
className='apps--SideBar-Item-NavLink'
exact={isExact}
to={path || `/${name}`}
to={`/${name}`}
>
<Icon name={icon} /> {t(`sidebar.${name}`, i18n)}
</NavLink>

View File

@ -13,7 +13,6 @@ export default ([
defaultValue: 'Accounts'
},
icon: 'users',
isExact: false,
isHidden: false,
name: 'accounts'
}

View File

@ -13,7 +13,6 @@ export default ([
defaultValue: 'Addresses'
},
icon: 'address book',
isExact: false,
isHidden: false,
name: 'addresses'
}

View File

@ -13,7 +13,6 @@ export default ([
defaultValue: 'Democracy'
},
icon: 'calendar check',
isExact: false,
isHidden: false,
name: 'democracy'
}

View File

@ -13,7 +13,6 @@ export default ([
defaultValue: 'Example'
},
icon: 'hand spock',
isExact: false,
isHidden: true,
name: 'example'
}

View File

@ -13,9 +13,7 @@ export default ([
defaultValue: 'Explorer'
},
icon: 'braille',
isExact: true,
isHidden: false,
name: 'explorer',
path: '/'
name: 'explorer'
}
] as Routes);

View File

@ -13,7 +13,6 @@ export default ([
defaultValue: 'Extrinsics'
},
icon: 'send',
isExact: false,
isHidden: false,
name: 'extrinsics'
}

View File

@ -16,7 +16,6 @@ import rpc from './rpc';
import staking from './staking';
import storage from './storage';
import toolbox from './toolbox';
import unknown from './unknown';
import vanitygen from './vanitygen';
export default ({
@ -36,6 +35,5 @@ export default ({
null,
rpc,
toolbox
),
unknown
)
} as Routing);

View File

@ -13,7 +13,6 @@ export default ([
defaultValue: 'Raw RPC'
},
icon: 'code',
isExact: false,
isHidden: false,
name: 'rpc'
}

View File

@ -13,7 +13,6 @@ export default ([
defaultValue: 'Staking'
},
icon: 'certificate',
isExact: false,
isHidden: false,
name: 'staking'
}

View File

@ -13,7 +13,6 @@ export default ([
defaultValue: 'Storage'
},
icon: 'database',
isExact: false,
isHidden: false,
name: 'storage'
}

View File

@ -13,7 +13,6 @@ export default ([
defaultValue: 'Toolbox'
},
icon: 'configure',
isExact: false,
isHidden: false,
name: 'toolbox'
}

View File

@ -1,18 +0,0 @@
// Copyright 2017-2018 @polkadot/apps authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { Route } from '../types';
import NotFound from '../NotFound';
export default ({
Component: NotFound,
i18n: {
defaultValue: 'Not found'
},
icon: 'warning circle',
isExact: false,
isHidden: true,
name: 'unknown'
} as Route);

View File

@ -13,7 +13,6 @@ export default ([
defaultValue: 'Vanity'
},
icon: 'hand lizard',
isExact: false,
isHidden: false,
name: 'vanitygen'
}

View File

@ -5,20 +5,21 @@
import { SemanticICONS } from 'semantic-ui-react/dist/commonjs';
import { BareProps } from '@polkadot/ui-app/types';
export type RouteProps = BareProps & {
basePath: string
}
export type Route = {
Component: React.ComponentType<BareProps>,
Component: React.ComponentType<RouteProps>,
i18n: any, // I18Next$Translate$Config,
icon: SemanticICONS,
isExact: boolean,
isHidden: boolean,
name: string,
path?: string
name: string
};
export type Routes = Array<Route | null>;
export type Routing = {
default: string,
routes: Routes,
unknown: Route
routes: Routes
}

View File

@ -9,11 +9,6 @@
],
"contributors": [],
"license": "ISC",
"scripts": {
"build": "polkadot-dev-build-babel",
"check": "stylelint 'src/**/*.css' && eslint src && flow check",
"test": "jest --coverage"
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/ui-react": "^0.19.33",

View File

@ -29,11 +29,6 @@
"url": "https://github.com/polkadot-js/ui/issues"
},
"homepage": "https://github.com/polkadot-js/ui/tree/master/packages/ui-react-rx#readme",
"scripts": {
"build": "polkadot-dev-build-babel",
"check": "eslint src && flow check",
"test": "echo \"Tests only available from root wrapper\""
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/api-rx": "^0.28.14",

View File

@ -3,11 +3,6 @@
"version": "0.19.33",
"description": "A collection of base React components",
"main": "index.js",
"scripts": {
"build": "polkadot-dev-build-babel",
"check": "stylelint 'src/**/*.css' && eslint src && flow check",
"test": "echo \"Tests only available from root wrapper\""
},
"author": "Jaco Greeff <jacogr@gmail.com>",
"maintainers": [
"Jaco Greeff <jacogr@gmail.com>"

View File

@ -9,11 +9,6 @@
],
"contributors": [],
"license": "ISC",
"scripts": {
"build": "polkadot-dev-build-babel",
"check": "stylelint 'src/**/*.css' && eslint src && flow check",
"test": "jest --coverage"
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/extrinsics": "^0.28.14",