Skip to content

Commit b447d1b

Browse files
committed
fix: version comparator by sort order
1 parent 56c1035 commit b447d1b

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/Pages/GlobalConfigurations/DeploymentCharts/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { versionComparatorBySortOrder } from '@Shared/Helpers'
2-
import { SortingOrder } from '@Common/Constants'
32
import { DeploymentChartListDTO, DeploymentChartType, DEVTRON_DEPLOYMENT_CHART_NAMES } from './types'
43
import fallbackGuiSchema from './basicViewSchema.json'
54

@@ -31,7 +30,7 @@ export const convertDeploymentChartListToChartType = (data: DeploymentChartListD
3130
{} as Record<string, DeploymentChartType>,
3231
)
3332
const result = Object.values(chartMap).map((element) => {
34-
element.versions.sort((a, b) => versionComparatorBySortOrder(a, b, 'version', SortingOrder.DESC))
33+
element.versions.sort((a, b) => versionComparatorBySortOrder(a.version, b.version))
3534
return element
3635
})
3736
return result

src/Shared/Helpers.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
UserApprovalConfigType,
3030
PATTERNS,
3131
ZERO_TIME_STRING,
32+
noop,
3233
} from '../Common'
3334
import {
3435
AggregationKeys,
@@ -138,17 +139,12 @@ export const numberComparatorBySortOrder = (
138139
sortOrder: SortingOrder = SortingOrder.ASC,
139140
): number => (sortOrder === SortingOrder.ASC ? a - b : b - a)
140141

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) {
147143
if (orderBy === SortingOrder.DESC) {
148-
return b[compareKey].localeCompare(a[compareKey], undefined, { numeric: true })
144+
return a.localeCompare(b, undefined, { numeric: true })
149145
}
150146

151-
return a[compareKey].localeCompare(b[compareKey], undefined, { numeric: true })
147+
return b.localeCompare(a, undefined, { numeric: true })
152148
}
153149

154150
export const getWebhookEventIcon = (eventName: WebhookEventNameType) => {
@@ -807,3 +803,21 @@ export const getIsManualApprovalSpecific = (userApprovalConfig?: Pick<UserApprov
807803
export const getHandleOpenURL = (url: string) => () => {
808804
window.open(url, '_blank', 'noreferrer')
809805
}
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

Comments
 (0)