@@ -5,48 +5,70 @@ import { ClusterType } from '@Shared/Services'
5
5
import { EnvironmentType , EnvListMinDTO } from '@Shared/types'
6
6
import { EnvironmentTypeEnum } from '@Shared/constants'
7
7
import { ROUTES } from '@Common/Constants'
8
+ import { stringComparatorBySortOrder } from '@Shared/Helpers'
8
9
import { AppsGroupedByProjectsType , ClusterDTO } from './types'
9
10
10
11
export const getAppOptionsGroupedByProjects = async ( ) : Promise < AppsGroupedByProjectsType > => {
11
12
const { result } = ( await get ( 'app/min' ) ) as ResponseType < AppsGroupedByProjectsType >
12
13
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 ) )
14
24
}
15
25
16
26
export const getProjectOptions = async ( ) : Promise < Pick < Teams , 'id' | 'name' > [ ] > => {
17
27
const { result } = await getTeamListMin ( )
18
28
19
- return (
20
- result ?. map ( ( { id, name } ) => ( {
29
+ if ( ! result ) {
30
+ return [ ]
31
+ }
32
+
33
+ return result
34
+ . map ( ( { id, name } ) => ( {
21
35
id,
22
36
name,
23
- } ) ) ?? [ ]
24
- )
37
+ } ) )
38
+ . sort ( ( a , b ) => stringComparatorBySortOrder ( a . name , b . name ) )
25
39
}
26
40
27
41
export const getClusterOptions = async ( ) : Promise < ClusterType [ ] > => {
28
42
const { result } = ( await get ( 'cluster/autocomplete' ) ) as ResponseType < ClusterDTO [ ] >
29
43
30
- return (
31
- result ?. map ( ( cluster ) => ( {
44
+ if ( ! result ) {
45
+ return [ ]
46
+ }
47
+
48
+ return result
49
+ . map ( ( cluster ) => ( {
32
50
id : cluster . id ,
33
51
name : cluster . cluster_name ,
34
52
isVirtual : cluster . isVirtualCluster ?? false ,
35
- } ) ) ?? [ ]
36
- )
53
+ } ) )
54
+ . sort ( ( a , b ) => stringComparatorBySortOrder ( a . name , b . name ) )
37
55
}
38
56
39
57
export const getEnvironmentOptions = async ( ) : Promise < EnvironmentType [ ] > => {
40
58
const { result } = ( await get ( ROUTES . ENVIRONMENT_LIST_MIN ) ) as ResponseType < EnvListMinDTO [ ] >
41
59
42
- return (
43
- result ?. map ( ( environment ) => ( {
60
+ if ( ! result ) {
61
+ return [ ]
62
+ }
63
+
64
+ return result
65
+ . map ( ( environment ) => ( {
44
66
id : environment . id ,
45
67
name : environment . environment_name ,
46
68
isVirtual : environment . isVirtualEnvironment ?? false ,
47
69
cluster : environment . cluster_name ,
48
70
environmentType : environment . default ? EnvironmentTypeEnum . production : EnvironmentTypeEnum . nonProduction ,
49
71
namespace : environment . namespace ,
50
- } ) ) ?? [ ]
51
- )
72
+ } ) )
73
+ . sort ( ( a , b ) => stringComparatorBySortOrder ( a . name , b . name ) )
52
74
}
0 commit comments