@@ -18,6 +18,8 @@ import {
1818 isEmptyNil ,
1919 isObject ,
2020 maybe ,
21+ mapKey ,
22+ mapValue ,
2123 objToArray ,
2224} from '../../utils'
2325
@@ -44,10 +46,6 @@ const debug = makeDebugger('C:PermissionEditor')
4446const valueIsObj = v => isObject ( v )
4547const valueIsNotObj = R . complement ( valueIsObj )
4648
47- // TODO: move to utils
48- const mapKey = R . compose ( R . head , R . keys )
49- const mapValue = R . compose ( R . head , R . values )
50-
5149const tooltipOffset = JSON . stringify ( { top : 5 , right : - 5 } )
5250
5351const getManagedCommunitiesRaws = userRules => {
@@ -112,25 +110,40 @@ const getCurUserRules = (data, curView, activeRaw) => {
112110 return maybe ( userRulesByCommunities [ activeRaw ] , { } )
113111}
114112
115- const PermissionList = ( { data, allRules, curView, activeRaw } ) => {
113+ const PermissionList = ( {
114+ data,
115+ allRules,
116+ selectRules,
117+ curView,
118+ activeRaw,
119+ } ) => {
116120 if ( isEmptyNil ( data ) ) {
117121 return < div />
118122 }
119123
120124 const curUserRules = getCurUserRules ( data , curView , activeRaw )
125+ const selectGeneralRules = R . filter ( valueIsNotObj , selectRules )
126+ const selectCommunityRules = R . filter ( valueIsObj , selectRules )
121127
122128 const curAllRules =
123129 curView === 'general'
124130 ? getJson ( allRules . general )
125131 : getJson ( allRules . community )
126132
127- const dataArray = objToArray ( R . merge ( curAllRules , curUserRules ) )
133+ const curSelectRules =
134+ curView === 'general' ? selectGeneralRules : selectCommunityRules [ activeRaw ]
135+
136+ const curActiveRules = R . merge ( curUserRules , curSelectRules )
137+ const ruleArray = objToArray ( R . merge ( curAllRules , curActiveRules ) )
128138
129139 return (
130140 < PermissionWrapper >
131141 < React . Fragment >
132- { dataArray . map ( p => (
133- < PerItem key = { shortid . generate ( ) } >
142+ { ruleArray . map ( p => (
143+ < PerItem
144+ key = { shortid . generate ( ) }
145+ onClick = { logic . onRuleClick . bind ( this , p ) }
146+ >
134147 < PerTitle > { mapKey ( p ) } </ PerTitle > < CheckMark active = { mapValue ( p ) } />
135148 </ PerItem >
136149 ) ) }
@@ -156,6 +169,7 @@ class PermissionEditorContainer extends React.Component {
156169 allRulesData,
157170 curView,
158171 curCommunityRaw,
172+ selectRulesData,
159173 } = permissionEditor
160174
161175 const user = editData . data
@@ -176,6 +190,7 @@ class PermissionEditorContainer extends React.Component {
176190 < Divider />
177191 < PermissionList
178192 data = { cmsPassportString }
193+ selectRules = { selectRulesData }
179194 allRules = { allRulesData . cms }
180195 curView = { curView }
181196 activeRaw = { curCommunityRaw }
@@ -198,7 +213,7 @@ class PermissionEditorContainer extends React.Component {
198213 < Icon type = "loading" /> 保存中
199214 </ Button >
200215 ) : (
201- < Button type = "primary" onClick = { debug } >
216+ < Button type = "primary" onClick = { logic . confirm . bind ( this , user . id ) } >
202217 保存
203218 </ Button >
204219 ) }
0 commit comments