Skip to content

Commit

Permalink
[UI] Improve version display (#387)
Browse files Browse the repository at this point in the history
Addresses #386
Addresses #384
Addresses #385
  • Loading branch information
loic-sharma authored Oct 16, 2019
1 parent be8caa6 commit c4546e0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
10 changes: 6 additions & 4 deletions src/BaGet.UI/src/DisplayPackage/Dependencies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ interface IPackageDependenciesProps {

class Dependencies extends React.Component<IDependenciesProps> {

static readonly netFrameworkRegex : RegExp = /net[0-9]{2,3}$/;
static readonly netCoreRegex : RegExp = /netcoreapp[0-9].[0-9]$/;
static readonly netStandardRegex : RegExp = /netstandard[0-9].[0-9]$/;
static readonly versionRangeRegex : RegExp = /\[[0-9](.[0-9])*, \)$/;
static readonly netFrameworkRegex = /^net[0-9]{2,3}$/;
static readonly netCoreRegex = /^netcoreapp[0-9].[0-9]$/;
static readonly netStandardRegex = /^netstandard[0-9].[0-9]$/;
static readonly semVerRegex = '(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?';

static readonly versionRangeRegex : RegExp = new RegExp(`^\\[${Dependencies.semVerRegex}, \\)$`);

constructor(props: IDependenciesProps) {
super(props);
Expand Down
8 changes: 6 additions & 2 deletions src/BaGet.UI/src/DisplayPackage/DisplayPackage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,18 @@ class DisplayPackage extends React.Component<IDisplayPackageProps, IDisplayPacka
if (!entry.catalogEntry.listed) continue;

const normalizedVersion = this.normalizeVersion(entry.catalogEntry.version);
const isCurrent = !!this.version
? normalizedVersion === this.version
: normalizedVersion === latestVersion;

versions.push({
date: new Date(entry.catalogEntry.published),
downloads: entry.catalogEntry.downloads,
version: normalizedVersion,
selected: isCurrent,
});

if ((!currentItem && normalizedVersion === latestVersion) ||
(this.version && normalizedVersion === this.version)) {
if (isCurrent) {
currentItem = entry;
}

Expand Down
9 changes: 7 additions & 2 deletions src/BaGet.UI/src/DisplayPackage/Versions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface IPackageVersion {
version: string;
downloads: number;
date: Date;
selected: boolean;
}

interface IVersionsProps {
Expand Down Expand Up @@ -59,8 +60,12 @@ export class Versions extends React.Component<IVersionsProps, IVersionsState> {
}

private renderVersion = (packageVersion: IPackageVersion) => {
const className = packageVersion.selected
? "bg-info"
: "";

return (
<tr key={packageVersion.version}>
<tr key={packageVersion.version} className={className}>
<td><Link to={`/packages/${this.props.packageId}/${packageVersion.version}`}>{packageVersion.version}</Link></td>
<td>{packageVersion.downloads}</td>
<td>{this.dateToString(packageVersion.date)}</td>
Expand All @@ -69,7 +74,7 @@ export class Versions extends React.Component<IVersionsProps, IVersionsState> {
}

private renderShowAllOrLessButton = () => {
if (this.props.versions.length < Versions.defaultVisible) {
if (this.props.versions.length <= Versions.defaultVisible) {
return null;
}

Expand Down
14 changes: 8 additions & 6 deletions src/BaGet.UI/src/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,14 @@ class SearchResults extends React.Component<ISearchResultsProps, ISearchResultsS
Latest version: {value.version}
</span>
</li>
<li>
<span className="tags">
<Icon iconName="Tag" className="ms-Icon" />
{value.tags.join(' ')}
</span>
</li>
{value.tags.length > 0 &&
<li>
<span className="tags">
<Icon iconName="Tag" className="ms-Icon" />
{value.tags.join(' ')}
</span>
</li>
}
</ul>
<div>
{value.description}
Expand Down

0 comments on commit c4546e0

Please sign in to comment.