Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : Group chaos infra in infrastructure selection modal #4779

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -1,9 +1,9 @@
import { Pagination, useToaster } from '@harnessio/uicore';
import React, { useEffect } from 'react';
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';

Expand All @@ -16,14 +16,13 @@ function KubernetesChaosInfrastructureReferenceFieldController({
const { showError } = useToaster();
const [searchInfrastructure, setSearchInfrastructure] = React.useState<string>('');
const [page, setPage] = React.useState<number>(0);
const limit = 5;
const [envID, setEnvID] = React.useState<string>('all');
const [limit, setLimit] = React.useState<number>(5);
const [envID, setEnvID] = React.useState<string>(AllEnv.AllEnv);
const [initialAllInfrastructureLength, setInitialAllInfrastructureLength] = React.useState<number>(0);
SahilKr24 marked this conversation as resolved.
Show resolved Hide resolved
const [activeEnv, setActiveEnv] = React.useState<string>('all');

const { data: listChaosInfraData, loading: listChaosInfraLoading } = listChaosInfra({
...scope,
environmentIDs: envID === 'all' ? undefined : [envID],
environmentIDs: envID === AllEnv.AllEnv ? undefined : [envID],
filter: { name: searchInfrastructure },
pagination: { page, limit },
options: { onError: error => showError(error.message) }
Expand All @@ -39,8 +38,8 @@ function KubernetesChaosInfrastructureReferenceFieldController({
const environmentList = listEnvironmentData?.listEnvironments?.environments;

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

Expand All @@ -67,9 +66,9 @@ function KubernetesChaosInfrastructureReferenceFieldController({
setPage(0);
}, [envID]);

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

Expand All @@ -82,7 +81,7 @@ function KubernetesChaosInfrastructureReferenceFieldController({
}
}, [preSelectedInfrastructure, setFieldValue]);

const infrastructureList = listChaosInfraData?.listInfras?.infras.map(infra => {
const infrastructureList = listChaosInfraData?.listInfras.infras.map(infra => {
const infraDetails: InfrastructureDetails = {
id: infra.infraID,
name: infra.name,
Expand All @@ -104,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={event => setLimit(parseInt(event.toString()))}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onPageSizeChange={setLimit}

/>
);
};
Expand All @@ -120,12 +122,11 @@ function KubernetesChaosInfrastructureReferenceFieldController({
setFieldValue('chaosInfrastructure.environmentID', infrastructure.environmentID, false);
}
}}
activeEnv={activeEnv}
setActiveEnv={setActiveEnv}
searchInfrastructure={searchInfrastructure}
setSearchInfrastructure={setSearchInfrastructure}
allInfrastructureLength={initialAllInfrastructureLength}
environmentList={environmentList}
envID={envID}
setEnvID={setEnvID}
loading={{
listChaosInfra: listChaosInfraLoading
Expand Down
4 changes: 4 additions & 0 deletions chaoscenter/web/src/models/chaosInfrastructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,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
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,25 @@
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: 8px !important;
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: 8px !important;
border-radius: 8px;
cursor: pointer;
}

.agentList {
flex-grow: 1;
gap: 1rem;
overflow: auto;
}

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

.item {
Expand Down Expand Up @@ -178,11 +175,6 @@
position: fixed;
}

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

.paginationContainer {
padding-top: 8px;
overflow: hidden;
Expand All @@ -200,16 +192,16 @@
}

.listEnvContainer {
background: #effbff;
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 !important;
border-radius: 8px;
cursor: pointer;
}

.itemEnv {
width: 100%;
display: grid;
grid-template-columns: 3fr 25px;
grid-template-columns: 1fr 25px;
align-items: center;
gap: 0.5rem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ declare namespace ChaosInfrastructureReferenceFieldModuleScssNamespace {
dialog: string;
editBtn: string;
fixed: string;
gap4: string;
gitBranchIcon: string;
gitInfo: string;
greenStatus: string;
Expand Down
Loading
Loading