Skip to content

Commit

Permalink
Merge "[CE-389] Add smart contract info page"
Browse files Browse the repository at this point in the history
  • Loading branch information
hightall authored and Gerrit Code Review committed Jun 22, 2018
2 parents a5f98ca + ef9b808 commit 5162a2b
Show file tree
Hide file tree
Showing 51 changed files with 1,857 additions and 314 deletions.
3 changes: 2 additions & 1 deletion user-dashboard/src/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "eslint-config-egg",
"rules": {
"array-bracket-spacing": [0],
"no-extend-native": [0]
"no-extend-native": [0],
"no-bitwise": [0]
},
"parser": "babel-eslint"
}
1 change: 1 addition & 0 deletions user-dashboard/src/.ui-eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"react/jsx-no-bind": [0],
"react/prop-types": [0],
"react/prefer-stateless-function": [0],
"react/no-did-mount-set-state": [0],
"react/jsx-wrap-multilines": [
"error",
{
Expand Down
56 changes: 39 additions & 17 deletions user-dashboard/src/app/assets/src/common/menu.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,52 @@
/*
SPDX-License-Identifier: Apache-2.0
*/
import { isUrl } from '../utils/utils';
import { isUrl } from "../utils/utils";

const menuData = [
{
name: 'Chain',
icon: 'link',
path: 'chain',
name: "Chain",
icon: "link",
path: "chain",
},
{
name: 'Apply Chain',
path: 'apply-chain',
name: "Apply Chain",
path: "apply-chain",
hideInMenu: true,
hideInBreadcrumb: false,
},
{
name: 'Smart Contract',
path: 'smart-contract',
icon: 'code-o',
},
{
name: 'Create New Smart Contract',
path: 'new-smart-contract',
hideInMenu: true,
hideInBreadcrumb: false,
name: "Smart Contract",
path: "smart-contract",
icon: "code-o",
children: [
{
name: "List",
path: "index",
},
{
name: "Info",
path: "info/:id",
hideInMenu: true,
hideInBreadcrumb: false,
},
{
name: "Create",
path: "new",
hideInMenu: true,
hideInBreadcrumb: false,
},
{
name: "New Code",
path: "new-code",
hideInMenu: true,
hideInBreadcrumb: false,
},
],
},
];

function formatter(data, parentPath = '/', parentAuthority) {
function formatter(data, parentPath = "/", parentAuthority) {
return data.map(item => {
let { path } = item;
if (!isUrl(path)) {
Expand All @@ -40,7 +58,11 @@ function formatter(data, parentPath = '/', parentAuthority) {
authority: item.authority || parentAuthority,
};
if (item.children) {
result.children = formatter(item.children, `${parentPath}${item.path}/`, item.authority);
result.children = formatter(
item.children,
`${parentPath}${item.path}/`,
item.authority
);
}
return result;
});
Expand Down
86 changes: 58 additions & 28 deletions user-dashboard/src/app/assets/src/common/router.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/*
SPDX-License-Identifier: Apache-2.0
*/
import { createElement } from 'react';
import dynamic from 'dva/dynamic';
import pathToRegexp from 'path-to-regexp';
import { getMenuData } from './menu';
import { createElement } from "react";
import dynamic from "dva/dynamic";
import pathToRegexp from "path-to-regexp";
import { getMenuData } from "./menu";

let routerDataCache;

const modelNotExisted = (app, model) =>
// eslint-disable-next-line
!app._models.some(({ namespace }) => {
return namespace === model.substring(model.lastIndexOf('/') + 1);
return namespace === model.substring(model.lastIndexOf("/") + 1);
});

// wrapper of dynamic
const dynamicWrapper = (app, models, component) => {
// () => require('module')
// transformed by babel-plugin-dynamic-import-node-sync
if (component.toString().indexOf('.then(') < 0) {
if (component.toString().indexOf(".then(") < 0) {
models.forEach(model => {
if (modelNotExisted(app, model)) {
// eslint-disable-next-line
Expand All @@ -39,7 +39,9 @@ const dynamicWrapper = (app, models, component) => {
return dynamic({
app,
models: () =>
models.filter(model => modelNotExisted(app, model)).map(m => import(`../models/${m}.js`)),
models
.filter(model => modelNotExisted(app, model))
.map(m => import(`../models/${m}.js`)),
// add routerData prop
component: () => {
if (!routerDataCache) {
Expand Down Expand Up @@ -72,35 +74,61 @@ function getFlatMenuData(menus) {

export const getRouterData = app => {
const routerConfig = {
'/': {
component: dynamicWrapper(app, ['user', 'login'], () => import('../layouts/BasicLayout')),
"/": {
component: dynamicWrapper(app, ["user", "login"], () =>
import("../layouts/BasicLayout")
),
},
'/chain': {
component: dynamicWrapper(app, ['chain'], () => import('../routes/Chain')),
"/chain": {
component: dynamicWrapper(app, ["chain"], () => import("../routes/Chain")),
},
'/apply-chain': {
component: dynamicWrapper(app, ['chain'], () => import('../routes/Chain/Apply')),
"/apply-chain": {
component: dynamicWrapper(app, ["chain"], () =>
import("../routes/Chain/Apply")
),
},
'/exception/403': {
component: dynamicWrapper(app, [], () => import('../routes/Exception/403')),
"/exception/403": {
component: dynamicWrapper(app, [], () =>
import("../routes/Exception/403")
),
},
'/exception/404': {
component: dynamicWrapper(app, [], () => import('../routes/Exception/404')),
"/exception/404": {
component: dynamicWrapper(app, [], () =>
import("../routes/Exception/404")
),
},
'/exception/500': {
component: dynamicWrapper(app, [], () => import('../routes/Exception/500')),
"/exception/500": {
component: dynamicWrapper(app, [], () =>
import("../routes/Exception/500")
),
},
'/user': {
component: dynamicWrapper(app, [], () => import('../layouts/UserLayout')),
"/user": {
component: dynamicWrapper(app, [], () => import("../layouts/UserLayout")),
},
'/user/login': {
component: dynamicWrapper(app, ['login'], () => import('../routes/User/Login')),
"/user/login": {
component: dynamicWrapper(app, ["login"], () =>
import("../routes/User/Login")
),
},
'/smart-contract': {
component: dynamicWrapper(app, ['smartContract'], () => import('../routes/SmartContract')),
"/smart-contract/index": {
component: dynamicWrapper(app, ["smartContract"], () =>
import("../routes/SmartContract")
),
},
'/new-smart-contract': {
component: dynamicWrapper(app, ['smartContract'], () => import('../routes/SmartContract/New')),
"/smart-contract/info/:id": {
component: dynamicWrapper(app, ["smartContract", "chain"], () =>
import("../routes/SmartContract/Info")
),
},
"/smart-contract/new": {
component: dynamicWrapper(app, ["smartContract"], () =>
import("../routes/SmartContract/New")
),
},
"/smart-contract/new-code/:id": {
component: dynamicWrapper(app, ["smartContract"], () =>
import("../routes/SmartContract/New/code")
),
},
};
// Get name from ./menu.js or just set it in the router data.
Expand All @@ -114,7 +142,9 @@ export const getRouterData = app => {
// Regular match item name
// eg. router /user/:id === /user/chen
const pathRegexp = pathToRegexp(path);
const menuKey = Object.keys(menuData).find(key => pathRegexp.test(`${key}`));
const menuKey = Object.keys(menuData).find(key =>
pathRegexp.test(`${key}`)
);
let menuItem = {};
// If menuKey is not empty
if (menuKey) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { Col } from 'antd';
import styles from './index.less';
import responsive from './responsive';

const Description = ({ term, column, className, children, ...restProps }) => {
const clsString = classNames(styles.description, className);
return (
<Col className={clsString} {...responsive[column]} {...restProps}>
{term && <div className={styles.term}>{term}</div>}
{children !== null && children !== undefined &&
<div className={styles.detail}>{children}</div>}
</Col>
);
};

Description.defaultProps = {
term: '',
};

Description.propTypes = {
term: PropTypes.node,
};

export default Description;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import classNames from 'classnames';
import { Row } from 'antd';
import styles from './index.less';

const DescriptionList = ({
className,
title,
col = 3,
layout = 'horizontal',
gutter = 32,
children,
size,
...restProps
}) => {
const clsString = classNames(styles.descriptionList, styles[layout], className, {
[styles.small]: size === 'small',
[styles.large]: size === 'large',
});
const column = col > 4 ? 4 : col;
return (
<div className={clsString} {...restProps}>
{title ? <div className={styles.title}>{title}</div> : null}
<Row gutter={gutter}>
{React.Children.map(children, child => child ? React.cloneElement(child, { column }) : child)}
</Row>
</div>
);
};

export default DescriptionList;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import DescriptionList from './DescriptionList';
import Description from './Description';

DescriptionList.Description = Description;
export default DescriptionList;
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
@import '~antd/lib/style/themes/default.less';

.descriptionList {
// offset the padding-bottom of last row
:global {
.ant-row {
margin-bottom: -16px;
overflow: hidden;
}
}

.title {
font-size: 14px;
color: @heading-color;
font-weight: 500;
margin-bottom: 16px;
}

.term {
// Line-height is 22px IE dom height will calculate error
line-height: 20px;
padding-bottom: 16px;
margin-right: 8px;
color: @heading-color;
white-space: nowrap;
display: table-cell;

&:after {
content: ':';
margin: 0 8px 0 2px;
position: relative;
top: -0.5px;
}
}

.detail {
line-height: 22px;
width: 100%;
padding-bottom: 16px;
color: @text-color;
display: table-cell;
}

&.small {
// offset the padding-bottom of last row
:global {
.ant-row {
margin-bottom: -8px;
}
}
.title {
margin-bottom: 12px;
color: @text-color;
}
.term,
.detail {
padding-bottom: 8px;
}
}

&.large {
.title {
font-size: 16px;
}
}

&.vertical {
.term {
padding-bottom: 8px;
display: block;
}

.detail {
display: block;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
1: { xs: 24 },
2: { xs: 24, sm: 12 },
3: { xs: 24, sm: 12, md: 8 },
4: { xs: 24, sm: 12, md: 6 },
};
Loading

0 comments on commit 5162a2b

Please sign in to comment.