Skip to content

Commit defc9be

Browse files
committed
fix: use constants for api urls and short hand notations
1 parent 7ee8ab4 commit defc9be

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/Common/Constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ export const ROUTES = {
9494
CONFIG_CD_PIPELINE: 'config/cd-pipeline',
9595
MODULE_CONFIGURED: 'module/config',
9696
RESOURCE_HISTORY_DEPLOYMENT: 'resource/history/deployment',
97+
APP_LIST_MIN: 'app/min',
98+
CLUSTER_LIST_MIN: 'cluster/autocomplete',
9799
}
98100

99101
export enum KEY_VALUE {

src/Shared/Hooks/useGetResourceKindsOptions/service.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { stringComparatorBySortOrder } from '@Shared/Helpers'
99
import { AppsGroupedByProjectsType, ClusterDTO } from './types'
1010

1111
export const getAppOptionsGroupedByProjects = async (): Promise<AppsGroupedByProjectsType> => {
12-
const { result } = (await get('app/min')) as ResponseType<AppsGroupedByProjectsType>
12+
const { result } = (await get(ROUTES.APP_LIST_MIN)) as ResponseType<AppsGroupedByProjectsType>
1313

1414
if (!result) {
1515
return []
@@ -39,17 +39,17 @@ export const getProjectOptions = async (): Promise<Pick<Teams, 'id' | 'name'>[]>
3939
}
4040

4141
export const getClusterOptions = async (): Promise<ClusterType[]> => {
42-
const { result } = (await get('cluster/autocomplete')) as ResponseType<ClusterDTO[]>
42+
const { result } = (await get(ROUTES.CLUSTER_LIST_MIN)) as ResponseType<ClusterDTO[]>
4343

4444
if (!result) {
4545
return []
4646
}
4747

4848
return result
49-
.map((cluster) => ({
50-
id: cluster.id,
51-
name: cluster.cluster_name,
52-
isVirtual: cluster.isVirtualCluster ?? false,
49+
.map(({ id, cluster_name: name, isVirtualCluster }) => ({
50+
id,
51+
name,
52+
isVirtual: isVirtualCluster ?? false,
5353
}))
5454
.sort((a, b) => stringComparatorBySortOrder(a.name, b.name))
5555
}
@@ -62,13 +62,22 @@ export const getEnvironmentOptions = async (): Promise<EnvironmentType[]> => {
6262
}
6363

6464
return result
65-
.map((environment) => ({
66-
id: environment.id,
67-
name: environment.environment_name,
68-
isVirtual: environment.isVirtualEnvironment ?? false,
69-
cluster: environment.cluster_name,
70-
environmentType: environment.default ? EnvironmentTypeEnum.production : EnvironmentTypeEnum.nonProduction,
71-
namespace: environment.namespace,
72-
}))
65+
.map(
66+
({
67+
id,
68+
environment_name: name,
69+
isVirtualEnvironment,
70+
cluster_name: cluster,
71+
default: isDefault,
72+
namespace,
73+
}) => ({
74+
id,
75+
name,
76+
isVirtual: isVirtualEnvironment ?? false,
77+
cluster,
78+
environmentType: isDefault ? EnvironmentTypeEnum.production : EnvironmentTypeEnum.nonProduction,
79+
namespace,
80+
}),
81+
)
7382
.sort((a, b) => stringComparatorBySortOrder(a.name, b.name))
7483
}

0 commit comments

Comments
 (0)