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

Commitabd6c36

Browse files
committed
use redux environments in environments UI
1 parent1656f73 commitabd6c36

File tree

6 files changed

+54
-45
lines changed

6 files changed

+54
-45
lines changed

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
11
// client/packages/lowcoder/src/pages/setting/environments/Environments.tsx
22
importReactfrom"react";
33
import{Switch,Route,useRouteMatch}from"react-router-dom";
4-
import{EnvironmentProvider}from"./context/EnvironmentContext";
54
importEnvironmentRoutesfrom"./routes/EnvironmentRoutes";
65
importEnvironmentsListfrom"./EnvironmentsList";
76

87
/**
98
* Top-level Environments component
10-
*Providesthe EnvironmentProviderat the top level
9+
*No longer needsthe EnvironmentProvidersince we use Redux
1110
*/
1211
constEnvironments:React.FC=()=>{
1312
const{ path}=useRouteMatch();
1413

1514
return(
16-
<EnvironmentProvider>
17-
<Switch>
18-
{/* Environment list route */}
19-
<Routeexactpath={path}>
20-
<EnvironmentsList/>
21-
</Route>
22-
23-
{/* All routes that need a specific environment */}
24-
<Routepath={`${path}/:envId`}>
25-
<EnvironmentRoutes/>
26-
</Route>
27-
</Switch>
28-
</EnvironmentProvider>
15+
<Switch>
16+
{/* Environment list route */}
17+
<Routeexactpath={path}>
18+
<EnvironmentsList/>
19+
</Route>
20+
21+
{/* All routes that need a specific environment */}
22+
<Routepath={`${path}/:envId`}>
23+
<EnvironmentRoutes/>
24+
</Route>
25+
</Switch>
2926
);
3027
};
3128

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
importReact,{useState}from"react";
1+
importReact,{useState,useEffect}from"react";
22
import{Typography,Alert,Input,Button,Space,Empty,Card,Spin,Row,Col,Tooltip,Badge}from"antd";
33
import{SearchOutlined,CloudServerOutlined,SyncOutlined,PlusOutlined}from"@ant-design/icons";
44
import{useHistory}from"react-router-dom";
5-
import{useEnvironmentContext}from"./context/EnvironmentContext";
5+
import{useSelector,useDispatch}from"react-redux";
6+
import{selectEnvironments,selectEnvironmentsLoading,selectEnvironmentsError}from"redux/selectors/enterpriseSelectors";
7+
import{fetchEnvironments}from"redux/reduxActions/enterpriseActions";
68
import{Environment}from"./types/environment.types";
79
importEnvironmentsTablefrom"./components/EnvironmentsTable";
810
importCreateEnvironmentModalfrom"./components/CreateEnvironmentModal";
@@ -17,23 +19,28 @@ const { Title, Text } = Typography;
1719
* Displays a table of environments
1820
*/
1921
constEnvironmentsList:React.FC=()=>{
20-
// Use the shared context instead of a local hook
21-
const{
22-
environments,
23-
isLoading,
24-
error,
25-
refreshEnvironments
26-
}=useEnvironmentContext();
22+
// Use Redux state instead of context
23+
constdispatch=useDispatch();
24+
constenvironments=useSelector(selectEnvironments);
25+
constisLoading=useSelector(selectEnvironmentsLoading);
26+
consterror=useSelector(selectEnvironmentsError);
2727

2828
// State for search input
2929
const[searchText,setSearchText]=useState("");
30-
const[isRefreshing,setIsRefreshing]=useState(false);
3130
const[isCreateModalVisible,setIsCreateModalVisible]=useState(false);
3231
const[isCreating,setIsCreating]=useState(false);
3332

3433
// Hook for navigation
3534
consthistory=useHistory();
3635

36+
// Load environments on component mount
37+
useEffect(()=>{
38+
// Only fetch if environments are not already loaded
39+
if(environments.length===0&&!isLoading){
40+
dispatch(fetchEnvironments());
41+
}
42+
},[dispatch,environments.length,isLoading]);
43+
3744
// Filter environments based on search text
3845
constfilteredEnvironments=environments.filter((env)=>{
3946
constsearchLower=searchText.toLowerCase();
@@ -62,18 +69,16 @@ const EnvironmentsList: React.FC = () => {
6269
};
6370

6471
// Handle refresh
65-
consthandleRefresh=async()=>{
66-
setIsRefreshing(true);
67-
awaitrefreshEnvironments();
68-
setIsRefreshing(false);
72+
consthandleRefresh=()=>{
73+
dispatch(fetchEnvironments());
6974
};
7075

7176
// Handle create environment
7277
consthandleCreateEnvironment=async(environmentData:Partial<Environment>)=>{
7378
setIsCreating(true);
7479
try{
7580
awaitcreateEnvironment(environmentData);
76-
awaitrefreshEnvironments();// Refresh the list after creation
81+
dispatch(fetchEnvironments());// Refresh the list after creation
7782
}catch(error){
7883
console.error("Failed to create environment:",error);
7984
throwerror;// Re-throw to let the modal handle the error display
@@ -153,7 +158,7 @@ const EnvironmentsList: React.FC = () => {
153158
Create Environment
154159
</Button>
155160
<Button
156-
icon={<SyncOutlinedspin={isRefreshing}/>}
161+
icon={<SyncOutlinedspin={isLoading}/>}
157162
onClick={handleRefresh}
158163
loading={isLoading}
159164
type="default"

‎client/packages/lowcoder/src/pages/setting/environments/components/DeployItemModal.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
importReact,{useState,useEffect}from'react';
33
import{Modal,Form,Select,Checkbox,Button,Spin,Input,Tag,Space,Alert}from'antd';
44
import{messageInstance}from'lowcoder-design/src/components/GlobalInstances';
5+
import{useSelector}from'react-redux';
6+
import{selectEnvironments,selectEnvironmentsLoading}from'redux/selectors/enterpriseSelectors';
57
import{Environment}from'../types/environment.types';
68
import{DeployableItemConfig}from'../types/deployable-item.types';
7-
import{useEnvironmentContext}from'../context/EnvironmentContext';
89
import{getEnvironmentTagColor,formatEnvironmentType}from'../utils/environmentUtils';
910
import{ExclamationCircleOutlined}from'@ant-design/icons';
1011
import{showFirstCredentialOverwriteConfirm,showSecondCredentialOverwriteConfirm}from'./credentialConfirmations';
@@ -27,7 +28,8 @@ function DeployItemModal({
2728
onSuccess
2829
}:DeployItemModalProps){
2930
const[form]=Form.useForm();
30-
const{ environments, isLoading}=useEnvironmentContext();
31+
constenvironments=useSelector(selectEnvironments);
32+
constisLoading=useSelector(selectEnvironmentsLoading);
3133
const[deploying,setDeploying]=useState(false);
3234
const[credentialConfirmationStep,setCredentialConfirmationStep]=useState(0);// 0: not started, 1: first confirmation, 2: confirmed
3335

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import React, {
99
}from"react";
1010
import{messageInstance}from"lowcoder-design/src/components/GlobalInstances";
1111
import{useParams}from"react-router-dom";
12+
import{useDispatch}from"react-redux";
13+
import{fetchEnvironments}from"redux/reduxActions/enterpriseActions";
1214
import{getEnvironmentById,updateEnvironment}from"../services/environments.service";
1315
import{Environment}from"../types/environment.types";
14-
import{useEnvironmentContext}from'./EnvironmentContext';
15-
16+
1617
interfaceSingleEnvironmentContextState{
1718
// Environment data
1819
environment:Environment|null;
@@ -53,8 +54,8 @@ import React, {
5354
const{ envId}=useParams<{envId:string}>();
5455
constenvironmentId=propEnvironmentId||envId;
5556

56-
//Access the environments contextto refreshthe list
57-
const{ refreshEnvironments}=useEnvironmentContext();
57+
//Use Redux dispatchto refreshenvironments instead of context
58+
constdispatch=useDispatch();
5859

5960
// State for environment data
6061
const[environment,setEnvironment]=useState<Environment|null>(null);
@@ -103,18 +104,16 @@ import React, {
103104
messageInstance.success("Environment updated successfully");
104105

105106
// Refresh both the single environment and environments list
106-
awaitPromise.all([
107-
fetchEnvironment(),// Refresh the current environment
108-
refreshEnvironments()// Refresh the environments list
109-
]);
107+
awaitfetchEnvironment();// Refresh the current environment
108+
dispatch(fetchEnvironments());// Refresh the environments list using Redux
110109

111110
returnupdatedEnv;
112111
}catch(err){
113112
consterrorMessage=errinstanceofError ?err.message :"Failed to update environment";
114113
messageInstance.error(errorMessage);
115114
throwerr;
116115
}
117-
},[environment,environmentId,fetchEnvironment,refreshEnvironments]);
116+
},[environment,environmentId,fetchEnvironment,dispatch]);
118117

119118
// Load environment data when the component mounts or environmentId changes
120119
useEffect(()=>{

‎client/packages/lowcoder/src/redux/sagas/enterpriseSagas.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { call, put, takeLatest } from 'redux-saga/effects';
22
import{ReduxAction,ReduxActionTypes}from"constants/reduxActionConstants";
33
import{setEnterpriseLicense,fetchEnvironmentsSuccess,fetchEnvironmentsFailure}from"redux/reduxActions/enterpriseActions";
44
import{BrandingSettingResponse,EnterpriseLicenseResponse,FetchBrandingSettingPayload,getBranding,getEnterpriseLicense}from"api/enterpriseApi";
5-
import{getEnvironments}from"pages/setting/environments/services/environments.service";
5+
import{getEnvironmentsWithLicenseStatus}from"pages/setting/environments/services/environments.service";
66
import{Environment}from"pages/setting/environments/types/environment.types";
77

88
import{AxiosResponse}from'axios';
@@ -19,7 +19,7 @@ function* fetchEnterpriseLicenseSaga(): Generator<any, void, EnterpriseLicenseRe
1919

2020
function*fetchEnvironmentsSaga():Generator<any,void,Environment[]>{
2121
try{
22-
constenvironments:Environment[]=yieldcall(getEnvironments);
22+
constenvironments:Environment[]=yieldcall(getEnvironmentsWithLicenseStatus);
2323
yieldput(fetchEnvironmentsSuccess(environments));
2424
}catch(error){
2525
console.error('Failed to fetch environments:',error);

‎client/packages/lowcoder/src/redux/selectors/enterpriseSelectors.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@ export const getWorkspaceBrandingSetting = (state: AppState) => {
2828
}
2929
// Environment selectors
3030
exportconstselectEnvironments=(state:AppState)=>
31-
state.ui.enterprise?.environments??[];
31+
state.ui.enterprise?.environments??[];
32+
33+
exportconstselectEnvironmentsLoading=(state:AppState)=>
34+
state.ui.enterprise?.environmentsLoading??false;
35+
36+
exportconstselectEnvironmentsError=(state:AppState)=>
37+
state.ui.enterprise?.environmentsError??null;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp