@@ -29,6 +29,7 @@ import {
29
29
UserApprovalConfigType ,
30
30
PATTERNS ,
31
31
ZERO_TIME_STRING ,
32
+ noop ,
32
33
} from '../Common'
33
34
import {
34
35
AggregationKeys ,
@@ -138,17 +139,12 @@ export const numberComparatorBySortOrder = (
138
139
sortOrder : SortingOrder = SortingOrder . ASC ,
139
140
) : number => ( sortOrder === SortingOrder . ASC ? a - b : b - a )
140
141
141
- export function versionComparatorBySortOrder (
142
- a : Record < string , any > ,
143
- b : Record < string , any > ,
144
- compareKey : string ,
145
- orderBy : SortingOrder ,
146
- ) {
142
+ export function versionComparatorBySortOrder ( a : string , b : string , orderBy = SortingOrder . ASC ) {
147
143
if ( orderBy === SortingOrder . DESC ) {
148
- return b [ compareKey ] . localeCompare ( a [ compareKey ] , undefined , { numeric : true } )
144
+ return a . localeCompare ( b , undefined , { numeric : true } )
149
145
}
150
146
151
- return a [ compareKey ] . localeCompare ( b [ compareKey ] , undefined , { numeric : true } )
147
+ return b . localeCompare ( a , undefined , { numeric : true } )
152
148
}
153
149
154
150
export const getWebhookEventIcon = ( eventName : WebhookEventNameType ) => {
@@ -807,3 +803,21 @@ export const getIsManualApprovalSpecific = (userApprovalConfig?: Pick<UserApprov
807
803
export const getHandleOpenURL = ( url : string ) => ( ) => {
808
804
window . open ( url , '_blank' , 'noreferrer' )
809
805
}
806
+
807
+ export const getDefaultValueFromType = ( value : unknown ) => {
808
+ switch ( typeof value ) {
809
+ case 'number' :
810
+ return 0
811
+ case 'string' :
812
+ return ''
813
+ case 'object' :
814
+ if ( value === null ) {
815
+ return null
816
+ }
817
+ return Array . isArray ( value ) ? [ ] : { }
818
+ case 'function' :
819
+ return noop
820
+ default :
821
+ return null
822
+ }
823
+ }
0 commit comments