This repository was archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathrepoHome.ts
More file actions
84 lines (73 loc) · 1.87 KB
/
repoHome.ts
File metadata and controls
84 lines (73 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { createSlice, PayloadAction, createAsyncThunk } from '@reduxjs/toolkit';
import { Deployment } from '../models';
import { listDeployments, getConfig } from '../apis';
export const perPage = 20;
interface RepoHomeState {
loading: boolean;
namespace: string;
name: string;
envs: string[];
env: string;
deployments: Deployment[];
page: number;
}
const initialState: RepoHomeState = {
loading: true,
namespace: '',
name: '',
envs: [],
env: '',
deployments: [],
page: 1,
};
export const fetchEnvs = createAsyncThunk<
string[],
void,
{ state: { repoHome: RepoHomeState } }
>('repoHome/fetchEnvs', async (_, { getState }) => {
const { namespace, name } = getState().repoHome;
const config = await getConfig(namespace, name);
return config.envs.map((e) => e.name);
});
export const fetchDeployments = createAsyncThunk<
Deployment[],
{ env: string; page: number },
{ state: { repoHome: RepoHomeState } }
>('repoHome/fetchDeployments', async ({ env, page }, { getState }) => {
const { namespace, name } = getState().repoHome;
const deployments = await listDeployments(
namespace,
name,
env,
'',
page,
perPage
);
return deployments;
});
export const repoHomeSlice = createSlice({
name: 'repoHome',
initialState,
reducers: {
init: (
state,
action: PayloadAction<{ namespace: string; name: string }>
) => {
state.namespace = action.payload.namespace;
state.name = action.payload.name;
},
},
extraReducers: (builder) => {
builder
.addCase(fetchEnvs.fulfilled, (state, action) => {
state.envs = action.payload;
})
.addCase(fetchDeployments.pending, (state) => {
state.loading = true;
})
.addCase(fetchDeployments.fulfilled, (state, action) => {
state.deployments = action.payload;
state.loading = false;
});
},
});