Skip to content

Commit 288e782

Browse files
authored
[UI] Fix several bugs (loic-sharma#254)
1 parent 18751e5 commit 288e782

File tree

13 files changed

+102
-14
lines changed

13 files changed

+102
-14
lines changed

src/BaGet.Core.Server/Controllers/Registration/RegistrationIndexController.cs

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ private RegistrationIndexPageItem ToRegistrationIndexPageItem(Package package) =
8282
listed: package.Listed,
8383
minClientVersion: package.MinClientVersion,
8484
packageContent: Url.PackageDownload(package.Id, package.Version),
85+
packageTypes: package.PackageTypes.Select(t => t.Name).ToList(),
8586
projectUrl: package.ProjectUrlString,
8687
repositoryUrl: package.RepositoryUrlString,
8788
repositoryType: package.RepositoryType,

src/BaGet.Core.Server/Extensions/IServiceCollectionExtensions.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.AspNetCore.Mvc;
66
using Microsoft.Extensions.DependencyInjection;
77
using Microsoft.Extensions.Options;
8+
using Newtonsoft.Json;
89

910
namespace BaGet.Core.Server.Extensions
1011
{
@@ -15,7 +16,11 @@ public static IServiceCollection ConfigureHttpServices(this IServiceCollection s
1516
services
1617
.AddMvc()
1718
.AddApplicationPart(typeof(BaGet.Controllers.PackageController).Assembly)
18-
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
19+
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
20+
.AddJsonOptions(options =>
21+
{
22+
options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
23+
});
1924

2025
services.AddCors();
2126
services.AddSingleton<IConfigureOptions<CorsOptions>, ConfigureCorsOptions>();

src/BaGet.Core/Mirror/MirrorService.cs

+13
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ private Package ToPackage(PackageMetadata metadata)
122122
IconUrl = ParseUri(metadata.IconUrl),
123123
LicenseUrl = ParseUri(metadata.LicenseUrl),
124124
ProjectUrl = ParseUri(metadata.ProjectUrl),
125+
PackageTypes = ParsePackageTypes(metadata.PackageTypes),
125126
RepositoryUrl = ParseUri(metadata.RepositoryUrl),
126127
RepositoryType = metadata.RepositoryType,
127128
Tags = metadata.Tags.ToArray(),
@@ -152,6 +153,18 @@ private string[] ParseAuthors(string authors)
152153
.ToArray();
153154
}
154155

156+
private List<PackageType> ParsePackageTypes(IReadOnlyList<string> packageTypes)
157+
{
158+
if (packageTypes == null || packageTypes.Count == 0)
159+
{
160+
return new List<PackageType>();
161+
}
162+
163+
return packageTypes
164+
.Select(t => new PackageType { Name = t, Version = "0.0.0" })
165+
.ToList();
166+
}
167+
155168
private List<PackageDependency> FindDependencies(PackageMetadata package)
156169
{
157170
if ((package.DependencyGroups?.Count ?? 0) == 0)

src/BaGet.Core/Services/DatabaseSearchService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private async Task<List<IGrouping<string, Package>>> SearchImplAsync(
7676
string packageType,
7777
IReadOnlyList<string> frameworks)
7878
{
79-
IQueryable<Package> search = _context.Packages;
79+
IQueryable<Package> search = _context.Packages.Where(p => p.Listed);
8080

8181
if (!string.IsNullOrEmpty(query))
8282
{

src/BaGet.Protocol/Registration/PackageMetadata.cs

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public PackageMetadata(
2222
bool listed,
2323
string minClientVersion,
2424
string packageContent,
25+
IReadOnlyList<string> packageTypes,
2526
string projectUrl,
2627
string repositoryUrl,
2728
string repositoryType,
@@ -46,6 +47,7 @@ public PackageMetadata(
4647
Listed = listed;
4748
MinClientVersion = minClientVersion;
4849
PackageContent = packageContent;
50+
PackageTypes = packageTypes;
4951
ProjectUrl = projectUrl;
5052
RepositoryUrl = repositoryUrl;
5153
RepositoryType = repositoryType;
@@ -76,6 +78,7 @@ public PackageMetadata(
7678
public bool Listed { get; }
7779
public string MinClientVersion { get; }
7880
public string PackageContent { get; }
81+
public IReadOnlyList<string> PackageTypes { get; }
7982
public string ProjectUrl { get; }
8083
public string RepositoryUrl { get; }
8184
public string RepositoryType { get; }

src/BaGet.UI/src/DisplayPackage/DisplayPackage.css

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
margin-top: 15px;
33
}
44

5+
.display-package .package-title {
6+
word-break: break-word;
7+
overflow-wrap: break-word;
8+
}
9+
510
.display-package h1 small {
611
margin-left: 10px;
712
font-size: 45%;

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ interface IPackage {
3333
repositoryUrl: string;
3434
repositoryType: string;
3535
totalDownloads: number;
36+
isDotnetTool: boolean;
3637
downloads: number;
3738
authors: string;
3839
tags: string[];
@@ -135,10 +136,14 @@ class DisplayPackage extends React.Component<IDisplayPackageProps, IDisplayPacka
135136
readme = currentItem.catalogEntry.description;
136137
}
137138

139+
const isDotnetTool = (currentItem.catalogEntry.packageTypes &&
140+
currentItem.catalogEntry.packageTypes.indexOf("DotnetTool") !== -1);
141+
138142
this.setState({
139143
package: {
140144
...currentItem.catalogEntry,
141145
downloadUrl: currentItem.packageContent,
146+
isDotnetTool,
142147
lastUpdate,
143148
latestVersion,
144149
readme,
@@ -188,7 +193,7 @@ class DisplayPackage extends React.Component<IDisplayPackageProps, IDisplayPacka
188193

189194
</div>
190195

191-
<InstallationInfo id={this.state.package.id} version={this.state.package.version} />
196+
<InstallationInfo id={this.state.package.id} version={this.state.package.version} isDotnetTool={this.state.package.isDotnetTool} />
192197

193198
{/* TODO: Fix this */}
194199
<div dangerouslySetInnerHTML={{ __html: this.state.package.readme }} />
@@ -215,7 +220,7 @@ class DisplayPackage extends React.Component<IDisplayPackageProps, IDisplayPacka
215220
<LicenseInfo url={this.state.package.licenseUrl} />
216221
<li>
217222
<Icon iconName="CloudDownload" className="ms-Icon" />
218-
<a href={this.state.package.downloadUrl}>Download Package</a>
223+
<a href={this.state.package.downloadUrl}>Download package</a>
219224
</li>
220225
</ul>
221226
</div>

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

+54-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import './InstallationInfo.css';
77
interface IInstallationInfoProps {
88
id: string;
99
version: string;
10+
isDotnetTool: boolean;
1011
}
1112

1213
interface IInstallationInfoState {
@@ -16,7 +17,9 @@ interface IInstallationInfoState {
1617
}
1718

1819
enum Tab {
19-
DotNet,
20+
Dotnet,
21+
DotnetTool,
22+
PackageReference,
2023
Paket,
2124
PackageManager,
2225
}
@@ -26,16 +29,43 @@ class InstallationInfo extends React.Component<IInstallationInfoProps, IInstalla
2629
constructor(props: IInstallationInfoProps) {
2730
super(props);
2831

29-
this.state = this.buildState(Tab.DotNet);
32+
// tslint:disable-next-line:no-console
33+
console.log(props);
34+
this.state = props.isDotnetTool
35+
? this.buildState(Tab.DotnetTool)
36+
: this.buildState(Tab.Dotnet);
3037
}
3138

3239
public render() {
3340
return (
3441
<div className="installation-info">
3542
<ul className="nav">
36-
<InstallationInfoTab type={Tab.DotNet} selected={this.state.selected} onSelect={this.handleSelect} />
37-
<InstallationInfoTab type={Tab.Paket} selected={this.state.selected} onSelect={this.handleSelect} />
38-
<InstallationInfoTab type={Tab.PackageManager} selected={this.state.selected} onSelect={this.handleSelect} />
43+
<InstallationInfoTab
44+
type={Tab.Dotnet}
45+
hidden={this.props.isDotnetTool}
46+
selected={this.state.selected}
47+
onSelect={this.handleSelect} />
48+
<InstallationInfoTab
49+
type={Tab.PackageReference}
50+
hidden={this.props.isDotnetTool}
51+
selected={this.state.selected}
52+
onSelect={this.handleSelect} />
53+
<InstallationInfoTab
54+
type={Tab.Paket}
55+
hidden={this.props.isDotnetTool}
56+
selected={this.state.selected}
57+
onSelect={this.handleSelect} />
58+
<InstallationInfoTab
59+
type={Tab.PackageManager}
60+
hidden={this.props.isDotnetTool}
61+
selected={this.state.selected}
62+
onSelect={this.handleSelect} />
63+
64+
<InstallationInfoTab
65+
type={Tab.DotnetTool}
66+
hidden={!this.props.isDotnetTool}
67+
selected={this.state.selected}
68+
onSelect={this.handleSelect} />
3969
</ul>
4070

4171
<div className="content">
@@ -62,11 +92,21 @@ class InstallationInfo extends React.Component<IInstallationInfoProps, IInstalla
6292
let prefix: string;
6393

6494
switch (tab) {
65-
case Tab.DotNet:
95+
case Tab.Dotnet:
6696
content = `dotnet add package ${this.props.id} --version ${this.props.version}`;
6797
prefix = ">";
6898
break;
6999

100+
case Tab.DotnetTool:
101+
content = `dotnet tool install --global ${this.props.id} --version ${this.props.version}`;
102+
prefix = ">";
103+
break;
104+
105+
case Tab.PackageReference:
106+
content = `<PackageReference Include="${this.props.id}" Version="${this.props.version}" />`;
107+
prefix = "";
108+
break;
109+
70110
case Tab.Paket:
71111
content = `paket add ${this.props.id} --version ${this.props.version}`;
72112
prefix = ">";
@@ -89,6 +129,7 @@ class InstallationInfo extends React.Component<IInstallationInfoProps, IInstalla
89129

90130
interface IInstallationInfoTabProps {
91131
type: Tab;
132+
hidden: boolean;
92133
selected: Tab;
93134
onSelect(value: Tab): void;
94135
}
@@ -102,13 +143,19 @@ class InstallationInfoTab extends React.Component<IInstallationInfoTabProps> {
102143
super(props);
103144

104145
switch (props.type) {
105-
case Tab.DotNet: this.title = ".NET CLI"; break;
146+
case Tab.Dotnet: this.title = ".NET CLI"; break;
147+
case Tab.DotnetTool: this.title = ".NET CLI"; break;
148+
case Tab.PackageReference: this.title = "PackageReference"; break;
106149
case Tab.Paket: this.title = "Paket CLI"; break;
107150
case Tab.PackageManager: this.title = "Package Manager"; break;
108151
}
109152
}
110153

111154
public render() {
155+
if (this.props.hidden) {
156+
return null;
157+
}
158+
112159
if (this.props.type === this.props.selected) {
113160
return <li className="active"><a href="#">{this.title}</a></li>
114161
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class LicenseInfo extends React.Component<ILicenseInfoProps> {
1919
return (
2020
<li>
2121
<Icon iconName="Certificate" className="ms-Icon" />
22-
<a href={this.props.url}>License Info</a>
22+
<a href={this.props.url}>License</a>
2323
</li>
2424
);
2525
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface ICatalogEntry {
2525
iconUrl: string;
2626
projectUrl: string;
2727
licenseUrl: string;
28+
packageTypes: string[];
2829
repositoryUrl: string;
2930
repositoryType: string;
3031
authors: string;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class SourceRepository extends React.Component<ISourceRepositoryProps> {
2121
return (
2222
<li>
2323
<img className="icon" aria-hidden="true" alt="GitHub logo" src="https://www.nuget.org/Content/gallery/img/github-32x32.png" />
24-
<a href={this.props.url}>Source Code</a>
24+
<a href={this.props.url}>Source code</a>
2525
</li>
2626
);
2727
}

src/BaGet.UI/src/SearchResults.css

+8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
margin-left: -5px;
4242
line-height: 20px;
4343
color: #666;
44+
overflow: hidden;
45+
text-overflow: ellipsis;
4446
white-space: nowrap;
4547
}
4648

@@ -65,3 +67,9 @@
6567
top: 2px;
6668
margin-right: 2px;
6769
}
70+
71+
.search-result .tags {
72+
overflow: hidden;
73+
text-overflow: ellipsis;
74+
white-space: nowrap;
75+
}

src/BaGet.UI/src/SearchResults.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class SearchResults extends React.Component<ISearchResultsProps, ISearchResultsS
178178
</span>
179179
</li>
180180
<li>
181-
<span>
181+
<span className="tags">
182182
<Icon iconName="Tag" className="ms-Icon" />
183183
{value.tags.join(' ')}
184184
</span>

0 commit comments

Comments
 (0)