Skip to content

Commit 056abbf

Browse files
committed
add reducers for environments
1 parent 416d117 commit 056abbf

File tree

1 file changed

+262
-6
lines changed

1 file changed

+262
-6
lines changed

client/packages/lowcoder/src/redux/reducers/uiReducers/enterpriseReducer.ts

Lines changed: 262 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,52 @@
1-
import { BrandingConfig, BrandingSettingResponse, EnterpriseLicenseResponse } from "@lowcoder-ee/api/enterpriseApi";
1+
import {
2+
BrandingConfig,
3+
BrandingSettingResponse,
4+
EnterpriseLicenseResponse,
5+
Environment,
6+
} from "@lowcoder-ee/api/enterpriseApi";
27
import { createReducer } from "@lowcoder-ee/util/reducerUtils";
38
import { ReduxAction, ReduxActionTypes } from "constants/reduxActionConstants";
49

510
export interface EnterpriseReduxState {
6-
enterprise: EnterpriseLicenseResponse,
7-
globalBranding?: BrandingConfig,
8-
workspaceBranding?: BrandingConfig,
11+
enterprise: EnterpriseLicenseResponse;
12+
globalBranding?: BrandingConfig;
13+
workspaceBranding?: BrandingConfig;
914
}
10-
15+
16+
export interface EnvironmentsState {
17+
list: Environment[];
18+
currentEnvironment: Environment | null;
19+
loading: boolean;
20+
error: any | null;
21+
creating: boolean;
22+
updating: boolean;
23+
deleting: boolean;
24+
updatingApiKey: boolean;
25+
}
26+
export interface EnterpriseReduxState {
27+
enterprise: EnterpriseLicenseResponse;
28+
globalBranding?: BrandingConfig;
29+
workspaceBranding?: BrandingConfig;
30+
environments: EnvironmentsState;
31+
}
32+
1133
const initialState: EnterpriseReduxState = {
1234
enterprise: {
1335
eeActive: false,
1436
remainingAPICalls: 0,
1537
eeLicenses: [],
16-
}
38+
},
39+
// Add environments initial state
40+
environments: {
41+
list: [],
42+
currentEnvironment: null,
43+
loading: false,
44+
error: null,
45+
creating: false,
46+
updating: false,
47+
deleting: false,
48+
updatingApiKey: false,
49+
},
1750
};
1851

1952
const enterpriseReducer = createReducer(initialState, {
@@ -38,6 +71,229 @@ const enterpriseReducer = createReducer(initialState, {
3871
...state,
3972
workspaceBranding: action.payload,
4073
}),
74+
75+
// Environment reducers
76+
[ReduxActionTypes.FETCH_ENVIRONMENTS]: (state: EnterpriseReduxState) => ({
77+
...state,
78+
environments: {
79+
...state.environments,
80+
loading: true,
81+
error: null,
82+
},
83+
}),
84+
[ReduxActionTypes.FETCH_ENVIRONMENTS_SUCCESS]: (
85+
state: EnterpriseReduxState,
86+
action: ReduxAction<Environment[]>
87+
) => ({
88+
...state,
89+
environments: {
90+
...state.environments,
91+
list: action.payload,
92+
loading: false,
93+
},
94+
}),
95+
[ReduxActionTypes.FETCH_ENVIRONMENTS_FAILURE]: (
96+
state: EnterpriseReduxState,
97+
action: ReduxAction<any>
98+
) => ({
99+
...state,
100+
environments: {
101+
...state.environments,
102+
loading: false,
103+
error: action.payload,
104+
},
105+
}),
106+
107+
[ReduxActionTypes.FETCH_ENVIRONMENT]: (state: EnterpriseReduxState) => ({
108+
...state,
109+
environments: {
110+
...state.environments,
111+
loading: true,
112+
error: null,
113+
},
114+
}),
115+
[ReduxActionTypes.FETCH_ENVIRONMENT_SUCCESS]: (
116+
state: EnterpriseReduxState,
117+
action: ReduxAction<Environment>
118+
) => ({
119+
...state,
120+
environments: {
121+
...state.environments,
122+
currentEnvironment: action.payload,
123+
loading: false,
124+
},
125+
}),
126+
[ReduxActionTypes.FETCH_ENVIRONMENT_FAILURE]: (
127+
state: EnterpriseReduxState,
128+
action: ReduxAction<any>
129+
) => ({
130+
...state,
131+
environments: {
132+
...state.environments,
133+
loading: false,
134+
error: action.payload,
135+
},
136+
}),
137+
138+
[ReduxActionTypes.CREATE_ENVIRONMENT]: (state: EnterpriseReduxState) => ({
139+
...state,
140+
environments: {
141+
...state.environments,
142+
creating: true,
143+
error: null,
144+
},
145+
}),
146+
[ReduxActionTypes.CREATE_ENVIRONMENT_SUCCESS]: (
147+
state: EnterpriseReduxState,
148+
action: ReduxAction<Environment>
149+
) => ({
150+
...state,
151+
environments: {
152+
...state.environments,
153+
list: [...state.environments.list, action.payload],
154+
creating: false,
155+
},
156+
}),
157+
[ReduxActionTypes.CREATE_ENVIRONMENT_FAILURE]: (
158+
state: EnterpriseReduxState,
159+
action: ReduxAction<any>
160+
) => ({
161+
...state,
162+
environments: {
163+
...state.environments,
164+
creating: false,
165+
error: action.payload,
166+
},
167+
}),
168+
169+
[ReduxActionTypes.UPDATE_ENVIRONMENT]: (state: EnterpriseReduxState) => ({
170+
...state,
171+
environments: {
172+
...state.environments,
173+
updating: true,
174+
error: null,
175+
},
176+
}),
177+
[ReduxActionTypes.UPDATE_ENVIRONMENT_SUCCESS]: (
178+
state: EnterpriseReduxState,
179+
action: ReduxAction<Environment>
180+
) => ({
181+
...state,
182+
environments: {
183+
...state.environments,
184+
list: state.environments.list.map((env) =>
185+
env.environmentId === action.payload.environmentId
186+
? action.payload
187+
: env
188+
),
189+
currentEnvironment:
190+
state.environments.currentEnvironment?.environmentId ===
191+
action.payload.environmentId
192+
? action.payload
193+
: state.environments.currentEnvironment,
194+
updating: false,
195+
},
196+
}),
197+
[ReduxActionTypes.UPDATE_ENVIRONMENT_FAILURE]: (
198+
state: EnterpriseReduxState,
199+
action: ReduxAction<any>
200+
) => ({
201+
...state,
202+
environments: {
203+
...state.environments,
204+
updating: false,
205+
error: action.payload,
206+
},
207+
}),
208+
209+
[ReduxActionTypes.DELETE_ENVIRONMENT]: (state: EnterpriseReduxState) => ({
210+
...state,
211+
environments: {
212+
...state.environments,
213+
deleting: true,
214+
error: null,
215+
},
216+
}),
217+
[ReduxActionTypes.DELETE_ENVIRONMENT_SUCCESS]: (
218+
state: EnterpriseReduxState,
219+
action: ReduxAction<{ environmentId: string }>
220+
) => ({
221+
...state,
222+
environments: {
223+
...state.environments,
224+
list: state.environments.list.filter(
225+
(env) => env.environmentId !== action.payload.environmentId
226+
),
227+
currentEnvironment:
228+
state.environments.currentEnvironment?.environmentId ===
229+
action.payload.environmentId
230+
? null
231+
: state.environments.currentEnvironment,
232+
deleting: false,
233+
},
234+
}),
235+
[ReduxActionTypes.DELETE_ENVIRONMENT_FAILURE]: (
236+
state: EnterpriseReduxState,
237+
action: ReduxAction<any>
238+
) => ({
239+
...state,
240+
environments: {
241+
...state.environments,
242+
deleting: false,
243+
error: action.payload,
244+
},
245+
}),
246+
247+
[ReduxActionTypes.UPDATE_ENVIRONMENT_API_KEY]: (
248+
state: EnterpriseReduxState
249+
) => ({
250+
...state,
251+
environments: {
252+
...state.environments,
253+
updatingApiKey: true,
254+
error: null,
255+
},
256+
}),
257+
[ReduxActionTypes.UPDATE_ENVIRONMENT_API_KEY_SUCCESS]: (
258+
state: EnterpriseReduxState,
259+
action: ReduxAction<{ environmentId: string; hasApiKey: boolean }>
260+
) => ({
261+
...state,
262+
environments: {
263+
...state.environments,
264+
list: state.environments.list.map((env) =>
265+
env.environmentId === action.payload.environmentId
266+
? {
267+
...env,
268+
environmentApikey: action.payload.hasApiKey ? "CONFIGURED" : "",
269+
}
270+
: env
271+
),
272+
updatingApiKey: false,
273+
},
274+
}),
275+
[ReduxActionTypes.UPDATE_ENVIRONMENT_API_KEY_FAILURE]: (
276+
state: EnterpriseReduxState,
277+
action: ReduxAction<any>
278+
) => ({
279+
...state,
280+
environments: {
281+
...state.environments,
282+
updatingApiKey: false,
283+
error: action.payload,
284+
},
285+
}),
286+
287+
[ReduxActionTypes.SET_CURRENT_ENVIRONMENT]: (
288+
state: EnterpriseReduxState,
289+
action: ReduxAction<Environment | null>
290+
) => ({
291+
...state,
292+
environments: {
293+
...state.environments,
294+
currentEnvironment: action.payload,
295+
},
296+
}),
41297
});
42298

43299
export default enterpriseReducer;

0 commit comments

Comments
 (0)