Skip to content

Commit b8769dc

Browse files
committed
permission update done
1 parent 1642b79 commit b8769dc

File tree

9 files changed

+114
-13
lines changed

9 files changed

+114
-13
lines changed

components/LoadingEffects/TableLoading.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const LoadingText = styled.div`
2525
const TableLoading = () => (
2626
<LoadingWrapper>
2727
<LoadingIcon src={`${ICON_ASSETS}/cmd/rainbow_logo.svg`} />
28-
<LoadingText>... 漫威的编辑真心可以 ...</LoadingText>
28+
<LoadingText>... 漫威的编剧真心可以 ...</LoadingText>
2929
</LoadingWrapper>
3030
)
3131

containers/PermissionEditor/index.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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')
4446
const valueIsObj = v => isObject(v)
4547
const 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-
5149
const tooltipOffset = JSON.stringify({ top: 5, right: -5 })
5250

5351
const 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
)}

containers/PermissionEditor/logic.js

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
// import R from 'ramda'
1+
import R from 'ramda'
22

3-
import { makeDebugger, $solver, asyncRes } from '../../utils'
3+
import {
4+
makeDebugger,
5+
$solver,
6+
asyncRes,
7+
mapKey,
8+
mapValue,
9+
TYPE,
10+
closePreviewer,
11+
} from '../../utils'
412
import SR71 from '../../utils/network/sr71'
513
import { PAGE_SIZE } from '../../config'
614

@@ -34,6 +42,30 @@ export function communitySelect(curCommunityRaw) {
3442
})
3543
}
3644

45+
export function onRuleClick(rule) {
46+
/* let selectRules = JSON.parse(permissionEditor.selectRules) */
47+
const { curCommunityRaw } = permissionEditor
48+
let { selectRulesData } = permissionEditor
49+
50+
if (curCommunityRaw === 'general') {
51+
selectRulesData = R.merge(selectRulesData, {
52+
[mapKey(rule)]: !mapValue(rule),
53+
})
54+
} else {
55+
const curCommunitySelectRules = R.mergeDeepRight(selectRulesData, {
56+
[curCommunityRaw]: {
57+
[mapKey(rule)]: !mapValue(rule),
58+
},
59+
})
60+
61+
selectRulesData = R.merge(selectRulesData, curCommunitySelectRules)
62+
}
63+
64+
permissionEditor.markState({
65+
selectRules: JSON.stringify(selectRulesData),
66+
})
67+
}
68+
3769
export function getAllCommunities(page = 1) {
3870
sr71$.query(S.pagedCommunities, commonFilter(page))
3971
}
@@ -42,6 +74,13 @@ export function getAllRules() {
4274
sr71$.query(S.allPassportRulesString, {})
4375
}
4476

77+
export function confirm(userId) {
78+
debug('confirm ..userId: ', userId)
79+
debug('selectRules --> ', permissionEditor.selectRules)
80+
const rules = permissionEditor.selectRules
81+
sr71$.mutate(S.stampCmsPassport, { userId, rules })
82+
}
83+
4584
// ###############################
4685
// Data & Error handlers
4786
// ###############################
@@ -64,6 +103,15 @@ const DataSolver = [
64103
})
65104
},
66105
},
106+
{
107+
match: asyncRes('stampCmsPassport'),
108+
action: () => {
109+
closePreviewer(TYPE.USERS_REFRESH)
110+
permissionEditor.markState({
111+
selectRules: '{}',
112+
})
113+
},
114+
},
67115
]
68116
const ErrSolver = []
69117

containers/PermissionEditor/schema.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,18 @@ const allPassportRulesString = gql`
2525
}
2626
`
2727

28+
const stampCmsPassport = gql`
29+
mutation($userId: ID!, $rules: String!) {
30+
stampCmsPassport(userId: $userId, rules: $rules) {
31+
id
32+
}
33+
}
34+
`
35+
2836
const schema = {
2937
pagedCommunities,
3038
allPassportRulesString,
39+
stampCmsPassport,
3140
}
3241

3342
export default schema

containers/UsersContent/logic.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import { PAGE_SIZE } from '../../config'
1414
import S from './schema'
1515
import SR71 from '../../utils/network/sr71'
1616

17-
const sr71$ = new SR71()
17+
const sr71$ = new SR71({
18+
resv_event: [EVENT.PREVIEW_CLOSE],
19+
})
1820
let sub$ = null
1921

2022
/* eslint-disable no-unused-vars */
@@ -71,6 +73,22 @@ const DataSolver = [
7173
})
7274
},
7375
},
76+
{
77+
match: asyncRes(EVENT.PREVIEW_CLOSE),
78+
action: res => {
79+
const closeType = res[EVENT.PREVIEW_CLOSE].type
80+
switch (closeType) {
81+
case TYPE.USERS_REFRESH: {
82+
const { pageNumber } = usersContent.pagedUsersData
83+
return loadUsers(pageNumber)
84+
}
85+
default: {
86+
debug('unknow event: ', closeType)
87+
/* return loadPosts() */
88+
}
89+
}
90+
},
91+
},
7492
]
7593
const ErrSolver = []
7694

stores/PermissionEditorStore/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const PermissionEditorStore = t
3131
'general'
3232
),
3333
curCommunityRaw: t.optional(t.string, 'general'),
34+
selectRules: t.optional(t.string, '{}'),
3435
})
3536
.views(self => ({
3637
get root() {
@@ -42,6 +43,9 @@ const PermissionEditorStore = t
4243
get allRulesData() {
4344
return stripMobx(self.allRules)
4445
},
46+
get selectRulesData() {
47+
return JSON.parse(self.selectRules)
48+
},
4549
}))
4650
.actions(self => ({
4751
markState(sobj) {

utils/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ export const TYPE = {
9696
COMMUNITIES_REFRESH: 'COMMUNITIES_REFRESH',
9797
TAGS_REFRESH: 'TAGS_REFRESH',
9898
GATEGORIES_REFRESH: 'GATEGORIES_REFRESH',
99+
100+
USERS_REFRESH: 'USERS_REFRESH',
99101
}
100102

101103
export const ROUTE = {

utils/functions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ export const objToArray = input =>
5353
return { [key]: input[key] }
5454
})
5555

56+
export const mapKey = R.compose(R.head, R.keys)
57+
export const mapValue = R.compose(R.head, R.values)
58+
5659
// reference: https://blog.carbonfive.com/2017/12/20/easy-pipeline-debugging-with-curried-console-log/
5760
export const Rlog = (arg = 'Rlog: ') => R.tap(log(arg))
5861

utils/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export { makeDebugger } from './debug'
1111
export {
1212
dispatchEvent,
1313
mapKeys,
14+
mapKey,
15+
mapValue,
1416
isObject,
1517
maybe,
1618
objToArray,

0 commit comments

Comments
 (0)