Skip to content

Commit b505672

Browse files
committed
feat: add sorting in useGetResourceKindsOptions
1 parent a89397a commit b505672

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
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": "0.1.11-beta-4",
3+
"version": "0.1.11-beta-5",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Shared/Hooks/useGetResourceKindsOptions/service.ts

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,70 @@ import { ClusterType } from '@Shared/Services'
55
import { EnvironmentType, EnvListMinDTO } from '@Shared/types'
66
import { EnvironmentTypeEnum } from '@Shared/constants'
77
import { ROUTES } from '@Common/Constants'
8+
import { stringComparatorBySortOrder } from '@Shared/Helpers'
89
import { AppsGroupedByProjectsType, ClusterDTO } from './types'
910

1011
export const getAppOptionsGroupedByProjects = async (): Promise<AppsGroupedByProjectsType> => {
1112
const { result } = (await get('app/min')) as ResponseType<AppsGroupedByProjectsType>
1213

13-
return result ?? []
14+
if (!result) {
15+
return []
16+
}
17+
18+
return result
19+
.map((project) => ({
20+
...project,
21+
appList: project.appList.sort((a, b) => stringComparatorBySortOrder(a.name, b.name)),
22+
}))
23+
.sort((a, b) => stringComparatorBySortOrder(a.projectName, b.projectName))
1424
}
1525

1626
export const getProjectOptions = async (): Promise<Pick<Teams, 'id' | 'name'>[]> => {
1727
const { result } = await getTeamListMin()
1828

19-
return (
20-
result?.map(({ id, name }) => ({
29+
if (!result) {
30+
return []
31+
}
32+
33+
return result
34+
.map(({ id, name }) => ({
2135
id,
2236
name,
23-
})) ?? []
24-
)
37+
}))
38+
.sort((a, b) => stringComparatorBySortOrder(a.name, b.name))
2539
}
2640

2741
export const getClusterOptions = async (): Promise<ClusterType[]> => {
2842
const { result } = (await get('cluster/autocomplete')) as ResponseType<ClusterDTO[]>
2943

30-
return (
31-
result?.map((cluster) => ({
44+
if (!result) {
45+
return []
46+
}
47+
48+
return result
49+
.map((cluster) => ({
3250
id: cluster.id,
3351
name: cluster.cluster_name,
3452
isVirtual: cluster.isVirtualCluster ?? false,
35-
})) ?? []
36-
)
53+
}))
54+
.sort((a, b) => stringComparatorBySortOrder(a.name, b.name))
3755
}
3856

3957
export const getEnvironmentOptions = async (): Promise<EnvironmentType[]> => {
4058
const { result } = (await get(ROUTES.ENVIRONMENT_LIST_MIN)) as ResponseType<EnvListMinDTO[]>
4159

42-
return (
43-
result?.map((environment) => ({
60+
if (!result) {
61+
return []
62+
}
63+
64+
return result
65+
.map((environment) => ({
4466
id: environment.id,
4567
name: environment.environment_name,
4668
isVirtual: environment.isVirtualEnvironment ?? false,
4769
cluster: environment.cluster_name,
4870
environmentType: environment.default ? EnvironmentTypeEnum.production : EnvironmentTypeEnum.nonProduction,
4971
namespace: environment.namespace,
50-
})) ?? []
51-
)
72+
}))
73+
.sort((a, b) => stringComparatorBySortOrder(a.name, b.name))
5274
}

0 commit comments

Comments
 (0)