@@ -181,6 +181,16 @@ function teamID(installation: SlackManagedInstallation): string {
181181 return installation . route . externalTenantId ;
182182}
183183
184+ function hasAllowedAction ( installation : SlackManagedInstallation , action : string ) : boolean {
185+ return ( installation . allowedActions || [ ] ) . some (
186+ ( candidate ) => candidate . trim ( ) . toLowerCase ( ) === action . trim ( ) . toLowerCase ( ) ,
187+ ) ;
188+ }
189+
190+ function installationIsDisconnected ( installation : SlackManagedInstallation ) : boolean {
191+ return installation . state . trim ( ) . toLowerCase ( ) === 'disconnected' ;
192+ }
193+
184194function WorkspaceListPage ( ) {
185195 const { value, error, loading, reload } = useAsyncValue (
186196 ( ) => slackGatewayRequest < InstallationListResponse > ( '/api/slack/workspaces' ) ,
@@ -218,6 +228,8 @@ function WorkspaceListPage() {
218228 < div className = "overflow-hidden rounded-[var(--radius-lg)] border border-border" >
219229 { installations . map ( ( installation ) => {
220230 const connection = primaryConnection ( installation ) ;
231+ const canDisconnect = hasAllowedAction ( installation , 'disconnect' ) ;
232+ const canTest = ! installationIsDisconnected ( installation ) ;
221233 return (
222234 < div
223235 key = { installation . id || teamID ( installation ) }
@@ -249,17 +261,21 @@ function WorkspaceListPage() {
249261 >
250262 Target
251263 </ Link >
252- < Link
253- to = { `/settings/slack/workspaces/test?teamId=${ encodeURIComponent ( teamID ( installation ) ) } ` }
254- className = { buttonVariants ( { variant : 'outline' } ) }
255- >
256- < SendIcon aria-hidden = "true" />
257- Test
258- </ Link >
259- < Button variant = "destructive" onClick = { ( ) => disconnect ( installation ) } >
260- < Trash2Icon aria-hidden = "true" />
261- Disconnect
262- </ Button >
264+ { canTest && (
265+ < Link
266+ to = { `/settings/slack/workspaces/test?teamId=${ encodeURIComponent ( teamID ( installation ) ) } ` }
267+ className = { buttonVariants ( { variant : 'outline' } ) }
268+ >
269+ < SendIcon aria-hidden = "true" />
270+ Test
271+ </ Link >
272+ ) }
273+ { canDisconnect && (
274+ < Button variant = "destructive" onClick = { ( ) => disconnect ( installation ) } >
275+ < Trash2Icon aria-hidden = "true" />
276+ Disconnect
277+ </ Button >
278+ ) }
263279 </ div >
264280 </ div >
265281 ) ;
@@ -368,6 +384,10 @@ function routeRequireMention(route: SlackManagedChannelRoute): boolean {
368384 return route . requireMention !== false ;
369385}
370386
387+ function routeEnabled ( route : SlackManagedChannelRoute ) : boolean {
388+ return route . enabled !== false ;
389+ }
390+
371391function ConnectionSettingsPage ( ) {
372392 const { installationId = '' , connectionId = '' } = useParams ( ) ;
373393 const loadPath = `/api/settings/channels/installations/${ encodeURIComponent (
@@ -385,7 +405,7 @@ function ConnectionSettingsPage() {
385405
386406 useEffect ( ( ) => {
387407 if ( value ?. connection ) {
388- setRoutes ( [ ...( value . connection . routes || [ ] ) ] ) ;
408+ setRoutes ( [ ...( value . connection . routes || [ ] ) ] . filter ( routeEnabled ) ) ;
389409 }
390410 } , [ value ?. connection ] ) ;
391411
0 commit comments