Skip to content

Commit 1a03758

Browse files
JanhaviAlekarSahilKr24Saranya-jena
authored
feat : Group chaos infra in infrastructure selection modal (#4779)
* Adding environment filter in Infrastructure selection modal Signed-off-by: JanhaviAlekar <[email protected]> * setting initialAllInfrastructureLength as 0 initially Signed-off-by: JanhaviAlekar <[email protected]> * making InitialAllInfrastructureLength consistent Signed-off-by: JanhaviAlekar <[email protected]> * Scroll env list and Pagination(infra) Signed-off-by: JanhaviAlekar <[email protected]> * added preSelectedEnvironmentID Signed-off-by: JanhaviAlekar <[email protected]> * Minor changes in code Signed-off-by: JanhaviAlekar <[email protected]> * Refactored code Signed-off-by: JanhaviAlekar <[email protected]> * Changing height of infralist section Signed-off-by: JanhaviAlekar <[email protected]> * Minor improvements Signed-off-by: JanhaviAlekar <[email protected]> --------- Signed-off-by: JanhaviAlekar <[email protected]> Co-authored-by: Sahil <[email protected]> Co-authored-by: Saranya Jena <[email protected]>
1 parent e7c18ba commit 1a03758

File tree

9 files changed

+290
-101
lines changed

9 files changed

+290
-101
lines changed

chaoscenter/web/src/api/entities/environment.ts

+6
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ export interface EnvironmentSortInput {
2323
field: SortType;
2424
ascending: boolean;
2525
}
26+
27+
export interface EnvironmentDetail {
28+
envName: string;
29+
envID: string;
30+
totalInfra?: number | null;
31+
}

chaoscenter/web/src/controllers/KubernetesChaosInfrastructureReferenceField/KubernetesChaosInfrastructureReferenceField.tsx

+47-6
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,55 @@ import React from 'react';
33
import { listChaosInfra } from '@api/core';
44
import { getScope } from '@utils';
55
import ChaosInfrastructureReferenceFieldView from '@views/ChaosInfrastructureReferenceField';
6-
import type { ChaosInfrastructureReferenceFieldProps } from '@models';
6+
import { AllEnv, type ChaosInfrastructureReferenceFieldProps } from '@models';
77
import type { InfrastructureDetails } from '@views/ChaosInfrastructureReferenceField/ChaosInfrastructureReferenceField';
8+
import { listEnvironment } from '@api/core/environments';
89

910
function KubernetesChaosInfrastructureReferenceFieldController({
1011
setFieldValue,
11-
initialInfrastructureID
12+
initialInfrastructureID,
13+
initialEnvironmentID
1214
}: ChaosInfrastructureReferenceFieldProps): React.ReactElement {
1315
const scope = getScope();
1416
const { showError } = useToaster();
1517
const [searchInfrastructure, setSearchInfrastructure] = React.useState<string>('');
16-
1718
const [page, setPage] = React.useState<number>(0);
18-
const limit = 8;
19+
const [limit, setLimit] = React.useState<number>(5);
20+
const [envID, setEnvID] = React.useState<string>(AllEnv.AllEnv);
21+
const [initialAllInfrastructureLength, setInitialAllInfrastructureLength] = React.useState<number>(0);
1922

2023
const { data: listChaosInfraData, loading: listChaosInfraLoading } = listChaosInfra({
2124
...scope,
22-
filter: { name: searchInfrastructure, isActive: true },
25+
environmentIDs: envID === AllEnv.AllEnv ? undefined : [envID],
26+
filter: { name: searchInfrastructure },
2327
pagination: { page, limit },
2428
options: { onError: error => showError(error.message) }
2529
});
2630

31+
const { data: listEnvironmentData } = listEnvironment({
32+
...scope,
33+
options: {
34+
onError: err => showError(err.message)
35+
}
36+
});
37+
38+
const environmentList = listEnvironmentData?.listEnvironments?.environments;
39+
40+
React.useEffect(() => {
41+
if (envID === AllEnv.AllEnv) {
42+
setInitialAllInfrastructureLength(listChaosInfraData?.listInfras.totalNoOfInfras || 0);
43+
}
44+
}, [listChaosInfraData]);
45+
46+
const preSelectedEnvironment = listEnvironmentData?.listEnvironments?.environments?.find(
47+
({ environmentID }) => environmentID === initialEnvironmentID
48+
);
49+
2750
// TODO: replace with get API as this becomes empty during edit
2851
const preSelectedInfrastructure = listChaosInfraData?.listInfras.infras.find(
2952
({ infraID }) => infraID === initialInfrastructureID
3053
);
54+
3155
const preSelectedInfrastructureDetails: InfrastructureDetails | undefined = preSelectedInfrastructure && {
3256
id: preSelectedInfrastructure?.infraID,
3357
name: preSelectedInfrastructure?.name,
@@ -38,6 +62,16 @@ function KubernetesChaosInfrastructureReferenceFieldController({
3862
environmentID: preSelectedInfrastructure?.environmentID
3963
};
4064

65+
React.useEffect(() => {
66+
setPage(0);
67+
}, [envID]);
68+
69+
React.useEffect(() => {
70+
if (preSelectedEnvironment) {
71+
setEnvID(preSelectedEnvironment?.environmentID);
72+
}
73+
}, [preSelectedEnvironment, setFieldValue]);
74+
4175
React.useEffect(() => {
4276
if (preSelectedInfrastructure) {
4377
setFieldValue('chaosInfrastructure.id', preSelectedInfrastructure.infraID, true);
@@ -69,7 +103,10 @@ function KubernetesChaosInfrastructureReferenceFieldController({
69103
pageSize={limit}
70104
pageCount={Math.ceil(totalNoOfInfras / limit)}
71105
pageIndex={page}
72-
gotoPage={pageNumber => setPage(pageNumber)}
106+
gotoPage={setPage}
107+
showPagination={true}
108+
pageSizeOptions={[5, 10, 15]}
109+
onPageSizeChange={setLimit}
73110
/>
74111
);
75112
};
@@ -87,6 +124,10 @@ function KubernetesChaosInfrastructureReferenceFieldController({
87124
}}
88125
searchInfrastructure={searchInfrastructure}
89126
setSearchInfrastructure={setSearchInfrastructure}
127+
allInfrastructureLength={initialAllInfrastructureLength}
128+
environmentList={environmentList}
129+
envID={envID}
130+
setEnvID={setEnvID}
90131
loading={{
91132
listChaosInfra: listChaosInfraLoading
92133
}}

chaoscenter/web/src/models/chaosInfrastructure.ts

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export function getChaosInfrastructureStatus(
3131
export interface ChaosInfrastructureReferenceFieldProps {
3232
setFieldValue: FormikHelpers<ExperimentMetadata>['setFieldValue'];
3333
initialInfrastructureID: string | undefined;
34+
initialEnvironmentID: string | undefined;
3435
}
3536

3637
export enum DeploymentScopeOptions {
@@ -64,6 +65,10 @@ export interface InitialValueProps {
6465
tolerationValues?: Array<Toleration>;
6566
}
6667

68+
export enum AllEnv {
69+
AllEnv = 'All'
70+
}
71+
6772
export interface DeploymentScopeItem extends CollapsableSelectOptions {
6873
type: DeploymentScopeOptions;
6974
name: string;

chaoscenter/web/src/strings/strings.en.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ infrastructureRegistered: >-
486486
Environment -> Infrastructure list.
487487
infrastructureStates: Learn more about the states of Infrastructure
488488
infrastructureType: Infrastructure type
489+
infrastructures: Infrastructures
489490
initialDelay: Initial Delay
490491
initialDelaySeconds: Initial Delay Seconds
491492
insecureSkipVerify: Insecure skip verify

chaoscenter/web/src/strings/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ export interface StringsMap {
409409
'infrastructureRegistered': unknown
410410
'infrastructureStates': unknown
411411
'infrastructureType': unknown
412+
'infrastructures': unknown
412413
'initialDelay': unknown
413414
'initialDelaySeconds': unknown
414415
'insecureSkipVerify': unknown

chaoscenter/web/src/views/ChaosInfrastructureReferenceField/ChaosInfrastructureReferenceField.module.scss

+49-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
padding: var(--spacing-xlarge) !important;
33

44
&.dialog {
5-
width: 833px;
5+
width: 912px;
66
height: 86vh;
77
max-height: 989px;
88
}
@@ -60,14 +60,13 @@
6060
background: #effbff;
6161
border: 1.5px solid #0278d5;
6262
box-shadow: 0px 0px 1px rgba(40, 41, 61, 0.04), 0px 2px 4px rgba(96, 97, 112, 0.16);
63-
border-radius: 4px;
63+
border-radius: 8px;
6464
}
6565

6666
.notSelected {
6767
background: #fafbfc;
68-
border: 1px solid rgba(40, 41, 61, 0.3);
6968
box-shadow: 0px 0px 1px rgba(40, 41, 61, 0.04), 0px 2px 4px rgba(96, 97, 112, 0.16);
70-
border-radius: 4px;
69+
border-radius: 8px;
7170
cursor: pointer;
7271
}
7372

@@ -78,14 +77,13 @@
7877

7978
.agentListInnerContainer {
8079
flex-grow: 1;
81-
overflow: auto;
8280
gap: 1rem;
83-
max-height: calc(100% - 48px);
81+
overflow: auto;
8482
}
8583

8684
.item {
8785
display: grid;
88-
grid-template-columns: 5fr 4fr 25px;
86+
grid-template-columns: 3fr 4fr 25px;
8987
align-items: center;
9088
gap: 0.5rem;
9189

@@ -95,7 +93,6 @@
9593
}
9694

9795
.iconCheck {
98-
visibility: hidden;
9996
margin-right: var(--spacing-xsmall);
10097
margin-left: var(--spacing-xsmall);
10198
cursor: pointer;
@@ -104,7 +101,15 @@
104101
> svg {
105102
> path {
106103
stroke-width: 1;
107-
stroke: var(--grey-500);
104+
stroke: var(--grey-100);
105+
}
106+
}
107+
}
108+
.iconCheck:hover {
109+
> svg {
110+
> path {
111+
stroke-width: 1;
112+
stroke: var(--green-500);
108113
}
109114
}
110115
}
@@ -134,7 +139,7 @@
134139
.gitInfo {
135140
display: grid;
136141
grid-template-columns: 4fr 5fr;
137-
padding: 6px 8px;
142+
padding: 4px 8px;
138143
background: var(--grey-100) !important;
139144
border-radius: 8px !important;
140145
width: 100%;
@@ -170,11 +175,6 @@
170175
position: fixed;
171176
}
172177

173-
.gap-4 {
174-
gap: 1rem;
175-
overflow: auto;
176-
}
177-
178178
.paginationContainer {
179179
padding-top: 8px;
180180
overflow: hidden;
@@ -190,3 +190,37 @@
190190
}
191191
}
192192
}
193+
194+
.listEnvContainer {
195+
background: var(--primary-1);
196+
box-shadow: 0px 0px 1px rgba(40, 41, 61, 0.04), 0px 2px 4px rgba(96, 97, 112, 0.16);
197+
border-radius: 8px;
198+
cursor: pointer;
199+
}
200+
201+
.itemEnv {
202+
width: 100%;
203+
display: grid;
204+
grid-template-columns: 1fr 25px;
205+
align-items: center;
206+
gap: 0.5rem;
207+
}
208+
209+
.activeEnv {
210+
border: 1px solid var(--primary-7);
211+
}
212+
213+
.center {
214+
display: flex;
215+
flex-direction: column;
216+
justify-content: center;
217+
align-self: center;
218+
219+
img {
220+
width: 200px;
221+
}
222+
}
223+
224+
.rounded {
225+
border-radius: 999px;
226+
}

chaoscenter/web/src/views/ChaosInfrastructureReferenceField/ChaosInfrastructureReferenceField.module.scss.d.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
declare namespace ChaosInfrastructureReferenceFieldModuleScssNamespace {
22
export interface IChaosInfrastructureReferenceFieldModuleScss {
3+
activeEnv: string;
34
agentList: string;
45
agentListInnerContainer: string;
6+
center: string;
57
container: string;
68
dialog: string;
79
editBtn: string;
810
fixed: string;
9-
gap4: string;
1011
gitBranchIcon: string;
1112
gitInfo: string;
1213
greenStatus: string;
1314
iconCheck: string;
1415
iconChecked: string;
1516
item: string;
17+
itemEnv: string;
1618
leftInfo: string;
19+
listEnvContainer: string;
1720
notSelected: string;
1821
paginationContainer: string;
1922
placeholder: string;
2023
redStatus: string;
2124
referenceSelect: string;
25+
rounded: string;
2226
selected: string;
2327
status: string;
2428
}

0 commit comments

Comments
 (0)