@@ -27,7 +27,7 @@ import { EmptyContent } from "pages/common/styledComponent";
27
27
import { trans } from "i18n" ;
28
28
import { PermissionItem } from "./PermissionList" ;
29
29
import { currentApplication } from "@lowcoder-ee/redux/selectors/applicationSelector" ;
30
- import { fetchAvailableGroupsMembers } from "@lowcoder-ee/util/pagination/axios" ;
30
+ import { fetchAvailableGroupsMembers , fetchAvailableOrgGroupsMembers } from "@lowcoder-ee/util/pagination/axios" ;
31
31
32
32
const AddAppUserContent = styled . div `
33
33
display: flex;
@@ -186,6 +186,13 @@ const AddRoleSelect = styled(StyledRoleSelect)<{ $isVisible: boolean }>`
186
186
display: ${ ( props ) => ( props . $isVisible ? "unset" : "none" ) } ;
187
187
` ;
188
188
189
+ type PermissionContextType = "application" | "organization" ;
190
+
191
+ type PermissionContextProps = {
192
+ contextType : PermissionContextType ;
193
+ organizationId ?: string ;
194
+ } ;
195
+
189
196
type AddAppOptionView = {
190
197
type : ApplicationPermissionType ;
191
198
id : string ;
@@ -294,8 +301,10 @@ const PermissionSelector = (props: {
294
301
user : User ;
295
302
filterItems : PermissionItem [ ] ;
296
303
supportRoles : { label : string ; value : PermissionRole } [ ] ;
304
+ contextType : PermissionContextType ;
305
+ organizationId ?: string ;
297
306
} ) => {
298
- const { selectedItems, setSelectRole, setSelectedItems, user } = props ;
307
+ const { selectedItems, setSelectRole, setSelectedItems, user, contextType , organizationId } = props ;
299
308
const [ roleSelectVisible , setRoleSelectVisible ] = useState ( false ) ;
300
309
const selectRef = useRef < HTMLDivElement > ( null ) ;
301
310
const [ optionViews , setOptionViews ] = useState < AddAppOptionView [ ] > ( )
@@ -305,42 +314,41 @@ const PermissionSelector = (props: {
305
314
306
315
const debouncedUserSearch = useCallback (
307
316
debounce ( ( searchTerm : string ) => {
308
- if ( ! application ) return ;
309
-
310
317
setIsLoading ( true ) ;
311
- fetchAvailableGroupsMembers ( application . applicationId , searchTerm ) . then ( res => {
312
- if ( res . success ) {
313
- setOptionViews ( getPermissionOptionView ( res . data , props . filterItems ) )
314
- }
315
- setIsLoading ( false ) ;
316
- } ) . catch ( ( ) => {
318
+
319
+ if ( contextType === "application" && application ) {
320
+ fetchAvailableGroupsMembers ( application . applicationId , searchTerm ) . then ( res => {
321
+ if ( res . success ) {
322
+ setOptionViews ( getPermissionOptionView ( res . data , props . filterItems ) )
323
+ }
324
+ setIsLoading ( false ) ;
325
+ } ) . catch ( ( ) => {
326
+ setIsLoading ( false ) ;
327
+ } ) ;
328
+ } else if ( contextType === "organization" && organizationId ) {
329
+ fetchAvailableOrgGroupsMembers ( organizationId , searchTerm ) . then ( res => {
330
+ if ( res . success ) {
331
+ setOptionViews ( getPermissionOptionView ( res . data || [ ] , props . filterItems ) )
332
+ }
333
+ setIsLoading ( false ) ;
334
+ } ) . catch ( ( ) => {
335
+ setIsLoading ( false ) ;
336
+ } ) ;
337
+ } else {
317
338
setIsLoading ( false ) ;
318
- } ) ;
339
+ }
319
340
} , 500 ) ,
320
- [ application , props . filterItems ]
341
+ [ application , props . filterItems , contextType , organizationId ]
321
342
) ;
322
343
323
344
useEffect ( ( ) => {
324
345
debouncedUserSearch ( searchValue ) ;
325
-
326
346
return ( ) => {
327
347
debouncedUserSearch . cancel ( ) ;
328
348
} ;
329
349
} , [ searchValue , debouncedUserSearch ] ) ;
330
350
331
- useEffect ( ( ) => {
332
- if ( ! application ) return ;
333
-
334
- setIsLoading ( true ) ;
335
- fetchAvailableGroupsMembers ( application . applicationId , "" ) . then ( res => {
336
- if ( res . success ) {
337
- setOptionViews ( getPermissionOptionView ( res . data , props . filterItems ) )
338
- }
339
- setIsLoading ( false ) ;
340
- } ) . catch ( ( ) => {
341
- setIsLoading ( false ) ;
342
- } ) ;
343
- } , [ application , props . filterItems ] ) ;
351
+
344
352
345
353
useEffect ( ( ) => {
346
354
setRoleSelectVisible ( selectedItems . length > 0 ) ;
@@ -425,8 +433,8 @@ export const Permission = (props: {
425
433
supportRoles : { label : string ; value : PermissionRole } [ ] ;
426
434
onCancel : ( ) => void ;
427
435
addPermission : ( userIds : string [ ] , groupIds : string [ ] , role : string ) => void ;
428
- } ) => {
429
- const { onCancel } = props ;
436
+ } & PermissionContextProps ) => {
437
+ const { onCancel, contextType = "application" , organizationId } = props ;
430
438
const user = useSelector ( getUser ) ;
431
439
const [ selectRole , setSelectRole ] = useState < ApplicationRoleType > ( "viewer" ) ;
432
440
const [ selectedItems , setSelectedItems ] = useState < PermissionAddEntity [ ] > ( [ ] ) ;
@@ -443,6 +451,8 @@ export const Permission = (props: {
443
451
user = { user }
444
452
filterItems = { props . filterItems }
445
453
supportRoles = { props . supportRoles }
454
+ contextType = { contextType }
455
+ organizationId = { organizationId }
446
456
/>
447
457
< BottomButton >
448
458
< TacoButton style = { { marginRight : "8px" } } onClick = { onCancel } >
0 commit comments