@@ -15,6 +15,7 @@ import {
1515} from '@openops/components/ui' ;
1616import {
1717 addConnectionBrackets ,
18+ Permission ,
1819 removeConnectionBrackets ,
1920} from '@openops/shared' ;
2021import { t } from 'i18next' ;
@@ -23,6 +24,7 @@ import type React from 'react';
2324import { memo , useCallback , useState } from 'react' ;
2425import { ControllerRenderProps , useFormContext } from 'react-hook-form' ;
2526
27+ import { useAuthorization } from '@/app/common/hooks/authorization-hooks' ;
2628import { AutoFormFieldWrapper } from '@/app/features/builder/block-properties/auto-form-field-wrapper' ;
2729import { DynamicFormValidationProvider } from '@/app/features/builder/dynamic-form-validation/dynamic-form-validation-context' ;
2830
@@ -50,6 +52,9 @@ const ConnectionSelect = memo((params: ConnectionSelectProps) => {
5052 string | null
5153 > ( null ) ;
5254
55+ const { checkAccess } = useAuthorization ( ) ;
56+ const canWriteConnection = checkAccess ( Permission . WRITE_APP_CONNECTION ) ;
57+
5358 const form = useFormContext ( ) ;
5459 const {
5560 data : connectionsPage ,
@@ -188,7 +193,7 @@ const ConnectionSelect = memo((params: ConnectionSelectProps) => {
188193
189194 { field . value && ! field . disabled && ! params . disabled && (
190195 < div className = "shrink-0 flex items-center gap-1" >
191- { selectConnectionOpen && (
196+ { selectConnectionOpen && canWriteConnection && (
192197 < Button
193198 type = "button"
194199 variant = "ghost"
@@ -229,30 +234,15 @@ const ConnectionSelect = memo((params: ConnectionSelectProps) => {
229234 ) }
230235 </ SelectTrigger >
231236 < SelectContent >
232- < SelectAction
233- onClick = { ( ) => {
237+ < ConnectionSelectContent
238+ canWriteConnection = { canWriteConnection }
239+ connections = { connectionsPage ?. data ?? [ ] }
240+ onCreateNew = { ( ) => {
234241 setReconnectConnectionId ( null ) ;
235242 setSelectConnectionOpen ( false ) ;
236243 setConnectionDialogOpen ( true ) ;
237244 } }
238- >
239- < span className = "flex items-center gap-1 text-primary w-full" >
240- < Plus size = { 16 } />
241- { t ( 'Create new connection' ) }
242- </ span >
243- </ SelectAction >
244-
245- { connectionsPage ?. data &&
246- connectionsPage . data . map ( ( connection ) => {
247- return (
248- < SelectItem
249- value = { addConnectionBrackets ( connection . name ) }
250- key = { connection . name }
251- >
252- { connection . name }
253- </ SelectItem >
254- ) ;
255- } ) }
245+ />
256246 </ SelectContent >
257247 </ Select >
258248 </ AutoFormFieldWrapper >
@@ -263,5 +253,47 @@ const ConnectionSelect = memo((params: ConnectionSelectProps) => {
263253 ) ;
264254} ) ;
265255
256+ type ConnectionSelectContentProps = {
257+ canWriteConnection : boolean ;
258+ connections : { name : string } [ ] ;
259+ onCreateNew : ( ) => void ;
260+ } ;
261+
262+ const ConnectionSelectContent = ( {
263+ canWriteConnection,
264+ connections,
265+ onCreateNew,
266+ } : ConnectionSelectContentProps ) => {
267+ if ( connections . length === 0 && ! canWriteConnection ) {
268+ return (
269+ < div className = "px-3 py-2 text-sm text-muted-foreground" >
270+ { t ( 'No available connections' ) }
271+ </ div >
272+ ) ;
273+ }
274+
275+ return (
276+ < >
277+ { canWriteConnection && (
278+ < SelectAction onClick = { onCreateNew } >
279+ < span className = "flex items-center gap-1 text-primary w-full" >
280+ < Plus size = { 16 } />
281+ { t ( 'Create new connection' ) }
282+ </ span >
283+ </ SelectAction >
284+ ) }
285+
286+ { connections . map ( ( connection ) => (
287+ < SelectItem
288+ value = { addConnectionBrackets ( connection . name ) }
289+ key = { connection . name }
290+ >
291+ { connection . name }
292+ </ SelectItem >
293+ ) ) }
294+ </ >
295+ ) ;
296+ } ;
297+
266298ConnectionSelect . displayName = 'ConnectionSelect' ;
267299export { ConnectionSelect } ;
0 commit comments