@@ -13,7 +13,8 @@ import {
13
13
Button ,
14
14
Statistic ,
15
15
Divider ,
16
- Breadcrumb
16
+ Breadcrumb ,
17
+ message
17
18
} from "antd" ;
18
19
import {
19
20
AppstoreOutlined ,
@@ -29,12 +30,16 @@ import { useEnvironmentContext } from "./context/EnvironmentContext";
29
30
import { useWorkspace } from "./hooks/useWorkspace" ;
30
31
import { useWorkspaceApps } from "./hooks/useWorkspaceApps" ;
31
32
import { useWorkspaceDataSources } from "./hooks/useWorkspaceDataSources" ;
32
-
33
+ import { useManagedApps } from "./hooks/enterprise/useManagedApps" ;
34
+ import { App } from "./types/app.types" ;
35
+ import { getMergedApps } from "./utils/getMergedApps" ;
36
+ import { connectManagedApp , unconnectManagedApp } from "./services/enterprise.service" ;
33
37
34
38
const { Title, Text } = Typography ;
35
39
const { TabPane } = Tabs ;
36
40
37
41
42
+
38
43
const WorkspaceDetail : React . FC = ( ) => {
39
44
40
45
// Get parameters from URL
@@ -72,8 +77,35 @@ const WorkspaceDetail: React.FC = () => {
72
77
dataSourceStats,
73
78
} = useWorkspaceDataSources ( environment , workspaceId ) ;
74
79
75
-
76
-
80
+ const { managedApps } = useManagedApps ( environmentId ) ;
81
+ const [ mergedApps , setMergedApps ] = useState < App [ ] > ( [ ] ) ;
82
+
83
+ useEffect ( ( ) => {
84
+ setMergedApps ( getMergedApps ( apps , managedApps ) ) ;
85
+ } , [ apps , managedApps ] ) ;
86
+
87
+
88
+
89
+
90
+ const handleToggleManagedApp = async ( app : App , checked : boolean ) => {
91
+ try {
92
+ if ( checked ) {
93
+ await connectManagedApp ( environmentId , app . name , app . applicationGid ! ) ;
94
+ } else {
95
+ await unconnectManagedApp ( app . applicationGid ! ) ;
96
+ }
97
+
98
+ setMergedApps ( ( currentApps ) =>
99
+ currentApps . map ( ( a ) =>
100
+ a . applicationId === app . applicationId ? { ...a , managed : checked } : a
101
+ )
102
+ ) ;
103
+
104
+ message . success ( `${ app . name } is now ${ checked ? "Managed" : "Unmanaged" } ` ) ;
105
+ } catch {
106
+ message . error ( `Failed to toggle ${ app . name } ` ) ;
107
+ }
108
+ } ;
77
109
if ( envLoading || workspaceLoading ) {
78
110
return (
79
111
< div style = { { display : 'flex' , justifyContent : 'center' , alignItems : 'center' , height : '100%' , padding : '50px' } } >
@@ -187,10 +219,11 @@ const WorkspaceDetail: React.FC = () => {
187
219
) }
188
220
189
221
{ /* Apps List */ }
190
- < AppsList
191
- apps = { apps }
222
+ < AppsList
223
+ apps = { mergedApps }
192
224
loading = { appsLoading }
193
225
error = { appsError }
226
+ onToggleManaged = { handleToggleManagedApp }
194
227
/>
195
228
</ Card >
196
229
</ TabPane >
0 commit comments