1- import React , { useEffect , useState } from "react" ;
2- import { useParams , useHistory } from "react-router-dom" ;
1+ import React , { useState } from "react" ;
32import history from "@lowcoder-ee/util/history" ;
43import {
54 Spin ,
65 Typography ,
76 Card ,
8- Row ,
9- Col ,
107 Tabs ,
11- Alert ,
128 Button ,
139 Breadcrumb ,
1410 Space ,
@@ -26,101 +22,77 @@ import {
2622 ArrowLeftOutlined ,
2723 CloudUploadOutlined
2824} 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+
3031import DeployableItemsTab from "./components/DeployableItemsTab" ;
32+ import { workspaceConfig } from "./config/workspace.config" ;
3133import { appsConfig } from "./config/apps.config" ;
3234import { dataSourcesConfig } from "./config/data-sources.config" ;
3335import { 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+
3837const { Title, Text } = Typography ;
3938const { TabPane } = Tabs ;
4039
41-
42-
4340const WorkspaceDetail : React . FC = ( ) => {
41+ // Use the context hooks
42+ const { environment } = useSingleEnvironmentContext ( ) ;
43+ const { workspace, isLoading, error, toggleManagedStatus } = useWorkspaceContext ( ) ;
44+ const { openDeployModal } = useDeployModal ( ) ;
4445
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 ) ;
7447
48+ // Handle toggle managed status
7549 const handleToggleManaged = async ( checked : boolean ) => {
7650 if ( ! workspace ) return ;
7751
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 ) ;
8362 }
8463 } ;
8564
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+ }
9372
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+ }
10182
102-
10383 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 } } >
10885 { /* Breadcrumb navigation */ }
10986 < Breadcrumb style = { { marginBottom : "16px" } } >
11087 < 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" ) } >
11589 < HomeOutlined /> Environments
11690 </ span >
11791 </ Breadcrumb . Item >
11892 < Breadcrumb . Item >
11993 < span
12094 style = { { cursor : "pointer" } }
121- onClick = { ( ) =>
122- history . push ( `/setting/environments/${ environmentId } ` )
123- }
95+ onClick = { ( ) => history . push ( `/setting/environments/${ environment . environmentId } ` ) }
12496 >
12597 < TeamOutlined /> { environment . environmentName }
12698 </ span >
@@ -129,29 +101,14 @@ const WorkspaceDetail: React.FC = () => {
129101 </ Breadcrumb >
130102
131103 { /* 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" } } >
143106 { /* Left section - Workspace info */ }
144107 < div >
145108 < Title level = { 3 } style = { { margin : 0 } } >
146109 { workspace . name }
147110 </ 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" } } >
155112 < Text type = "secondary" style = { { marginRight : "16px" } } >
156113 ID: { workspace . id }
157114 </ Text >
@@ -166,8 +123,9 @@ const WorkspaceDetail: React.FC = () => {
166123 < div style = { { display : "flex" , alignItems : "center" } } >
167124 < Text style = { { marginRight : "8px" } } > Managed:</ Text >
168125 < Switch
169- checked = { workspace . managed }
126+ checked = { ! ! workspace . managed }
170127 onChange = { handleToggleManaged }
128+ loading = { isToggling }
171129 checkedChildren = "Yes"
172130 unCheckedChildren = "No"
173131 />
@@ -192,9 +150,7 @@ const WorkspaceDetail: React.FC = () => {
192150 </ Tooltip >
193151 < Button
194152 icon = { < ArrowLeftOutlined /> }
195- onClick = { ( ) =>
196- history . push ( `/setting/environments/${ environmentId } ` )
197- }
153+ onClick = { ( ) => history . push ( `/setting/environments/${ environment . environmentId } ` ) }
198154 >
199155 Back
200156 </ Button >
@@ -204,58 +160,35 @@ const WorkspaceDetail: React.FC = () => {
204160
205161 { /* Tabs for Apps, Data Sources, and Queries */ }
206162 < 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" >
215164 < DeployableItemsTab
216165 environment = { environment }
217166 config = { appsConfig }
218- additionalParams = { { workspaceId } }
167+ additionalParams = { { workspaceId : workspace . id } }
219168 title = "Apps in this Workspace"
220169 />
221170 </ TabPane >
222171
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" >
232173 < DeployableItemsTab
233174 environment = { environment }
234175 config = { dataSourcesConfig }
235- additionalParams = { { workspaceId } }
176+ additionalParams = { { workspaceId : workspace . id } }
236177 title = "Data Sources in this Workspace"
237178 />
238179 </ TabPane >
239180
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" >
248182 < DeployableItemsTab
249183 environment = { environment }
250184 config = { queryConfig }
251- additionalParams = { { workspaceId } }
185+ additionalParams = { { workspaceId : workspace . id } }
252186 title = "Queries in this Workspace"
253187 />
254188 </ TabPane >
255189 </ Tabs >
256190 </ div >
257191 ) ;
258- }
259-
192+ } ;
260193
261- export default WorkspaceDetail
194+ export default WorkspaceDetail ;
0 commit comments