@@ -84,6 +84,41 @@ const ResultList = ({
84
84
}
85
85
}
86
86
87
+ const sortArrayByTeamAndName = ( array : any [ ] , owner : string , nameKey : string ) => {
88
+ if ( array ) {
89
+ array . sort ( ( a , b ) => {
90
+ // If owner is defined for both a and b
91
+ if ( a [ owner ] && b [ owner ] ) {
92
+ let comparison = a [ owner ] . toLowerCase ( ) . localeCompare ( b [ owner ] . toLowerCase ( ) ) ;
93
+ // If owner is not the same, sort by owner
94
+ if ( comparison !== 0 ) return comparison ;
95
+ } else if ( a [ owner ] ) {
96
+ // If owner is defined for a but not for b, a comes first
97
+ return - 1 ;
98
+ } else if ( b [ owner ] ) {
99
+ // If owner is defined for b but not for a, b comes first
100
+ return 1 ;
101
+ } else {
102
+ // If both a and b are undefined, they are equal in terms of sorting
103
+ return 0 ;
104
+ }
105
+ // If owner is the same or both are undefined, sort by name
106
+ if ( a [ nameKey ] && b [ nameKey ] ) {
107
+ return a [ nameKey ] . toLowerCase ( ) . localeCompare ( b [ nameKey ] . toLowerCase ( ) ) ;
108
+ } else if ( a [ nameKey ] ) {
109
+ // If name is defined for a but not for b, a comes first
110
+ return - 1 ;
111
+ } else if ( b [ nameKey ] ) {
112
+ // If name is defined for b but not for a, b comes first
113
+ return 1 ;
114
+ } else {
115
+ // If both a and b are undefined, they are equal in terms of sorting
116
+ return 0 ;
117
+ }
118
+ } ) ;
119
+ }
120
+ }
121
+
87
122
if ( search && ! ! searchParam ) {
88
123
var { data, loading, error } = search
89
124
@@ -96,21 +131,6 @@ const ResultList = ({
96
131
( d ) => ! isDataProduct ( d . result )
97
132
)
98
133
99
- const sortByTeamAndName = ( a : any , b : any ) => {
100
- if ( a . teamkatalogenURL && b . teamkatalogenURL ) {
101
- let comparison = a . teamkatalogenURL . localeCompare ( b . teamkatalogenURL ) ;
102
- if ( comparison !== 0 ) return comparison ;
103
- } else if ( a . teamkatalogenURL ) {
104
- return - 1 ; // a comes first if b is undefined
105
- } else if ( b . teamkatalogenURL ) {
106
- return 1 ; // b comes first if a is undefined
107
- }
108
- // If teamkatalogenURL is the same or both are undefined, sort by name
109
- return a . name . localeCompare ( b . name ) ;
110
- }
111
- if ( dataproducts ) { dataproducts . sort ( sortByTeamAndName ) }
112
- if ( stories ) { stories . sort ( sortByTeamAndName ) }
113
- if ( insightProducts ) { insightProducts . sort ( sortByTeamAndName ) }
114
134
115
135
return (
116
136
< Results >
@@ -178,6 +198,7 @@ const ResultList = ({
178
198
)
179
199
}
180
200
if ( dataproducts ) {
201
+ sortArrayByTeamAndName ( dataproducts , 'owner.group' , 'name' )
181
202
return (
182
203
< Results >
183
204
{ dataproducts . map ( ( d , idx ) => (
@@ -195,6 +216,7 @@ const ResultList = ({
195
216
}
196
217
197
218
if ( stories ) {
219
+ sortArrayByTeamAndName ( stories , 'group' , 'name' )
198
220
return (
199
221
< div >
200
222
< Results >
@@ -222,6 +244,7 @@ const ResultList = ({
222
244
}
223
245
224
246
if ( insightProducts ) {
247
+ sortArrayByTeamAndName ( insightProducts , 'group' , 'name' )
225
248
return (
226
249
< div >
227
250
< Results >
0 commit comments