1
1
import { GroupRoleInfo , GroupUser , OrgGroup , TacoRoles } from "constants/orgConstants" ;
2
2
import { User } from "constants/userConstants" ;
3
- import { AddIcon , ArrowIcon , CustomSelect , PackUpIcon , SuperUserIcon } from "lowcoder-design" ;
3
+ import { AddIcon , ArrowIcon , CustomSelect , PackUpIcon , Search , SuperUserIcon } from "lowcoder-design" ;
4
4
import { trans } from "i18n" ;
5
5
import ProfileImage from "pages/common/profileImage" ;
6
- import React , { useMemo } from "react" ;
6
+ import React , { useCallback , useEffect , useMemo , useState } from "react" ;
7
7
import { useDispatch } from "react-redux" ;
8
8
import {
9
9
deleteGroupUserAction ,
@@ -20,7 +20,6 @@ import {
20
20
GroupNameView ,
21
21
HeaderBack ,
22
22
LAST_ADMIN_QUIT ,
23
- PermissionHeaderWrapper ,
24
23
QuestionTooltip ,
25
24
RoleSelectSubTitle ,
26
25
RoleSelectTitle ,
@@ -31,13 +30,35 @@ import {
31
30
import history from "util/history" ;
32
31
import { PERMISSION_SETTING } from "constants/routesURL" ;
33
32
import Column from "antd/es/table/Column" ;
33
+ import { debounce } from "lodash" ;
34
+ import { fetchGroupUsrPagination } from "@lowcoder-ee/util/pagination/axios" ;
34
35
35
36
const StyledAddIcon = styled ( AddIcon ) `
36
37
g path {
37
38
fill: #ffffff;
38
39
}
39
40
` ;
40
41
42
+ const PermissionHeaderWrapper = styled . div `
43
+ display: flex;
44
+ align-items: center;
45
+ justify-content: space-between;
46
+ width: 100%;
47
+ margin-bottom: 16px;
48
+ ` ;
49
+
50
+ const OptionsHeader = styled . div `
51
+ display: flex;
52
+ align-items: center;
53
+ gap: 12px;
54
+ ` ;
55
+
56
+ type ElementsState = {
57
+ elements : any [ ] ;
58
+ total : number ;
59
+ role : string ;
60
+ } ;
61
+
41
62
type GroupPermissionProp = {
42
63
group : OrgGroup ;
43
64
orgId : string ;
@@ -47,11 +68,24 @@ type GroupPermissionProp = {
47
68
setModify ?: any ;
48
69
modify ?: boolean ;
49
70
loading ?: boolean ;
71
+ setElements : React . Dispatch < React . SetStateAction < ElementsState > > ;
50
72
} ;
51
73
52
- function GroupUsersPermission ( props : GroupPermissionProp ) {
53
- // const { Column } = TableStyled;
54
- const { group, orgId, groupUsers, currentUserGroupRole, currentUser, setModify, modify, loading } = props ;
74
+ const GroupUsersPermission : React . FC < GroupPermissionProp > = ( props ) => {
75
+ const {
76
+ group,
77
+ orgId,
78
+ groupUsers,
79
+ currentUserGroupRole,
80
+ currentUser,
81
+ setModify,
82
+ modify,
83
+ loading,
84
+ setElements
85
+ } = props ;
86
+ const [ searchValue , setSearchValue ] = useState ( "" )
87
+ const dispatch = useDispatch ( ) ;
88
+
55
89
const adminCount = groupUsers . filter ( ( user ) => isGroupAdmin ( user . role ) ) . length ;
56
90
const sortedGroupUsers = useMemo ( ( ) => {
57
91
return [ ...groupUsers ] . sort ( ( a , b ) => {
@@ -64,7 +98,31 @@ function GroupUsersPermission(props: GroupPermissionProp) {
64
98
}
65
99
} ) ;
66
100
} , [ groupUsers ] ) ;
67
- const dispatch = useDispatch ( ) ;
101
+
102
+ const debouncedFetchPotentialMembers = useCallback (
103
+ debounce ( ( searchVal : string ) => {
104
+ fetchGroupUsrPagination ( { groupId : group . groupId , search : searchVal } )
105
+ . then ( result => {
106
+ if ( result . success ) {
107
+ setElements ( {
108
+ elements : result . data || [ ] ,
109
+ total : result . total || 0 ,
110
+ role : result . visitorRole || ""
111
+ } ) ;
112
+ }
113
+ } )
114
+ } , 500 ) , [ dispatch ]
115
+ ) ;
116
+
117
+ useEffect ( ( ) => {
118
+ if ( searchValue . length > 2 || searchValue === "" ) {
119
+ debouncedFetchPotentialMembers ( searchValue ) ;
120
+ }
121
+ return ( ) => {
122
+ debouncedFetchPotentialMembers . cancel ( ) ;
123
+ } ;
124
+ } , [ searchValue , debouncedFetchPotentialMembers ] ) ;
125
+
68
126
return (
69
127
< >
70
128
< PermissionHeaderWrapper >
@@ -78,19 +136,31 @@ function GroupUsersPermission(props: GroupPermissionProp) {
78
136
) }
79
137
</ HeaderBack >
80
138
{ isGroupAdmin ( currentUserGroupRole ) && ! group . syncGroup && (
81
- < AddGroupUserDialog
82
- groupUsers = { groupUsers }
83
- orgId = { orgId }
84
- groupId = { group . groupId }
85
- setModify = { setModify }
86
- modify = { modify }
87
- trigger = {
88
- < AddMemberButton buttonType = "primary" icon = { < StyledAddIcon /> } >
89
- { trans ( "memberSettings.addMember" ) }
90
- </ AddMemberButton >
91
- }
92
- style = { { marginLeft : "auto" } }
93
- />
139
+ < OptionsHeader >
140
+ < Search
141
+ placeholder = { trans ( "memberSettings.searchMember" ) }
142
+ value = { searchValue }
143
+ onChange = { ( e ) => setSearchValue ( e . target . value ) }
144
+ style = { {
145
+ width : "20%" ,
146
+ minWidth : "160px" ,
147
+ height : "32px" ,
148
+ marginTop : 'auto'
149
+ } }
150
+ />
151
+ < AddGroupUserDialog
152
+ groupUsers = { groupUsers }
153
+ orgId = { orgId }
154
+ groupId = { group . groupId }
155
+ setModify = { setModify }
156
+ modify = { modify }
157
+ trigger = {
158
+ < AddMemberButton buttonType = "primary" icon = { < StyledAddIcon /> } >
159
+ { trans ( "memberSettings.addMember" ) }
160
+ </ AddMemberButton >
161
+ }
162
+ />
163
+ </ OptionsHeader >
94
164
) }
95
165
</ PermissionHeaderWrapper >
96
166
< TableStyled
0 commit comments