komodorio/helm-dashboard

Version to install options should be sorted semantically

martinwang2002 opened this issue · 8 comments

Description

Version to install options should be sorted semantically. It does not make sense for argocd @ 5.2.0 to come before argocd @ 5.19.

Screenshots

image

Additional information

vers.sort((b, a) => (a.version > b.version) - (a.version < b.version))

I don't think this line is necessary in terms of the api response for /api/helm/repositories/versions?name= as it's already sorted semantically.

There is no guarantee that backend will provide the desired sorting. I believe the frontend should sort the list properly.
If anyone can fix that - contribution is welcome.

import re

def semver_sort(versions):
def split_version(v):
match = re.match(r'^(\d+).(\d+).(\d+)$', v)
if match:
return (int(match.group(1)), int(match.group(2)), int(match.group(3)))
else:
return None

def semver_key(v):
    version_parts = split_version(v)
    if version_parts:
        return (version_parts[0], version_parts[1], version_parts[2])
    else:
        return (0, 0, 0)

return sorted(versions, key=semver_key)

Example usage

versions = ['5.2.0', '5.1.0', '5.19.0', '5.3.0', '5.18.0', '6.0.0']
sorted_versions = semver_sort(versions)
print(sorted_versions)

That code is for backend, while I talk about frontend ensuring the sorting.

@harshit-mehtaa This change actually broke it.
I now get whenever I try to click "reconfigure" button...

actions.js:94 Uncaught TypeError: a.split is not a function
    at actions.js:94:37
    at Array.map (<anonymous>)
    at Object.<anonymous> (actions.js:94:25)
    at c (jquery-3.6.0.min.js:2:28327)
    at Object.fireWith [as resolveWith] (jquery-3.6.0.min.js:2:29072)
    at l (jquery-3.6.0.min.js:2:79901)
    at XMLHttpRequest.<anonymous> (jquery-3.6.0.min.js:2:82355)

Weird, I had tested it locally. Unfortunately missed to attach the screen shot in the PR
For the interim, can we revert the commit and merge it?

Can we fix it instead? Make sure the parsing do not fail.

I tried to find a few solutions but none of them are working
I need some help with this

I have tried this

image