Skip to content

Commit

Permalink
Use only server-side documentation links on versions page. (dart-lang…
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Nov 1, 2023
1 parent 13164bf commit 3fd71ce
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 124 deletions.
2 changes: 2 additions & 0 deletions app/lib/frontend/handlers/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ Future<shelf.Response> packageVersionsListHandler(
}

final dartSdkVersion = await getDartSdkVersion();
final taskStatus = await taskBackend.packageStatus(packageName);
return renderPkgVersionsPage(
data,
// output is expected in descending versions order
versions.descendingVersions,
dartSdkVersion: dartSdkVersion.semanticVersion,
taskStatus: taskStatus,
);
},
cacheEntry: cache.uiPackageVersions(packageName),
Expand Down
2 changes: 2 additions & 0 deletions app/lib/frontend/templates/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ Tab _scoreTab(PackagePageData data) {
id: 'analysis',
title: 'Scores',
contentNode: scoreTabNode(
package: data.package.name!,
version: data.version.version!,
card: data.scoreCard,
likeCount: data.package.likes,
usesFlutter: data.version.pubspec!.usesFlutter,
Expand Down
10 changes: 9 additions & 1 deletion app/lib/frontend/templates/package_versions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:pub_semver/pub_semver.dart';
import '../../package/model_properties.dart';
import '../../package/models.dart';
import '../../shared/urls.dart' as urls;
import '../../task/models.dart';
import '../dom/dom.dart' as d;

import 'detail_page.dart';
Expand All @@ -22,6 +23,7 @@ String renderPkgVersionsPage(
PackagePageData data,
List<VersionInfo> versions, {
required Version dartSdkVersion,
required PackageStateInfo taskStatus,
}) {
final previewVersionRows = <d.Node>[];
final stableVersionRows = <d.Node>[];
Expand All @@ -35,7 +37,13 @@ String renderPkgVersionsPage(
for (int i = 0; i < versions.length; i++) {
final version = versions[i];
final pubspec = Pubspec.fromJson(version.pubspec);
final rowNode = versionRowNode(pubspec.name, version, pubspec);
final versionStatus = taskStatus.versions[version.version];
final rowNode = versionRowNode(
pubspec.name,
version,
pubspec,
versionStatus: versionStatus,
);
final semanticVersion = Version.parse(version.version);
if (version.retracted != null && version.retracted!) {
retractedVersionRows.add(rowNode);
Expand Down
8 changes: 7 additions & 1 deletion app/lib/frontend/templates/views/pkg/score_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import '../../package_misc.dart' show formatScore;

/// Renders the score page content.
d.Node scoreTabNode({
required String package,
required String version,
required int? likeCount,
required ScoreCardData? card,
required bool usesFlutter,
Expand Down Expand Up @@ -74,7 +76,11 @@ d.Node scoreTabNode({
classes: ['analysis-info'],
children: [
d.text('Check the '),
d.a(href: 'score/log.txt', text: 'analysis log'),
d.a(
href: urls.pkgScoreLogTxtUrl(package,
version: isLatestStable ? null : version),
text: 'analysis log',
),
d.text(' for details.'),
],
),
Expand Down
70 changes: 52 additions & 18 deletions app/lib/frontend/templates/views/pkg/versions/version_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:_pub_shared/data/package_api.dart';
import 'package:pub_dev/task/models.dart';

import '../../../../../package/model_properties.dart';
import '../../../../../shared/urls.dart' as urls;
import '../../../../dom/dom.dart' as d;
import '../../../../static_files.dart';
import '../../../package_misc.dart';

d.Node versionRowNode(String package, VersionInfo version, Pubspec pubspec) {
d.Node versionRowNode(
String package,
VersionInfo version,
Pubspec pubspec, {
PackageVersionStateInfo? versionStatus,
}) {
final sdk = pubspec.minSdkVersion;
return d.tr(
attributes: {
Expand Down Expand Up @@ -44,23 +50,7 @@ d.Node versionRowNode(String package, VersionInfo version, Pubspec pubspec) {
),
d.td(
classes: ['documentation'],
child: d.a(
href: urls.pkgDocUrl(package, version: version.version),
rel: 'nofollow',
title: 'Go to the documentation of $package ${version.version}',
child: d.img(
classes: ['version-table-icon'],
image: d.Image(
src: staticUrls.documentationIcon,
alt: 'Go to the documentation of $package ${version.version}',
width: 24,
height: 24,
),
attributes: {
'data-failed-icon': staticUrls.documentationFailedIcon,
},
),
),
child: _documentationCell(package, version, versionStatus),
),
d.td(
classes: ['archive'],
Expand All @@ -82,3 +72,47 @@ d.Node versionRowNode(String package, VersionInfo version, Pubspec pubspec) {
],
);
}

d.Node _documentationCell(
String package,
VersionInfo version,
PackageVersionStateInfo? status,
) {
if (status == null) {
return d.text('');
}
final taskStatus = status.status;
if (taskStatus == PackageVersionStatus.pending) {
return d.text('pending');
} else if (status.docs) {
return d.a(
href: urls.pkgDocUrl(package, version: version.version),
rel: 'nofollow',
title: 'Go to the documentation of $package ${version.version}',
child: d.img(
classes: ['version-table-icon'],
image: d.Image(
src: staticUrls.documentationIcon,
alt: 'Go to the documentation of $package ${version.version}',
width: 24,
height: 24,
),
),
);
} else {
return d.a(
href: urls.pkgScoreLogTxtUrl(package, version: version.version),
rel: 'nofollow',
title: 'Check the analysis logs for $package ${version.version}',
child: d.img(
classes: ['version-table-icon'],
image: d.Image(
src: staticUrls.documentationFailedIcon,
alt: 'Check the analysis logs for $package ${version.version}',
width: 24,
height: 24,
),
),
);
}
}
4 changes: 4 additions & 0 deletions app/lib/shared/urls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ String pkgVersionsUrl(String package) =>
String pkgScoreUrl(String package, {String? version}) =>
pkgPageUrl(package, version: version, pkgPageTab: PkgPageTab.score);

String pkgScoreLogTxtUrl(String package, {String? version}) {
return p.join(pkgScoreUrl(package, version: version), 'log.txt');
}

String pkgAdminUrl(
String package, {
bool? includeHost,
Expand Down
2 changes: 1 addition & 1 deletion app/test/frontend/golden/pkg_score_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ <h3>
</p>
<p class="analysis-info">
Check the
<a href="score/log.txt">analysis log</a>
<a href="/packages/oxygen/score/log.txt">analysis log</a>
for details.
</p>
</section>
Expand Down
10 changes: 3 additions & 7 deletions app/test/frontend/golden/pkg_versions_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ <h2 id="stable">Stable versions of oxygen</h2>
</td>
<td class="documentation">
<a href="/documentation/oxygen/1.2.0/" rel="nofollow" title="Go to the documentation of oxygen 1.2.0">
<img class="version-table-icon" src="/static/hash-%%etag%%/img/description-24px.svg" alt="Go to the documentation of oxygen 1.2.0" width="24" height="24" data-failed-icon="/static/hash-%%etag%%/img/documentation-failed-icon.svg"/>
<img class="version-table-icon" src="/static/hash-%%etag%%/img/description-24px.svg" alt="Go to the documentation of oxygen 1.2.0" width="24" height="24"/>
</a>
</td>
<td class="archive">
Expand All @@ -270,11 +270,7 @@ <h2 id="stable">Stable versions of oxygen</h2>
<td class="uploaded">
<a class="-x-ago" href="" title="%%version-created-date%%" aria-label="Switch between date and elapsed time." aria-role="button">%%x-ago%%</a>
</td>
<td class="documentation">
<a href="/documentation/oxygen/1.0.0/" rel="nofollow" title="Go to the documentation of oxygen 1.0.0">
<img class="version-table-icon" src="/static/hash-%%etag%%/img/description-24px.svg" alt="Go to the documentation of oxygen 1.0.0" width="24" height="24" data-failed-icon="/static/hash-%%etag%%/img/documentation-failed-icon.svg"/>
</a>
</td>
<td class="documentation"></td>
<td class="archive">
<a href="/packages/oxygen/versions/1.0.0.tar.gz" rel="nofollow" title="Download oxygen 1.0.0 archive">
<img class="version-table-icon" src="/static/hash-%%etag%%/img/vertical_align_bottom-24px.svg" alt="Download oxygen 1.0.0 archive" width="24" height="24"/>
Expand Down Expand Up @@ -317,7 +313,7 @@ <h2 id="prerelease">Prerelease versions of oxygen</h2>
</td>
<td class="documentation">
<a href="/documentation/oxygen/2.0.0-dev/" rel="nofollow" title="Go to the documentation of oxygen 2.0.0-dev">
<img class="version-table-icon" src="/static/hash-%%etag%%/img/description-24px.svg" alt="Go to the documentation of oxygen 2.0.0-dev" width="24" height="24" data-failed-icon="/static/hash-%%etag%%/img/documentation-failed-icon.svg"/>
<img class="version-table-icon" src="/static/hash-%%etag%%/img/description-24px.svg" alt="Go to the documentation of oxygen 2.0.0-dev" width="24" height="24"/>
</a>
</td>
<td class="archive">
Expand Down
2 changes: 1 addition & 1 deletion app/test/frontend/static_files_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ void main() {
test('script.dart.js and parts size check', () {
final file = cache.getFile('/static/js/script.dart.js');
expect(file, isNotNull);
expect((file!.bytes.length / 1024).round(), closeTo(312, 1));
expect((file!.bytes.length / 1024).round(), closeTo(309, 1));

final parts = cache.paths
.where((path) =>
Expand Down
2 changes: 2 additions & 0 deletions app/test/frontend/templates_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ void main() {
// no content
expect(
scoreTabNode(
package: 'pkg',
version: '1.1.1',
card: null,
likeCount: 4,
usesFlutter: false,
Expand Down
2 changes: 1 addition & 1 deletion app/test/task/testdata/goldens/packages/oxygen/score.html
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ <h3>
</p>
<p class="analysis-info">
Check the
<a href="score/log.txt">analysis log</a>
<a href="/packages/oxygen/score/log.txt">analysis log</a>
for details.
</p>
</section>
Expand Down
4 changes: 2 additions & 2 deletions app/test/task/testdata/goldens/packages/oxygen/versions.html
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ <h2 id="stable">Stable versions of oxygen</h2>
</td>
<td class="documentation">
<a href="/documentation/oxygen/2.0.0/" rel="nofollow" title="Go to the documentation of oxygen 2.0.0">
<img class="version-table-icon" src="/static/hash-%%etag%%/img/description-24px.svg" alt="Go to the documentation of oxygen 2.0.0" width="24" height="24" data-failed-icon="/static/hash-%%etag%%/img/documentation-failed-icon.svg"/>
<img class="version-table-icon" src="/static/hash-%%etag%%/img/description-24px.svg" alt="Go to the documentation of oxygen 2.0.0" width="24" height="24"/>
</a>
</td>
<td class="archive">
Expand All @@ -258,7 +258,7 @@ <h2 id="stable">Stable versions of oxygen</h2>
</td>
<td class="documentation">
<a href="/documentation/oxygen/1.0.0/" rel="nofollow" title="Go to the documentation of oxygen 1.0.0">
<img class="version-table-icon" src="/static/hash-%%etag%%/img/description-24px.svg" alt="Go to the documentation of oxygen 1.0.0" width="24" height="24" data-failed-icon="/static/hash-%%etag%%/img/documentation-failed-icon.svg"/>
<img class="version-table-icon" src="/static/hash-%%etag%%/img/description-24px.svg" alt="Go to the documentation of oxygen 1.0.0" width="24" height="24"/>
</a>
</td>
<td class="archive">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ <h3>
</p>
<p class="analysis-info">
Check the
<a href="score/log.txt">analysis log</a>
<a href="/packages/oxygen/versions/1.0.0/score/log.txt">analysis log</a>
for details.
</p>
</section>
Expand Down
2 changes: 0 additions & 2 deletions pkg/web_app/lib/script.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'dart:html';
import 'package:mdc_web/mdc_web.dart' as mdc show autoInit;
import 'src/account.dart';
import 'src/dartdoc_status.dart';
import 'src/foldable.dart';
import 'src/hoverable.dart';
import 'src/issues.dart';
Expand Down Expand Up @@ -36,7 +35,6 @@ void _setupAllEvents() {
setupHoverable();
setupMobileNav();
setupIssues();
updateDartdocStatus();
setupLikes();
setupLikesList();
setupScreenshotCarousel();
Expand Down
89 changes: 0 additions & 89 deletions pkg/web_app/lib/src/dartdoc_status.dart

This file was deleted.

0 comments on commit 3fd71ce

Please sign in to comment.