Skip to content

Commit afb2827

Browse files
authored
Show greatest listed package (loic-sharma#413)
1 parent a6d4b47 commit afb2827

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

src/BaGet.UI/package-lock.json

+28-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BaGet.UI/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"react-markdown": "^4.2.2",
2020
"react-router-dom": "^4.3.1",
2121
"react-scripts": "^3.1.2",
22+
"semver": "^6.2.0",
2223
"timeago.js": "^3.0.2"
2324
},
2425
"scripts": {
@@ -34,6 +35,7 @@
3435
"@types/react": "^16.9.3",
3536
"@types/react-dom": "^16.9.1",
3637
"@types/react-router-dom": "^4.3.1",
38+
"@types/semver": "^6.2.0",
3739
"typescript": "^3.6.3"
3840
},
3941
"browserslist": {

src/BaGet.UI/src/DisplayPackage/DisplayPackage.tsx

+16-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Icon } from 'office-ui-fabric-react/lib/Icon';
22
import * as React from 'react';
33
import ReactMarkdown from 'react-markdown';
44
import timeago from 'timeago.js';
5+
import { gt } from 'semver';
56

67
import { config } from '../config';
78
import Dependencies from './Dependencies';
@@ -116,10 +117,10 @@ class DisplayPackage extends React.Component<IDisplayPackageProps, IDisplayPacka
116117

117118
const results = json as Registration.IRegistrationIndex;
118119

119-
const latestVersion = results.items[0].upper;
120120
let currentItem: Registration.IRegistrationPageItem | undefined;
121121
let lastUpdate: Date | undefined;
122122

123+
const latestVersion = this.latestVersion(results);
123124
const versions: IPackageVersion[] = [];
124125

125126
for (const entry of results.items[0].items) {
@@ -147,7 +148,7 @@ class DisplayPackage extends React.Component<IDisplayPackageProps, IDisplayPacka
147148
}
148149
}
149150

150-
if (currentItem && lastUpdate) {
151+
if (latestVersion && currentItem && lastUpdate) {
151152
let readme = "";
152153

153154
const isDotnetTool = (currentItem.catalogEntry.packageTypes &&
@@ -315,6 +316,19 @@ class DisplayPackage extends React.Component<IDisplayPackageProps, IDisplayPacka
315316
? version
316317
: version.substring(0, buildMetadataStart);
317318
}
319+
320+
private latestVersion(index: Registration.IRegistrationIndex): string | null {
321+
let latestVersion: string | null = null;
322+
for (const entry of index.items[0].items) {
323+
if (!entry.catalogEntry.listed) continue;
324+
325+
if (latestVersion === null || gt(entry.catalogEntry.version, latestVersion)) {
326+
latestVersion = entry.catalogEntry.version;
327+
}
328+
}
329+
330+
return latestVersion;
331+
}
318332
}
319333

320334
interface IExpandableSectionProps {

0 commit comments

Comments
 (0)