Skip to content

Commit 2ec863a

Browse files
authored
Merge pull request #1684 from iamfaran/environments
Environments Refactor + New Plugin Updates
2 parents 6633573 + 3dfbee3 commit 2ec863a

15 files changed

+594
-371
lines changed

client/packages/lowcoder/src/pages/setting/environments/EnvironmentDetail.tsx

+15-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, {useState} from "react";
2-
import { useParams } from "react-router-dom";
32
import {
43
Spin,
54
Typography,
@@ -8,25 +7,18 @@ import {
87
Tabs,
98
Alert,
109
Descriptions,
11-
Dropdown,
1210
Menu,
1311
Button,
1412
Breadcrumb,
1513
} from "antd";
1614
import {
17-
ReloadOutlined,
1815
LinkOutlined,
19-
ClusterOutlined,
2016
TeamOutlined,
21-
UserOutlined,
22-
SyncOutlined,
2317
EditOutlined,
24-
EllipsisOutlined,
25-
MoreOutlined,
2618
HomeOutlined
2719
} from "@ant-design/icons";
2820

29-
import { useEnvironmentContext } from "./context/EnvironmentContext";
21+
import { useSingleEnvironmentContext } from "./context/SingleEnvironmentContext";
3022
import { workspaceConfig } from "./config/workspace.config";
3123
import { userGroupsConfig } from "./config/usergroups.config";
3224
import DeployableItemsTab from "./components/DeployableItemsTab";
@@ -37,21 +29,18 @@ import history from "@lowcoder-ee/util/history";
3729
const { Title, Text } = Typography;
3830
const { TabPane } = Tabs;
3931

40-
4132
/**
4233
* Environment Detail Page Component
4334
* Shows detailed information about a specific environment
4435
*/
4536
const EnvironmentDetail: React.FC = () => {
46-
// Get environment ID from URL params
37+
// Use the SingleEnvironmentContext instead of EnvironmentContext
4738
const {
4839
environment,
49-
isLoadingEnvironment,
40+
isLoading,
5041
error,
5142
updateEnvironmentData
52-
} = useEnvironmentContext();
53-
54-
43+
} = useSingleEnvironmentContext();
5544

5645
const [isEditModalVisible, setIsEditModalVisible] = useState(false);
5746
const [isUpdating, setIsUpdating] = useState(false);
@@ -67,11 +56,16 @@ const EnvironmentDetail: React.FC = () => {
6756
};
6857

6958
// Handle save environment
70-
const handleSaveEnvironment = async (environmentId: string, data: Partial<Environment>) => {
59+
const handleSaveEnvironment = async (data: Partial<Environment>) => {
60+
if (!environment) return;
61+
7162
setIsUpdating(true);
7263
try {
73-
await updateEnvironmentData(environmentId, data);
64+
// Close the modal first, before the update completes
7465
handleCloseModal();
66+
67+
// Then update the environment data
68+
await updateEnvironmentData(data);
7569
} catch (error) {
7670
console.error('Failed to update environment:', error);
7771
} finally {
@@ -89,7 +83,7 @@ const EnvironmentDetail: React.FC = () => {
8983
</Menu>
9084
);
9185

92-
if (isLoadingEnvironment) {
86+
if (isLoading) {
9387
return (
9488
<div style={{ display: 'flex', justifyContent: 'center', padding: '50px' }}>
9589
<Spin size="large" tip="Loading environment..." />
@@ -107,6 +101,7 @@ const EnvironmentDetail: React.FC = () => {
107101
/>
108102
);
109103
}
104+
110105
return (
111106
<div
112107
className="environment-detail-container"
@@ -124,7 +119,6 @@ const EnvironmentDetail: React.FC = () => {
124119
<Breadcrumb.Item>{environment.environmentName}</Breadcrumb.Item>
125120
</Breadcrumb>
126121

127-
{/* Header with environment name and controls */}
128122
{/* Header with environment name and controls */}
129123
<div
130124
className="environment-header"
@@ -231,6 +225,7 @@ const EnvironmentDetail: React.FC = () => {
231225
/>
232226
</TabPane>
233227
</Tabs>
228+
234229
{/* Edit Environment Modal */}
235230
{environment && (
236231
<EditEnvironmentModal
@@ -245,4 +240,4 @@ const EnvironmentDetail: React.FC = () => {
245240
);
246241
};
247242

248-
export default EnvironmentDetail;
243+
export default EnvironmentDetail;

client/packages/lowcoder/src/pages/setting/environments/Environments.tsx

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1+
// client/packages/lowcoder/src/pages/setting/environments/Environments.tsx
12
import React from "react";
2-
import { Switch, Route } from "react-router-dom";
3+
import { Switch, Route, useRouteMatch } from "react-router-dom";
34
import { EnvironmentProvider } from "./context/EnvironmentContext";
5+
import EnvironmentRoutes from "./routes/EnvironmentRoutes";
46
import EnvironmentsList from "./EnvironmentsList";
5-
import EnvironmentScopedRoutes from "./components/EnvironmentScopedRoutes";
6-
7-
import {
8-
ENVIRONMENT_SETTING,
9-
ENVIRONMENT_DETAIL
10-
} from "@lowcoder-ee/constants/routesURL";
117

128
/**
13-
* Top-level Environments component that wraps all environment-related routes
14-
* with the EnvironmentProvider for shared state management
9+
* Top-level Environments component
10+
* Provides the EnvironmentProvider at the top level
1511
*/
1612
const Environments: React.FC = () => {
13+
const { path } = useRouteMatch();
14+
1715
return (
1816
<EnvironmentProvider>
1917
<Switch>
20-
{/* Route that shows the list of environments */}
21-
<Route exact path={ENVIRONMENT_SETTING}>
18+
{/* Environment list route */}
19+
<Route exact path={path}>
2220
<EnvironmentsList />
2321
</Route>
24-
25-
{/* All other routes under /environments/:envId */}
26-
<Route path={ENVIRONMENT_DETAIL}>
27-
<EnvironmentScopedRoutes />
22+
23+
{/* All routes that need a specific environment */}
24+
<Route path={`${path}/:envId`}>
25+
<EnvironmentRoutes />
2826
</Route>
2927
</Switch>
3028
</EnvironmentProvider>

client/packages/lowcoder/src/pages/setting/environments/EnvironmentsList.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const EnvironmentsList: React.FC = () => {
1818
// Use the shared context instead of a local hook
1919
const {
2020
environments,
21-
isLoadingEnvironments,
21+
isLoading,
2222
error,
2323
} = useEnvironmentContext();
2424

@@ -83,7 +83,7 @@ const EnvironmentsList: React.FC = () => {
8383
)}
8484

8585
{/* Empty state handling */}
86-
{!isLoadingEnvironments && environments.length === 0 && !error ? (
86+
{!isLoading && environments.length === 0 && !error ? (
8787
<Empty
8888
description="No environments found"
8989
image={Empty.PRESENTED_IMAGE_SIMPLE}
@@ -92,7 +92,7 @@ const EnvironmentsList: React.FC = () => {
9292
/* Table component */
9393
<EnvironmentsTable
9494
environments={filteredEnvironments}
95-
loading={isLoadingEnvironments}
95+
loading={isLoading}
9696
onRowClick={handleRowClick}
9797
/>
9898
)}

0 commit comments

Comments
 (0)