Skip to content

Commit 4245037

Browse files
authored
frontend: Migrate to use default_version and yanked (#9842)
1 parent 1f3322a commit 4245037

File tree

4 files changed

+14
-22
lines changed

4 files changed

+14
-22
lines changed

app/components/crate-row.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
{{@crate.name}}
77
</a>
88
{{/let}}
9-
{{#if @crate.defaultVersion}}
10-
<span local-class="version" data-test-version>v{{@crate.defaultVersion}}</span>
9+
{{#if (and @crate.default_version (not @crate.yanked))}}
10+
<span local-class="version" data-test-version>v{{@crate.default_version}}</span>
1111
<CopyButton
12-
@copyText='{{@crate.name}} = "{{@crate.defaultVersion}}"'
12+
@copyText='{{@crate.name}} = "{{@crate.default_version}}"'
1313
title="Copy Cargo.toml snippet to clipboard"
1414
local-class="copy-button"
1515
data-test-copy-toml-button

app/models/crate.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ export default class Crate extends Model {
1010
@attr recent_downloads;
1111
@attr('date') created_at;
1212
@attr('date') updated_at;
13+
/**
14+
* This is the default version that will be shown when visiting the crate
15+
* details page. Note that this value can be `null`, which may be unexpected.
16+
* @type {string | null}
17+
*/
18+
@attr default_version;
19+
@attr yanked;
1320
@attr max_version;
1421
@attr max_stable_version;
1522
@attr newest_version;
@@ -27,21 +34,6 @@ export default class Crate extends Model {
2734
@hasMany('category', { async: true, inverse: null }) categories;
2835
@hasMany('dependency', { async: true, inverse: null }) reverse_dependencies;
2936

30-
/**
31-
* This is the default version that will be shown when visiting the crate
32-
* details page. Note that this can be `undefined` if all versions of the crate
33-
* have been yanked.
34-
* @return {string}
35-
*/
36-
get defaultVersion() {
37-
if (this.max_stable_version) {
38-
return this.max_stable_version;
39-
}
40-
if (this.max_version && this.max_version !== '0.0.0') {
41-
return this.max_version;
42-
}
43-
}
44-
4537
@cached get versionIdsBySemver() {
4638
let versions = this.versions.toArray() ?? [];
4739
return versions.sort(compareVersionBySemver).map(v => v.id);

app/routes/crate/dependencies.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export default class VersionRoute extends Route {
88
let crate = this.modelFor('crate');
99
let versions = await crate.get('versions');
1010

11-
let { defaultVersion } = crate;
12-
let version = versions.find(version => version.num === defaultVersion) ?? versions.lastObject;
11+
let { default_version } = crate;
12+
let version = versions.find(version => version.num === default_version) ?? versions.lastObject;
1313

1414
this.router.replaceWith('crate.version-dependencies', crate, version.num);
1515
}

app/routes/crate/version.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export default class VersionRoute extends Route {
3131
return this.router.replaceWith('catch-all', { transition, title });
3232
}
3333
} else {
34-
let { defaultVersion } = crate;
35-
version = versions.find(version => version.num === defaultVersion);
34+
let { default_version } = crate;
35+
version = versions.find(version => version.num === default_version);
3636

3737
if (!version) {
3838
let versionNums = versions.map(it => it.num);

0 commit comments

Comments
 (0)