Skip to content

Commit

Permalink
feat : Group chaos infra in infrastructure selection modal (#4779)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people committed Sep 6, 2024
1 parent e7c18ba commit 1a03758
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 101 deletions.
6 changes: 6 additions & 0 deletions chaoscenter/web/src/api/entities/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ export interface EnvironmentSortInput {
field: SortType;
ascending: boolean;
}

export interface EnvironmentDetail {
envName: string;
envID: string;
totalInfra?: number | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,55 @@ import React from 'react';
import { listChaosInfra } from '@api/core';
import { getScope } from '@utils';
import ChaosInfrastructureReferenceFieldView from '@views/ChaosInfrastructureReferenceField';
import type { ChaosInfrastructureReferenceFieldProps } from '@models';
import { AllEnv, type ChaosInfrastructureReferenceFieldProps } from '@models';
import type { InfrastructureDetails } from '@views/ChaosInfrastructureReferenceField/ChaosInfrastructureReferenceField';
import { listEnvironment } from '@api/core/environments';

function KubernetesChaosInfrastructureReferenceFieldController({
setFieldValue,
initialInfrastructureID
initialInfrastructureID,
initialEnvironmentID
}: ChaosInfrastructureReferenceFieldProps): React.ReactElement {
const scope = getScope();
const { showError } = useToaster();
const [searchInfrastructure, setSearchInfrastructure] = React.useState<string>('');

const [page, setPage] = React.useState<number>(0);
const limit = 8;
const [limit, setLimit] = React.useState<number>(5);
const [envID, setEnvID] = React.useState<string>(AllEnv.AllEnv);
const [initialAllInfrastructureLength, setInitialAllInfrastructureLength] = React.useState<number>(0);

const { data: listChaosInfraData, loading: listChaosInfraLoading } = listChaosInfra({
...scope,
filter: { name: searchInfrastructure, isActive: true },
environmentIDs: envID === AllEnv.AllEnv ? undefined : [envID],
filter: { name: searchInfrastructure },
pagination: { page, limit },
options: { onError: error => showError(error.message) }
});

const { data: listEnvironmentData } = listEnvironment({
...scope,
options: {
onError: err => showError(err.message)
}
});

const environmentList = listEnvironmentData?.listEnvironments?.environments;

React.useEffect(() => {
if (envID === AllEnv.AllEnv) {
setInitialAllInfrastructureLength(listChaosInfraData?.listInfras.totalNoOfInfras || 0);
}
}, [listChaosInfraData]);

const preSelectedEnvironment = listEnvironmentData?.listEnvironments?.environments?.find(
({ environmentID }) => environmentID === initialEnvironmentID
);

// TODO: replace with get API as this becomes empty during edit
const preSelectedInfrastructure = listChaosInfraData?.listInfras.infras.find(
({ infraID }) => infraID === initialInfrastructureID
);

const preSelectedInfrastructureDetails: InfrastructureDetails | undefined = preSelectedInfrastructure && {
id: preSelectedInfrastructure?.infraID,
name: preSelectedInfrastructure?.name,
Expand All @@ -38,6 +62,16 @@ function KubernetesChaosInfrastructureReferenceFieldController({
environmentID: preSelectedInfrastructure?.environmentID
};

React.useEffect(() => {
setPage(0);
}, [envID]);

React.useEffect(() => {
if (preSelectedEnvironment) {
setEnvID(preSelectedEnvironment?.environmentID);
}
}, [preSelectedEnvironment, setFieldValue]);

React.useEffect(() => {
if (preSelectedInfrastructure) {
setFieldValue('chaosInfrastructure.id', preSelectedInfrastructure.infraID, true);
Expand Down Expand Up @@ -69,7 +103,10 @@ function KubernetesChaosInfrastructureReferenceFieldController({
pageSize={limit}
pageCount={Math.ceil(totalNoOfInfras / limit)}
pageIndex={page}
gotoPage={pageNumber => setPage(pageNumber)}
gotoPage={setPage}
showPagination={true}
pageSizeOptions={[5, 10, 15]}
onPageSizeChange={setLimit}
/>
);
};
Expand All @@ -87,6 +124,10 @@ function KubernetesChaosInfrastructureReferenceFieldController({
}}
searchInfrastructure={searchInfrastructure}
setSearchInfrastructure={setSearchInfrastructure}
allInfrastructureLength={initialAllInfrastructureLength}
environmentList={environmentList}
envID={envID}
setEnvID={setEnvID}
loading={{
listChaosInfra: listChaosInfraLoading
}}
Expand Down
5 changes: 5 additions & 0 deletions chaoscenter/web/src/models/chaosInfrastructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function getChaosInfrastructureStatus(
export interface ChaosInfrastructureReferenceFieldProps {
setFieldValue: FormikHelpers<ExperimentMetadata>['setFieldValue'];
initialInfrastructureID: string | undefined;
initialEnvironmentID: string | undefined;
}

export enum DeploymentScopeOptions {
Expand Down Expand Up @@ -64,6 +65,10 @@ export interface InitialValueProps {
tolerationValues?: Array<Toleration>;
}

export enum AllEnv {
AllEnv = 'All'
}

export interface DeploymentScopeItem extends CollapsableSelectOptions {
type: DeploymentScopeOptions;
name: string;
Expand Down
1 change: 1 addition & 0 deletions chaoscenter/web/src/strings/strings.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ infrastructureRegistered: >-
Environment -> Infrastructure list.
infrastructureStates: Learn more about the states of Infrastructure
infrastructureType: Infrastructure type
infrastructures: Infrastructures
initialDelay: Initial Delay
initialDelaySeconds: Initial Delay Seconds
insecureSkipVerify: Insecure skip verify
Expand Down
1 change: 1 addition & 0 deletions chaoscenter/web/src/strings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ export interface StringsMap {
'infrastructureRegistered': unknown
'infrastructureStates': unknown
'infrastructureType': unknown
'infrastructures': unknown
'initialDelay': unknown
'initialDelaySeconds': unknown
'insecureSkipVerify': unknown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
padding: var(--spacing-xlarge) !important;

&.dialog {
width: 833px;
width: 912px;
height: 86vh;
max-height: 989px;
}
Expand Down Expand Up @@ -60,14 +60,13 @@
background: #effbff;
border: 1.5px solid #0278d5;
box-shadow: 0px 0px 1px rgba(40, 41, 61, 0.04), 0px 2px 4px rgba(96, 97, 112, 0.16);
border-radius: 4px;
border-radius: 8px;
}

.notSelected {
background: #fafbfc;
border: 1px solid rgba(40, 41, 61, 0.3);
box-shadow: 0px 0px 1px rgba(40, 41, 61, 0.04), 0px 2px 4px rgba(96, 97, 112, 0.16);
border-radius: 4px;
border-radius: 8px;
cursor: pointer;
}

Expand All @@ -78,14 +77,13 @@

.agentListInnerContainer {
flex-grow: 1;
overflow: auto;
gap: 1rem;
max-height: calc(100% - 48px);
overflow: auto;
}

.item {
display: grid;
grid-template-columns: 5fr 4fr 25px;
grid-template-columns: 3fr 4fr 25px;
align-items: center;
gap: 0.5rem;

Expand All @@ -95,7 +93,6 @@
}

.iconCheck {
visibility: hidden;
margin-right: var(--spacing-xsmall);
margin-left: var(--spacing-xsmall);
cursor: pointer;
Expand All @@ -104,7 +101,15 @@
> svg {
> path {
stroke-width: 1;
stroke: var(--grey-500);
stroke: var(--grey-100);
}
}
}
.iconCheck:hover {
> svg {
> path {
stroke-width: 1;
stroke: var(--green-500);
}
}
}
Expand Down Expand Up @@ -134,7 +139,7 @@
.gitInfo {
display: grid;
grid-template-columns: 4fr 5fr;
padding: 6px 8px;
padding: 4px 8px;
background: var(--grey-100) !important;
border-radius: 8px !important;
width: 100%;
Expand Down Expand Up @@ -170,11 +175,6 @@
position: fixed;
}

.gap-4 {
gap: 1rem;
overflow: auto;
}

.paginationContainer {
padding-top: 8px;
overflow: hidden;
Expand All @@ -190,3 +190,37 @@
}
}
}

.listEnvContainer {
background: var(--primary-1);
box-shadow: 0px 0px 1px rgba(40, 41, 61, 0.04), 0px 2px 4px rgba(96, 97, 112, 0.16);
border-radius: 8px;
cursor: pointer;
}

.itemEnv {
width: 100%;
display: grid;
grid-template-columns: 1fr 25px;
align-items: center;
gap: 0.5rem;
}

.activeEnv {
border: 1px solid var(--primary-7);
}

.center {
display: flex;
flex-direction: column;
justify-content: center;
align-self: center;

img {
width: 200px;
}
}

.rounded {
border-radius: 999px;
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
declare namespace ChaosInfrastructureReferenceFieldModuleScssNamespace {
export interface IChaosInfrastructureReferenceFieldModuleScss {
activeEnv: string;
agentList: string;
agentListInnerContainer: string;
center: string;
container: string;
dialog: string;
editBtn: string;
fixed: string;
gap4: string;
gitBranchIcon: string;
gitInfo: string;
greenStatus: string;
iconCheck: string;
iconChecked: string;
item: string;
itemEnv: string;
leftInfo: string;
listEnvContainer: string;
notSelected: string;
paginationContainer: string;
placeholder: string;
redStatus: string;
referenceSelect: string;
rounded: string;
selected: string;
status: string;
}
Expand Down
Loading

0 comments on commit 1a03758

Please sign in to comment.