@@ -27,7 +27,7 @@ import { EmptyContent } from "pages/common/styledComponent";
2727import { trans } from "i18n" ;
2828import { PermissionItem } from "./PermissionList" ;
2929import { 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" ;
3131
3232const AddAppUserContent = styled . div `
3333 display: flex;
@@ -186,6 +186,13 @@ const AddRoleSelect = styled(StyledRoleSelect)<{ $isVisible: boolean }>`
186186 display: ${ ( props ) => ( props . $isVisible ? "unset" : "none" ) } ;
187187` ;
188188
189+ type PermissionContextType = "application" | "organization" ;
190+
191+ type PermissionContextProps = {
192+ contextType : PermissionContextType ;
193+ organizationId ?: string ;
194+ } ;
195+
189196type AddAppOptionView = {
190197 type : ApplicationPermissionType ;
191198 id : string ;
@@ -294,8 +301,10 @@ const PermissionSelector = (props: {
294301 user : User ;
295302 filterItems : PermissionItem [ ] ;
296303 supportRoles : { label : string ; value : PermissionRole } [ ] ;
304+ contextType : PermissionContextType ;
305+ organizationId ?: string ;
297306} ) => {
298- const { selectedItems, setSelectRole, setSelectedItems, user } = props ;
307+ const { selectedItems, setSelectRole, setSelectedItems, user, contextType , organizationId } = props ;
299308 const [ roleSelectVisible , setRoleSelectVisible ] = useState ( false ) ;
300309 const selectRef = useRef < HTMLDivElement > ( null ) ;
301310 const [ optionViews , setOptionViews ] = useState < AddAppOptionView [ ] > ( )
@@ -305,42 +314,41 @@ const PermissionSelector = (props: {
305314
306315 const debouncedUserSearch = useCallback (
307316 debounce ( ( searchTerm : string ) => {
308- if ( ! application ) return ;
309-
310317 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 {
317338 setIsLoading ( false ) ;
318- } ) ;
339+ }
319340 } , 500 ) ,
320- [ application , props . filterItems ]
341+ [ application , props . filterItems , contextType , organizationId ]
321342 ) ;
322343
323344 useEffect ( ( ) => {
324345 debouncedUserSearch ( searchValue ) ;
325-
326346 return ( ) => {
327347 debouncedUserSearch . cancel ( ) ;
328348 } ;
329349 } , [ searchValue , debouncedUserSearch ] ) ;
330350
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+
344352
345353 useEffect ( ( ) => {
346354 setRoleSelectVisible ( selectedItems . length > 0 ) ;
@@ -425,8 +433,8 @@ export const Permission = (props: {
425433 supportRoles : { label : string ; value : PermissionRole } [ ] ;
426434 onCancel : ( ) => void ;
427435 addPermission : ( userIds : string [ ] , groupIds : string [ ] , role : string ) => void ;
428- } ) => {
429- const { onCancel } = props ;
436+ } & PermissionContextProps ) => {
437+ const { onCancel, contextType = "application" , organizationId } = props ;
430438 const user = useSelector ( getUser ) ;
431439 const [ selectRole , setSelectRole ] = useState < ApplicationRoleType > ( "viewer" ) ;
432440 const [ selectedItems , setSelectedItems ] = useState < PermissionAddEntity [ ] > ( [ ] ) ;
@@ -443,6 +451,8 @@ export const Permission = (props: {
443451 user = { user }
444452 filterItems = { props . filterItems }
445453 supportRoles = { props . supportRoles }
454+ contextType = { contextType }
455+ organizationId = { organizationId }
446456 />
447457 < BottomButton >
448458 < TacoButton style = { { marginRight : "8px" } } onClick = { onCancel } >
0 commit comments