@@ -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 = {
190197type :ApplicationPermissionType ;
191198id :string ;
@@ -294,8 +301,10 @@ const PermissionSelector = (props: {
294301user :User ;
295302filterItems :PermissionItem [ ] ;
296303supportRoles :{ 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 ;
299308const [ roleSelectVisible , setRoleSelectVisible ] = useState ( false ) ;
300309const selectRef = useRef < HTMLDivElement > ( null ) ;
301310const [ optionViews , setOptionViews ] = useState < AddAppOptionView [ ] > ( )
@@ -305,42 +314,41 @@ const PermissionSelector = (props: {
305314
306315const debouncedUserSearch = useCallback (
307316debounce ( ( searchTerm :string ) => {
308- if ( ! application ) return ;
309-
310317setIsLoading ( 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 {
317338setIsLoading ( false ) ;
318- } ) ;
339+ }
319340} , 500 ) ,
320- [ application , props . filterItems ]
341+ [ application , props . filterItems , contextType , organizationId ]
321342) ;
322343
323344useEffect ( ( ) => {
324345debouncedUserSearch ( searchValue ) ;
325-
326346return ( ) => {
327347debouncedUserSearch . 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
345353useEffect ( ( ) => {
346354setRoleSelectVisible ( selectedItems . length > 0 ) ;
@@ -425,8 +433,8 @@ export const Permission = (props: {
425433supportRoles :{ label :string ; value :PermissionRole } [ ] ;
426434onCancel :( ) => void ;
427435addPermission :( userIds :string [ ] , groupIds :string [ ] , role :string ) => void ;
428- } ) => {
429- const { onCancel} = props ;
436+ } & PermissionContextProps ) => {
437+ const { onCancel, contextType = "application" , organizationId } = props ;
430438const user = useSelector ( getUser ) ;
431439const [ selectRole , setSelectRole ] = useState < ApplicationRoleType > ( "viewer" ) ;
432440const [ selectedItems , setSelectedItems ] = useState < PermissionAddEntity [ ] > ( [ ] ) ;
@@ -443,6 +451,8 @@ export const Permission = (props: {
443451user = { user }
444452filterItems = { props . filterItems }
445453supportRoles = { props . supportRoles }
454+ contextType = { contextType }
455+ organizationId = { organizationId }
446456/>
447457< BottomButton >
448458< TacoButton style = { { marginRight :"8px" } } onClick = { onCancel } >