Skip to content

Commit 80a0f22

Browse files
Merge pull request #888 from devtron-labs/feat/cv-table-api
feat: cost visibility table api
2 parents 5b8807e + 94f4e70 commit 80a0f22

File tree

16 files changed

+161
-106
lines changed

16 files changed

+161
-106
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.20.1-pre-4",
3+
"version": "1.20.1-pre-5",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Assets/IconV2/ic-alibaba.svg

Lines changed: 3 additions & 0 deletions
Loading

src/Assets/IconV2/ic-aws.svg

Lines changed: 11 additions & 0 deletions
Loading
Lines changed: 6 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

src/Assets/IconV2/ic-otc-cloud.svg

Lines changed: 5 additions & 0 deletions
Loading

src/Common/Common.service.ts

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
sanitizeUserApprovalList,
2424
stringComparatorBySortOrder,
2525
} from '@Shared/Helpers'
26-
import { PolicyBlockInfo, RuntimeParamsAPIResponseType, RuntimePluginVariables } from '@Shared/types'
26+
import { EnvListMinDTO, PolicyBlockInfo, RuntimeParamsAPIResponseType, RuntimePluginVariables } from '@Shared/types'
2727
import { GitProviderType, ROUTES } from './Constants'
2828
import { getUrlWithSearchParams, sortCallback } from './Helper'
2929
import {
@@ -51,11 +51,14 @@ import {
5151
GetAppsInfoForEnvProps,
5252
AppMeta,
5353
ApprovalRuntimeStateType,
54+
EnvironmentsGroupedByClustersType,
55+
AppsGroupedByProjectsType,
5456
} from './Types'
5557
import { ApiResourceType, STAGE_MAP } from '../Pages'
5658
import { RefVariableType, VariableTypeFormat } from './CIPipeline.Types'
5759
import { get, post } from './API'
5860
import { StatusType } from '@Shared/Components'
61+
import { EnvironmentTypeEnum } from '@Shared/constants'
5962

6063
export const getTeamListMin = (): Promise<TeamList> => {
6164
// ignore active field
@@ -564,3 +567,67 @@ export const getAppsInfoForEnv = async ({ envId, appIds }: GetAppsInfoForEnvProp
564567
}, []),
565568
}
566569
}
570+
571+
572+
export const getAppOptionsGroupedByProjects = async (): Promise<AppsGroupedByProjectsType> => {
573+
const { result } = await get<AppsGroupedByProjectsType>(ROUTES.APP_LIST_MIN)
574+
575+
if (!result) {
576+
return []
577+
}
578+
579+
return result
580+
.map((project) => ({
581+
...project,
582+
appList: project.appList.sort((a, b) => stringComparatorBySortOrder(a.name, b.name)),
583+
}))
584+
.sort((a, b) => stringComparatorBySortOrder(a.projectName, b.projectName))
585+
}
586+
587+
588+
export const getEnvironmentOptionsGroupedByClusters = async (): Promise<EnvironmentsGroupedByClustersType> => {
589+
const { result } = (await get(ROUTES.ENVIRONMENT_LIST_MIN)) as ResponseType<EnvListMinDTO[]>
590+
591+
if (!result) {
592+
return []
593+
}
594+
595+
const sortedEnvList = result
596+
.map(
597+
({
598+
id,
599+
environment_name: name,
600+
isVirtualEnvironment,
601+
cluster_name: cluster,
602+
default: isDefault,
603+
namespace,
604+
}) => ({
605+
id,
606+
name,
607+
isVirtual: isVirtualEnvironment ?? false,
608+
cluster,
609+
environmentType: isDefault ? EnvironmentTypeEnum.production : EnvironmentTypeEnum.nonProduction,
610+
namespace,
611+
}),
612+
)
613+
.sort((a, b) => stringComparatorBySortOrder(a.name, b.name))
614+
615+
const envGroupedByCluster = Object.values(
616+
sortedEnvList.reduce<
617+
Record<EnvironmentsGroupedByClustersType[number]['clusterName'], EnvironmentsGroupedByClustersType[number]>
618+
>((acc, env) => {
619+
if (!acc[env.cluster]) {
620+
acc[env.cluster] = {
621+
clusterName: env.cluster,
622+
envList: [],
623+
}
624+
}
625+
626+
acc[env.cluster].envList.push(env)
627+
628+
return acc
629+
}, {}),
630+
).sort((a, b) => stringComparatorBySortOrder(a.clusterName, b.clusterName))
631+
632+
return envGroupedByCluster
633+
}

src/Common/Types.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
StatusType,
3030
DocLinkProps,
3131
DeploymentStrategyType,
32+
EnvironmentType,
3233
} from '../Shared'
3334
import {
3435
ACTION_STATE,
@@ -215,19 +216,21 @@ export type ErrorScreenManagerProps = {
215216
reloadClass?: string
216217
} & (
217218
| {
218-
/**
219-
* Would be used to redirect URL in case of 404
220-
* @default - APP_LIST
221-
*/
222-
redirectURL?: string
223-
on404Redirect?: never
224-
} | {
225-
redirectURL?: never
226-
on404Redirect: () => void
227-
} | {
228-
redirectURL?: never
229-
on404Redirect?: never
230-
}
219+
/**
220+
* Would be used to redirect URL in case of 404
221+
* @default - APP_LIST
222+
*/
223+
redirectURL?: string
224+
on404Redirect?: never
225+
}
226+
| {
227+
redirectURL?: never
228+
on404Redirect: () => void
229+
}
230+
| {
231+
redirectURL?: never
232+
on404Redirect?: never
233+
}
231234
)
232235

233236
export interface ErrorScreenNotAuthorizedProps {
@@ -1099,4 +1102,17 @@ export interface ClusterEnvironmentCategoryDTO {
10991102
description?: string
11001103
}
11011104

1102-
export interface ClusterEnvironmentCategoryType extends ClusterEnvironmentCategoryDTO {}
1105+
export interface ClusterEnvironmentCategoryType extends ClusterEnvironmentCategoryDTO {}
1106+
1107+
export type AppsGroupedByProjectsType = {
1108+
projectId: number
1109+
projectName: string
1110+
appList: {
1111+
name: string
1112+
}[]
1113+
}[]
1114+
1115+
export type EnvironmentsGroupedByClustersType = {
1116+
clusterName: EnvironmentType['cluster']
1117+
envList: EnvironmentType[]
1118+
}[]

0 commit comments

Comments
 (0)