1
- import React , { useEffect , useState } from "react" ;
2
- import { useParams , useHistory } from "react-router-dom" ;
1
+ import React , { useState } from "react" ;
3
2
import history from "@lowcoder-ee/util/history" ;
4
3
import {
5
4
Spin ,
6
5
Typography ,
7
6
Card ,
8
- Row ,
9
- Col ,
10
7
Tabs ,
11
- Alert ,
12
8
Button ,
13
9
Breadcrumb ,
14
10
Space ,
@@ -26,101 +22,77 @@ import {
26
22
ArrowLeftOutlined ,
27
23
CloudUploadOutlined
28
24
} from "@ant-design/icons" ;
29
- import { useEnvironmentContext } from "./context/EnvironmentContext" ;
25
+
26
+ // Use the context hooks
27
+ import { useSingleEnvironmentContext } from "./context/SingleEnvironmentContext" ;
28
+ import { useWorkspaceContext } from "./context/WorkspaceContext" ;
29
+ import { useDeployModal } from "./context/DeployModalContext" ;
30
+
30
31
import DeployableItemsTab from "./components/DeployableItemsTab" ;
32
+ import { workspaceConfig } from "./config/workspace.config" ;
31
33
import { appsConfig } from "./config/apps.config" ;
32
34
import { dataSourcesConfig } from "./config/data-sources.config" ;
33
35
import { queryConfig } from "./config/query.config" ;
34
- import { useDeployableItems } from "./hooks/useDeployableItems" ;
35
- import { workspaceConfig } from "./config/workspace.config" ;
36
- import { useDeployModal } from "./context/DeployModalContext" ;
37
- import { useSingleEnvironmentContext } from "./context/SingleEnvironmentContext" ;
36
+
38
37
const { Title, Text } = Typography ;
39
38
const { TabPane } = Tabs ;
40
39
41
-
42
-
43
40
const WorkspaceDetail : React . FC = ( ) => {
41
+ // Use the context hooks
42
+ const { environment } = useSingleEnvironmentContext ( ) ;
43
+ const { workspace, isLoading, error, toggleManagedStatus } = useWorkspaceContext ( ) ;
44
+ const { openDeployModal } = useDeployModal ( ) ;
44
45
45
- // Get parameters from URL
46
- const { environmentId, workspaceId } = useParams < {
47
- workspaceId : string ;
48
- environmentId : string ;
49
- } > ( ) ;
50
- const {
51
- environment,
52
- isLoading : envLoading ,
53
- error : envError ,
54
- } = useSingleEnvironmentContext ( ) ;
55
-
56
- const { openDeployModal} = useDeployModal ( ) ;
57
-
58
- // Use our generic hook with the workspace config
59
- const {
60
- items : workspaces ,
61
- stats : workspaceStats ,
62
- loading : workspaceLoading ,
63
- error : workspaceError ,
64
- toggleManagedStatus,
65
- refreshItems
66
- } = useDeployableItems (
67
- workspaceConfig ,
68
- environment ,
69
- { workspaceId } // Additional params if needed
70
- ) ;
71
-
72
- // Find the current workspace in the items array
73
- const workspace = workspaces . find ( w => w . id === workspaceId ) ;
46
+ const [ isToggling , setIsToggling ] = useState ( false ) ;
74
47
48
+ // Handle toggle managed status
75
49
const handleToggleManaged = async ( checked : boolean ) => {
76
50
if ( ! workspace ) return ;
77
51
78
- const success = await toggleManagedStatus ( workspace , checked ) ;
79
- if ( success ) {
80
- message . success ( `Workspace is now ${ checked ? 'Managed' : 'Unmanaged' } ` ) ;
81
- } else {
82
- message . error ( 'Failed to change managed status' ) ;
52
+ setIsToggling ( true ) ;
53
+ try {
54
+ const success = await toggleManagedStatus ( checked ) ;
55
+ if ( success ) {
56
+ message . success ( `Workspace is now ${ checked ? 'Managed' : 'Unmanaged' } ` ) ;
57
+ } else {
58
+ message . error ( 'Failed to change managed status' ) ;
59
+ }
60
+ } finally {
61
+ setIsToggling ( false ) ;
83
62
}
84
63
} ;
85
64
86
- if ( envLoading || workspaceLoading ) {
87
- return (
88
- < div style = { { display : 'flex' , justifyContent : 'center' , alignItems : 'center' , height : '100%' , padding : '50px' } } >
89
- < Spin size = "large" tip = "Loading workspace details..." />
90
- </ div >
91
- ) ;
92
- }
65
+ if ( isLoading ) {
66
+ return (
67
+ < div style = { { display : 'flex' , justifyContent : 'center' , alignItems : 'center' , height : '100%' , padding : '50px' } } >
68
+ < Spin size = "large" tip = "Loading workspace details..." />
69
+ </ div >
70
+ ) ;
71
+ }
93
72
94
- if ( ! environment || ! workspace ) {
95
- return (
96
- < div style = { { display : 'flex' , justifyContent : 'center' , alignItems : 'center' , height : '100%' , padding : '50px' } } >
97
- < Typography . Title level = { 3 } > Workspace not found</ Typography . Title >
98
- </ div >
99
- )
100
- }
73
+ if ( error || ! environment || ! workspace ) {
74
+ return (
75
+ < div style = { { display : 'flex' , justifyContent : 'center' , alignItems : 'center' , height : '100%' , padding : '50px' } } >
76
+ < Typography . Title level = { 3 } >
77
+ { error || "Workspace not found" }
78
+ </ Typography . Title >
79
+ </ div >
80
+ ) ;
81
+ }
101
82
102
-
103
83
return (
104
- < div
105
- className = "workspace-detail-container"
106
- style = { { padding : "24px" , flex : 1 } }
107
- >
84
+ < div className = "workspace-detail-container" style = { { padding : "24px" , flex : 1 } } >
108
85
{ /* Breadcrumb navigation */ }
109
86
< Breadcrumb style = { { marginBottom : "16px" } } >
110
87
< Breadcrumb . Item >
111
- < span
112
- style = { { cursor : "pointer" } }
113
- onClick = { ( ) => history . push ( "/setting/environments" ) }
114
- >
88
+ < span style = { { cursor : "pointer" } } onClick = { ( ) => history . push ( "/setting/environments" ) } >
115
89
< HomeOutlined /> Environments
116
90
</ span >
117
91
</ Breadcrumb . Item >
118
92
< Breadcrumb . Item >
119
93
< span
120
94
style = { { cursor : "pointer" } }
121
- onClick = { ( ) =>
122
- history . push ( `/setting/environments/${ environmentId } ` )
123
- }
95
+ onClick = { ( ) => history . push ( `/setting/environments/${ environment . environmentId } ` ) }
124
96
>
125
97
< TeamOutlined /> { environment . environmentName }
126
98
</ span >
@@ -129,29 +101,14 @@ const WorkspaceDetail: React.FC = () => {
129
101
</ Breadcrumb >
130
102
131
103
{ /* Workspace header with details and actions */ }
132
- < Card
133
- style = { { marginBottom : "24px" } }
134
- bodyStyle = { { padding : "16px 24px" } }
135
- >
136
- < div
137
- style = { {
138
- display : "flex" ,
139
- justifyContent : "space-between" ,
140
- alignItems : "center" ,
141
- } }
142
- >
104
+ < Card style = { { marginBottom : "24px" } } bodyStyle = { { padding : "16px 24px" } } >
105
+ < div style = { { display : "flex" , justifyContent : "space-between" , alignItems : "center" } } >
143
106
{ /* Left section - Workspace info */ }
144
107
< div >
145
108
< Title level = { 3 } style = { { margin : 0 } } >
146
109
{ workspace . name }
147
110
</ Title >
148
- < div
149
- style = { {
150
- display : "flex" ,
151
- alignItems : "center" ,
152
- marginTop : "8px" ,
153
- } }
154
- >
111
+ < div style = { { display : "flex" , alignItems : "center" , marginTop : "8px" } } >
155
112
< Text type = "secondary" style = { { marginRight : "16px" } } >
156
113
ID: { workspace . id }
157
114
</ Text >
@@ -166,8 +123,9 @@ const WorkspaceDetail: React.FC = () => {
166
123
< div style = { { display : "flex" , alignItems : "center" } } >
167
124
< Text style = { { marginRight : "8px" } } > Managed:</ Text >
168
125
< Switch
169
- checked = { workspace . managed }
126
+ checked = { ! ! workspace . managed }
170
127
onChange = { handleToggleManaged }
128
+ loading = { isToggling }
171
129
checkedChildren = "Yes"
172
130
unCheckedChildren = "No"
173
131
/>
@@ -192,9 +150,7 @@ const WorkspaceDetail: React.FC = () => {
192
150
</ Tooltip >
193
151
< Button
194
152
icon = { < ArrowLeftOutlined /> }
195
- onClick = { ( ) =>
196
- history . push ( `/setting/environments/${ environmentId } ` )
197
- }
153
+ onClick = { ( ) => history . push ( `/setting/environments/${ environment . environmentId } ` ) }
198
154
>
199
155
Back
200
156
</ Button >
@@ -204,58 +160,35 @@ const WorkspaceDetail: React.FC = () => {
204
160
205
161
{ /* Tabs for Apps, Data Sources, and Queries */ }
206
162
< Tabs defaultActiveKey = "apps" >
207
- < TabPane
208
- tab = {
209
- < span >
210
- < AppstoreOutlined /> Apps
211
- </ span >
212
- }
213
- key = "apps"
214
- >
163
+ < TabPane tab = { < span > < AppstoreOutlined /> Apps</ span > } key = "apps" >
215
164
< DeployableItemsTab
216
165
environment = { environment }
217
166
config = { appsConfig }
218
- additionalParams = { { workspaceId } }
167
+ additionalParams = { { workspaceId : workspace . id } }
219
168
title = "Apps in this Workspace"
220
169
/>
221
170
</ TabPane >
222
171
223
- { /* Update the TabPane in WorkspaceDetail.tsx */ }
224
- < TabPane
225
- tab = {
226
- < span >
227
- < DatabaseOutlined /> Data Sources
228
- </ span >
229
- }
230
- key = "dataSources"
231
- >
172
+ < TabPane tab = { < span > < DatabaseOutlined /> Data Sources</ span > } key = "dataSources" >
232
173
< DeployableItemsTab
233
174
environment = { environment }
234
175
config = { dataSourcesConfig }
235
- additionalParams = { { workspaceId } }
176
+ additionalParams = { { workspaceId : workspace . id } }
236
177
title = "Data Sources in this Workspace"
237
178
/>
238
179
</ TabPane >
239
180
240
- < TabPane
241
- tab = {
242
- < span >
243
- < CodeOutlined /> Queries
244
- </ span >
245
- }
246
- key = "queries"
247
- >
181
+ < TabPane tab = { < span > < CodeOutlined /> Queries</ span > } key = "queries" >
248
182
< DeployableItemsTab
249
183
environment = { environment }
250
184
config = { queryConfig }
251
- additionalParams = { { workspaceId } }
185
+ additionalParams = { { workspaceId : workspace . id } }
252
186
title = "Queries in this Workspace"
253
187
/>
254
188
</ TabPane >
255
189
</ Tabs >
256
190
</ div >
257
191
) ;
258
- }
259
-
192
+ } ;
260
193
261
- export default WorkspaceDetail
194
+ export default WorkspaceDetail ;
0 commit comments