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 9 commits
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
Original file line number Diff line number Diff line change
@@ -1,33 +1,58 @@
import { Pagination, useToaster } from '@harnessio/uicore';
import React from 'react';
import React, { useEffect } from 'react';
import { listChaosInfra } from '@api/core';
import { getScope } from '@utils';
import ChaosInfrastructureReferenceFieldView from '@views/ChaosInfrastructureReferenceField';
import 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 = 5;
JanhaviAlekar marked this conversation as resolved.
Show resolved Hide resolved
const [envID, setEnvID] = React.useState<string>('all');
const [initialAllInfrastructureLength, setInitialAllInfrastructureLength] = React.useState<number>(0);
SahilKr24 marked this conversation as resolved.
Show resolved Hide resolved
const [activeEnv, setActiveEnv] = React.useState<string>('all');
SahilKr24 marked this conversation as resolved.
Show resolved Hide resolved

const { data: listChaosInfraData, loading: listChaosInfraLoading } = listChaosInfra({
...scope,
filter: { name: searchInfrastructure, isActive: true },
environmentIDs: envID === 'all' ? 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 === 'all' && listChaosInfraData?.listInfras?.totalNoOfInfras && searchInfrastructure === '') {
setInitialAllInfrastructureLength(listChaosInfraData.listInfras.totalNoOfInfras);
}
}, [listChaosInfraData]);
JanhaviAlekar marked this conversation as resolved.
Show resolved Hide resolved

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 +63,16 @@ function KubernetesChaosInfrastructureReferenceFieldController({
environmentID: preSelectedInfrastructure?.environmentID
};

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

useEffect(() => {
if (preSelectedEnvironment) {
setEnvID(preSelectedEnvironment?.environmentID), setActiveEnv(preSelectedEnvironment?.environmentID);
JanhaviAlekar marked this conversation as resolved.
Show resolved Hide resolved
}
}, [preSelectedEnvironment, setFieldValue]);

JanhaviAlekar marked this conversation as resolved.
Show resolved Hide resolved
React.useEffect(() => {
if (preSelectedInfrastructure) {
setFieldValue('chaosInfrastructure.id', preSelectedInfrastructure.infraID, true);
Expand All @@ -47,7 +82,7 @@ function KubernetesChaosInfrastructureReferenceFieldController({
}
}, [preSelectedInfrastructure, setFieldValue]);

const infrastructureList = listChaosInfraData?.listInfras.infras.map(infra => {
const infrastructureList = listChaosInfraData?.listInfras?.infras.map(infra => {
JanhaviAlekar marked this conversation as resolved.
Show resolved Hide resolved
const infraDetails: InfrastructureDetails = {
id: infra.infraID,
name: infra.name,
Expand Down Expand Up @@ -85,8 +120,13 @@ function KubernetesChaosInfrastructureReferenceFieldController({
setFieldValue('chaosInfrastructure.environmentID', infrastructure.environmentID, false);
}
}}
activeEnv={activeEnv}
setActiveEnv={setActiveEnv}
JanhaviAlekar marked this conversation as resolved.
Show resolved Hide resolved
searchInfrastructure={searchInfrastructure}
setSearchInfrastructure={setSearchInfrastructure}
allInfrastructureLength={initialAllInfrastructureLength}
environmentList={environmentList}
setEnvID={setEnvID}
loading={{
listChaosInfra: listChaosInfraLoading
}}
Expand Down
1 change: 1 addition & 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
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,32 +60,33 @@
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 !important;
}

.notSelected {
background: #fafbfc;
border: 1px solid rgba(40, 41, 61, 0.3);
// border: 1px solid rgba(40, 41, 61, 0.3);
JanhaviAlekar marked this conversation as resolved.
Show resolved Hide resolved
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 !important;
JanhaviAlekar marked this conversation as resolved.
Show resolved Hide resolved
cursor: pointer;
}

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

.agentListInnerContainer {
flex-grow: 1;
overflow: auto;
// overflow: auto;
JanhaviAlekar marked this conversation as resolved.
Show resolved Hide resolved
gap: 1rem;
max-height: calc(100% - 48px);
}

.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 +96,6 @@
}

.iconCheck {
visibility: hidden;
margin-right: var(--spacing-xsmall);
margin-left: var(--spacing-xsmall);
cursor: pointer;
Expand All @@ -104,7 +104,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 +142,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 @@ -172,7 +180,7 @@

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

.paginationContainer {
Expand All @@ -190,3 +198,37 @@
}
}
}

.listEnvContainer {
background: #effbff;
JanhaviAlekar marked this conversation as resolved.
Show resolved Hide resolved
box-shadow: 0px 0px 1px rgba(40, 41, 61, 0.04), 0px 2px 4px rgba(96, 97, 112, 0.16);
border-radius: 8px !important;
JanhaviAlekar marked this conversation as resolved.
Show resolved Hide resolved
cursor: pointer;
}

.itemEnv {
width: 100%;
display: grid;
grid-template-columns: 3fr 25px;
JanhaviAlekar marked this conversation as resolved.
Show resolved Hide resolved
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,7 +1,9 @@
declare namespace ChaosInfrastructureReferenceFieldModuleScssNamespace {
export interface IChaosInfrastructureReferenceFieldModuleScss {
activeEnv: string;
agentList: string;
agentListInnerContainer: string;
center: string;
container: string;
dialog: string;
editBtn: string;
Expand All @@ -13,12 +15,15 @@ declare namespace ChaosInfrastructureReferenceFieldModuleScssNamespace {
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
Loading