Skip to content

Commit 4a63983

Browse files
authored
fix: Order versioned docs select items by recency (#14768)
## DESCRIBE YOUR PR This PR makes a change to the order in which we show the version select items if a docs page has multiple versions: Instead of sorting the version designator alphabetically, this PR attempts to sort them by recent to oldest. For now, this only looks at the major number, since the version designator can be arbitrary and we can't assume proper semver (see example).If we can't extract a proper major version, we continue to sort alphabetically. Before: <img width="287" height="237" alt="image" src="https://github.com/user-attachments/assets/d0e39874-3548-4b82-b940-9b4ebdad9a44" /> After: <img width="291" height="240" alt="image" src="https://github.com/user-attachments/assets/e4f005ad-0f97-4107-8f0c-982f81c8af0e" /> (the 10x version in this screenshot serves an illustrative purpose. I'm not shipping that anytime soon :D) (This PR is brought to you by a sidequest while working on updating sveltekit docs and encountering weird ordering. Happy to close/adjust as reviewers see fit :) ) ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: Some time week ending Sept 5th - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [x] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs)
1 parent 6193409 commit 4a63983

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/components/versionSelector/index.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,31 @@ import styles from './style.module.scss';
1111

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

14+
function sortVersions(versions: string[]) {
15+
return versions.sort((a, b) => {
16+
const aMajor = parseInt(a.split('.')[0], 10);
17+
const bMajor = parseInt(b.split('.')[0], 10);
18+
19+
if (isNaN(aMajor) || isNaN(bMajor)) {
20+
return a.localeCompare(b);
21+
}
22+
23+
if (aMajor < bMajor) {
24+
return 1;
25+
}
26+
27+
if (aMajor === bMajor) {
28+
// yes, this is flawed. But for now there's no case where we need to order
29+
// by minor or patch so I wanna avoid pulling in semver as a dependency
30+
return a.localeCompare(b);
31+
}
32+
33+
return -1;
34+
});
35+
}
36+
1437
export function VersionSelector({versions, sdk}: {sdk: string; versions: string[]}) {
15-
const availableVersions = ['latest', ...versions];
38+
const availableVersions = ['latest', ...sortVersions([...versions])];
1639
const router = useRouter();
1740
const pathname = usePathname();
1841

0 commit comments

Comments
 (0)