Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6750980

Browse files
committed
add managed workspace in the workspace context
1 parent7440ba3 commit6750980

File tree

2 files changed

+114
-128
lines changed

2 files changed

+114
-128
lines changed
Lines changed: 58 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
importReact,{useEffect,useState}from"react";
2-
import{useParams,useHistory}from"react-router-dom";
1+
importReact,{useState}from"react";
32
importhistoryfrom"@lowcoder-ee/util/history";
43
import{
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+
3031
importDeployableItemsTabfrom"./components/DeployableItemsTab";
32+
import{workspaceConfig}from"./config/workspace.config";
3133
import{appsConfig}from"./config/apps.config";
3234
import{dataSourcesConfig}from"./config/data-sources.config";
3335
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+
3837
const{ Title, Text}=Typography;
3938
const{ TabPane}=Tabs;
4039

41-
42-
4340
constWorkspaceDetail: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-
constworkspace=workspaces.find(w=>w.id===workspaceId);
46+
const[isToggling,setIsToggling]=useState(false);
7447

48+
// Handle toggle managed status
7549
consthandleToggleManaged=async(checked:boolean)=>{
7650
if(!workspace)return;
7751

78-
constsuccess=awaittoggleManagedStatus(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+
constsuccess=awaittoggleManagedStatus(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-
<divstyle={{display:'flex',justifyContent:'center',alignItems:'center',height:'100%',padding:'50px'}}>
89-
<Spinsize="large"tip="Loading workspace details..."/>
90-
</div>
91-
);
92-
}
65+
if(isLoading){
66+
return(
67+
<divstyle={{display:'flex',justifyContent:'center',alignItems:'center',height:'100%',padding:'50px'}}>
68+
<Spinsize="large"tip="Loading workspace details..."/>
69+
</div>
70+
);
71+
}
9372

94-
if(!environment||!workspace){
95-
return(
96-
<divstyle={{display:'flex',justifyContent:'center',alignItems:'center',height:'100%',padding:'50px'}}>
97-
<Typography.Titlelevel={3}>Workspace not found</Typography.Title>
98-
</div>
99-
)
100-
}
73+
if(error||!environment||!workspace){
74+
return(
75+
<divstyle={{display:'flex',justifyContent:'center',alignItems:'center',height:'100%',padding:'50px'}}>
76+
<Typography.Titlelevel={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+
<divclassName="workspace-detail-container"style={{padding:"24px",flex:1}}>
10885
{/* Breadcrumb navigation */}
10986
<Breadcrumbstyle={{marginBottom:"16px"}}>
11087
<Breadcrumb.Item>
111-
<span
112-
style={{cursor:"pointer"}}
113-
onClick={()=>history.push("/setting/environments")}
114-
>
88+
<spanstyle={{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+
<Cardstyle={{marginBottom:"24px"}}bodyStyle={{padding:"16px 24px"}}>
105+
<divstyle={{display:"flex",justifyContent:"space-between",alignItems:"center"}}>
143106
{/* Left section - Workspace info */}
144107
<div>
145108
<Titlelevel={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+
<divstyle={{display:"flex",alignItems:"center",marginTop:"8px"}}>
155112
<Texttype="secondary"style={{marginRight:"16px"}}>
156113
ID:{workspace.id}
157114
</Text>
@@ -166,8 +123,9 @@ const WorkspaceDetail: React.FC = () => {
166123
<divstyle={{display:"flex",alignItems:"center"}}>
167124
<Textstyle={{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
<TabsdefaultActiveKey="apps">
207-
<TabPane
208-
tab={
209-
<span>
210-
<AppstoreOutlined/> Apps
211-
</span>
212-
}
213-
key="apps"
214-
>
163+
<TabPanetab={<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+
<TabPanetab={<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+
<TabPanetab={<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-
exportdefaultWorkspaceDetail
194+
exportdefaultWorkspaceDetail;

‎client/packages/lowcoder/src/pages/setting/environments/context/WorkspaceContext.tsx‎

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import React, {
1010
import{message}from"antd";
1111
import{useParams}from"react-router-dom";
1212
import{useSingleEnvironmentContext}from"./SingleEnvironmentContext";
13-
import{fetchWorkspaceById}from"../services/environments.service";
13+
import{fetchWorkspaceById}from"../services/environments.service";
1414
import{Workspace}from"../types/workspace.types";
15+
import{getManagedWorkspaces,connectManagedWorkspace,unconnectManagedWorkspace}from"../services/enterprise.service";
1516

1617
interfaceWorkspaceContextState{
1718
// Workspace data
@@ -25,6 +26,7 @@ import React, {
2526

2627
// Functions
2728
refreshWorkspace:()=>Promise<void>;
29+
toggleManagedStatus:(checked:boolean)=>Promise<boolean>;
2830
}
2931

3032
constWorkspaceContext=createContext<WorkspaceContextState|undefined>(undefined);
@@ -71,8 +73,29 @@ import React, {
7173
setError(null);
7274

7375
try{
74-
constdata=awaitfetchWorkspaceById(environment.environmentId,workspaceId,environment.environmentApikey,environment.environmentApiServiceUrl!);
75-
setWorkspace(data);
76+
// Fetch the workspace data
77+
constworkspaceData=awaitfetchWorkspaceById(
78+
environment.environmentId,
79+
workspaceId,
80+
environment.environmentApikey,
81+
environment.environmentApiServiceUrl!
82+
);
83+
84+
if(!workspaceData){
85+
thrownewError("Workspace not found");
86+
}
87+
88+
// Fetch managed workspaces to check if this one is managed
89+
constmanagedWorkspaces=awaitgetManagedWorkspaces(environment.environmentId);
90+
91+
// Set the managed status
92+
constisManaged=managedWorkspaces.some(org=>org.orgGid===workspaceData.gid);
93+
94+
// Update the workspace with managed status
95+
setWorkspace({
96+
...workspaceData,
97+
managed:isManaged
98+
});
7699
}catch(err){
77100
consterrorMessage=errinstanceofError ?err.message :"Workspace not found or failed to load";
78101
setError(errorMessage);
@@ -81,6 +104,35 @@ import React, {
81104
}
82105
},[workspaceId,environment]);
83106

107+
// Function to toggle managed status
108+
consttoggleManagedStatus=useCallback(async(checked:boolean):Promise<boolean>=>{
109+
if(!workspace||!environment){
110+
returnfalse;
111+
}
112+
113+
try{
114+
if(checked){
115+
// Connect the workspace as managed
116+
awaitconnectManagedWorkspace(
117+
environment.environmentId,
118+
workspace.name,
119+
workspace.gid!
120+
);
121+
}else{
122+
// Disconnect the managed workspace
123+
awaitunconnectManagedWorkspace(workspace.gid!);
124+
}
125+
126+
// Update local state
127+
setWorkspace(prev=>prev ?{ ...prev,managed:checked} :null);
128+
129+
returntrue;
130+
}catch(err){
131+
consterrorMessage=errinstanceofError ?err.message :"Failed to update managed status";
132+
message.error(errorMessage);
133+
returnfalse;
134+
}
135+
},[workspace,environment]);
84136

85137
// Load workspace data when the component mounts or dependencies change
86138
useEffect(()=>{
@@ -93,6 +145,7 @@ import React, {
93145
isLoading,
94146
error,
95147
refreshWorkspace:fetchWorkspace,
148+
toggleManagedStatus
96149
};
97150

98151
return(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp