Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: isv role page #803

Merged
merged 1 commit into from
Feb 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/Collapse/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
height: 0;
opacity: 0;
transition: all .3s ease;
pointer-events: none;
}

.isCheck {
Expand Down
65 changes: 65 additions & 0 deletions src/portals/isv/pages/Roles/ModuleFeatures/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React, { Component } from 'react';
import { observer } from 'mobx-react';
import classnames from 'classnames';
import _ from 'lodash';

import styles from './index.scss';

const sortModule = id => (a, b) => {
const numA = Number(_.last(a[id].split(id[0])));
const numB = Number(_.last(b[id].split(id[0])));
return numA - numB;
};

const getArray = (array, id) => {
if (!_.isArray(array)) return [];

return array.slice().sort(sortModule(id));
};

const isCheckAll = (module, feature) => {
if (module.is_check_all) {
return true;
}
const getUniqActions = () => _.flatMap(
_.uniqBy(feature.action_bundle, 'action_bundle_id'),
'action_bundle_id'
);

const total = getUniqActions(feature).length;
const selectedCount = _.uniq(feature.checked_action_id).length;
return selectedCount === total;
};

@observer
export default class ModuleFeatures extends Component {
render() {
const { roleStore, roleId } = this.props;
const { moduleNames } = roleStore;
const modules = moduleNames[roleId];
if (!modules) return null;

return (
<div className={styles.container}>
{getArray(modules, 'module_id').map(module => (
<div key={module.module_id}>
<div className={classnames(styles.item, styles.moduleName)}>
{module.module_name}
</div>
{getArray(module.feature, 'feature_id').map(feature => (
<div
key={feature.feature_id}
className={classnames(styles.item, {
[styles.gray]: !isCheckAll(module, feature),
[styles.moduleName]: isCheckAll(module, feature)
})}
>
{feature.feature_name}
</div>
))}
</div>
))}
</div>
);
}
}
26 changes: 26 additions & 0 deletions src/portals/isv/pages/Roles/ModuleFeatures/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@import '~scss/vars';

.container {
display: flex;
flex-flow: row wrap;
@include normal-font;

> div {
width: 25%;
margin-bottom: 15px;
}
}

.moduleName {
color: $N500;
font-weight: 500;
}
.gray {
color: $N75;
font-weight: normal;
}

.item {
margin-top: 8px;
margin-bottom: 8px;
}
46 changes: 29 additions & 17 deletions src/portals/isv/pages/Roles/index.jsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
import React, { Component } from 'react';
/* import PropTypes from 'prop-types';
* import classnames from 'classnames'; */
import { observer, inject } from 'mobx-react';
import { translate } from 'react-i18next';
import Layout from 'components/Layout';
import Collapse from 'components/Collapse';
import ModuleFeature from './ModuleFeatures';

import styles from './index.scss';

@translate()
@inject(({ rootStore }) => ({
roleStore: rootStore.roleStore
}))
@observer
export default class TeamRole extends Component {
renderTitle({ title, describtion }) {
async componentDidMount() {
const { roleStore } = this.props;

await roleStore.fetchAll();
}

renderTitle({ role_name, description }) {
return (
<div>
<h3 className={styles.title}>{title}</h3>
<div className={styles.describtion}>{describtion}</div>
<h3 className={styles.title}>{role_name}</h3>
<div className={styles.describtion}>{description}</div>
</div>
);
}

onChange = (role, isCheck) => {
if (!isCheck) return null;

const { roleStore } = this.props;
roleStore.fetchRoleModuleName(role.role_id);
};

render() {
const roles = [
{
title: '超级管理员',
describtion: '拥有所有功能的最高权限,不得编辑和删除。'
},
{
title: '开发人员',
describtion: '负责开发、测试、运维应用。'
}
];
const { roleStore } = this.props;
const { roles } = roleStore;
return (
<Layout
className={styles.container}
Expand All @@ -36,12 +47,13 @@ export default class TeamRole extends Component {
>
{roles.map(role => (
<Collapse
key={role.title}
key={role.role_id}
className={styles.roleContainer}
header={this.renderTitle(role)}
onChange={isCheck => this.onChange(role, isCheck)}
iconPosition="right"
>
test
<ModuleFeature roleId={role.role_id} roleStore={roleStore} />
</Collapse>
))}
</Layout>
Expand Down
13 changes: 13 additions & 0 deletions src/stores/user/role.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export default class RoleStore extends Store {

@observable modules = [];

@observable moduleNames = {};

@observable features = [];

@observable selectedRoleKeys = [];
Expand Down Expand Up @@ -75,6 +77,7 @@ export default class RoleStore extends Store {
this.isLoading = false;
}

@action
async fetchRoleModule(roleId) {
this.isLoading = true;
const result = await this.request.get(`roles:module`, {
Expand All @@ -85,6 +88,16 @@ export default class RoleStore extends Store {
this.isLoading = false;
}

@action
async fetchRoleModuleName(roleId) {
this.isLoading = true;
const result = await this.request.get(`roles:module`, {
role_id: roleId
});
this.moduleNames[roleId] = _.get(result, 'role_module.module', []);
this.isLoading = false;
}

@action
getModuleTreeData = () => {
const data = [
Expand Down
2 changes: 1 addition & 1 deletion test/pages/__snapshots__/Home.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Array [
class="section section-size-dev-9 section-offset-dev-0"
>
<div
class="apps"
class=""
>
<div
class="appList fixNav"
Expand Down