Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/components/versionSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,31 @@ import styles from './style.module.scss';

import {VersionBanner} from '../versionBanner';

function sortVersions(versions: string[]) {
return versions.sort((a, b) => {
const aMajor = parseInt(a.split('.')[0], 10);
const bMajor = parseInt(b.split('.')[0], 10);

if (isNaN(aMajor) || isNaN(bMajor)) {
return a.localeCompare(b);
}

if (aMajor < bMajor) {
return 1;
}

if (aMajor === bMajor) {
// yes, this is flawed. But for now there's no case where we need to order
// by minor or patch so I wanna avoid pulling in semver as a dependency
return a.localeCompare(b);
}

return -1;
});
}

export function VersionSelector({versions, sdk}: {sdk: string; versions: string[]}) {
const availableVersions = ['latest', ...versions];
const availableVersions = ['latest', ...sortVersions([...versions])];
const router = useRouter();
const pathname = usePathname();

Expand Down
Loading