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:
parent
6183cc27d6
commit
8155e94d05
@ -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"
|
||||
|
||||
@ -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';
|
||||
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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';
|
||||
|
||||
|
||||
@ -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 () {
|
||||
|
||||
@ -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 = {
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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 () {
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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 () {
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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 () {
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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",
|
||||
|
||||
20
packages/apps/src/Content/NotFound.tsx
Normal file
20
packages/apps/src/Content/NotFound.tsx
Normal 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} />
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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);
|
||||
@ -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>
|
||||
|
||||
@ -13,7 +13,6 @@ export default ([
|
||||
defaultValue: 'Accounts'
|
||||
},
|
||||
icon: 'users',
|
||||
isExact: false,
|
||||
isHidden: false,
|
||||
name: 'accounts'
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@ export default ([
|
||||
defaultValue: 'Addresses'
|
||||
},
|
||||
icon: 'address book',
|
||||
isExact: false,
|
||||
isHidden: false,
|
||||
name: 'addresses'
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@ export default ([
|
||||
defaultValue: 'Democracy'
|
||||
},
|
||||
icon: 'calendar check',
|
||||
isExact: false,
|
||||
isHidden: false,
|
||||
name: 'democracy'
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@ export default ([
|
||||
defaultValue: 'Example'
|
||||
},
|
||||
icon: 'hand spock',
|
||||
isExact: false,
|
||||
isHidden: true,
|
||||
name: 'example'
|
||||
}
|
||||
|
||||
@ -13,9 +13,7 @@ export default ([
|
||||
defaultValue: 'Explorer'
|
||||
},
|
||||
icon: 'braille',
|
||||
isExact: true,
|
||||
isHidden: false,
|
||||
name: 'explorer',
|
||||
path: '/'
|
||||
name: 'explorer'
|
||||
}
|
||||
] as Routes);
|
||||
|
||||
@ -13,7 +13,6 @@ export default ([
|
||||
defaultValue: 'Extrinsics'
|
||||
},
|
||||
icon: 'send',
|
||||
isExact: false,
|
||||
isHidden: false,
|
||||
name: 'extrinsics'
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -13,7 +13,6 @@ export default ([
|
||||
defaultValue: 'Raw RPC'
|
||||
},
|
||||
icon: 'code',
|
||||
isExact: false,
|
||||
isHidden: false,
|
||||
name: 'rpc'
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@ export default ([
|
||||
defaultValue: 'Staking'
|
||||
},
|
||||
icon: 'certificate',
|
||||
isExact: false,
|
||||
isHidden: false,
|
||||
name: 'staking'
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@ export default ([
|
||||
defaultValue: 'Storage'
|
||||
},
|
||||
icon: 'database',
|
||||
isExact: false,
|
||||
isHidden: false,
|
||||
name: 'storage'
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@ export default ([
|
||||
defaultValue: 'Toolbox'
|
||||
},
|
||||
icon: 'configure',
|
||||
isExact: false,
|
||||
isHidden: false,
|
||||
name: 'toolbox'
|
||||
}
|
||||
|
||||
@ -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);
|
||||
@ -13,7 +13,6 @@ export default ([
|
||||
defaultValue: 'Vanity'
|
||||
},
|
||||
icon: 'hand lizard',
|
||||
isExact: false,
|
||||
isHidden: false,
|
||||
name: 'vanitygen'
|
||||
}
|
||||
|
||||
13
packages/apps/src/types.d.ts
vendored
13
packages/apps/src/types.d.ts
vendored
@ -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
|
||||
}
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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>"
|
||||
|
||||
@ -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",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user