Skip to content

Commit 96f740b

Browse files
committed
chore: rename versionComparator in helpers
1 parent c253958 commit 96f740b

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/Pages/GlobalConfigurations/DeploymentCharts/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { versionComparator } from '@Shared/Helpers'
1+
import { versionComparatorBySortOrder } from '@Shared/Helpers'
22
import { SortingOrder } from '@Common/Constants'
33
import { DeploymentChartListDTO, DeploymentChartType, DEVTRON_DEPLOYMENT_CHART_NAMES } from './types'
44
import fallbackGuiSchema from './basicViewSchema.json'
@@ -29,7 +29,7 @@ export const convertDeploymentChartListToChartType = (data: DeploymentChartListD
2929
{},
3030
)
3131
const result = Object.values(chartMap).map((element) => {
32-
element.versions?.sort((a, b) => versionComparator(a, b, 'version', SortingOrder.DESC))
32+
element.versions?.sort((a, b) => versionComparatorBySortOrder(a, b, 'version', SortingOrder.DESC))
3333
return element
3434
})
3535
return result

src/Shared/Helpers.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@ export const numberComparatorBySortOrder = (
135135
sortOrder: SortingOrder = SortingOrder.ASC,
136136
): number => (sortOrder === SortingOrder.ASC ? a - b : b - a)
137137

138+
export function versionComparatorBySortOrder(
139+
a: Record<string, any>,
140+
b: Record<string, any>,
141+
compareKey: string,
142+
orderBy: SortingOrder,
143+
) {
144+
if (orderBy === SortingOrder.DESC) {
145+
return b[compareKey].localeCompare(a[compareKey], undefined, { numeric: true })
146+
}
147+
148+
return a[compareKey].localeCompare(b[compareKey], undefined, { numeric: true })
149+
}
150+
138151
export const getWebhookEventIcon = (eventName: WebhookEventNameType) => {
139152
switch (eventName) {
140153
case WebhookEventNameType.PULL_REQUEST:
@@ -747,16 +760,3 @@ export const getFileNameFromHeaders = (headers: Headers) =>
747760
?.find((n) => n.includes('filename='))
748761
?.replace('filename=', '')
749762
.trim()
750-
751-
export function versionComparator(
752-
a: Record<string, any>,
753-
b: Record<string, any>,
754-
compareKey: string,
755-
orderBy: SortingOrder,
756-
) {
757-
if (orderBy === SortingOrder.DESC) {
758-
return b[compareKey].localeCompare(a[compareKey], undefined, { numeric: true })
759-
}
760-
761-
return a[compareKey].localeCompare(b[compareKey], undefined, { numeric: true })
762-
}

0 commit comments

Comments
 (0)