Skip to content

frontend: Migrate to use default_version and yanked #9842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/components/crate-row.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
{{@crate.name}}
</a>
{{/let}}
{{#if @crate.defaultVersion}}
<span local-class="version" data-test-version>v{{@crate.defaultVersion}}</span>
{{#if (and @crate.default_version (not @crate.yanked))}}
<span local-class="version" data-test-version>v{{@crate.default_version}}</span>
<CopyButton
@copyText='{{@crate.name}} = "{{@crate.defaultVersion}}"'
@copyText='{{@crate.name}} = "{{@crate.default_version}}"'
title="Copy Cargo.toml snippet to clipboard"
local-class="copy-button"
data-test-copy-toml-button
Expand Down
22 changes: 7 additions & 15 deletions app/models/crate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ export default class Crate extends Model {
@attr recent_downloads;
@attr('date') created_at;
@attr('date') updated_at;
/**
* This is the default version that will be shown when visiting the crate
* details page. Note that this value can be `null`, which may be unexpected.
* @type {string | null}
*/
@attr default_version;
@attr yanked;
@attr max_version;
@attr max_stable_version;
@attr newest_version;
Expand All @@ -27,21 +34,6 @@ export default class Crate extends Model {
@hasMany('category', { async: true, inverse: null }) categories;
@hasMany('dependency', { async: true, inverse: null }) reverse_dependencies;

/**
* This is the default version that will be shown when visiting the crate
* details page. Note that this can be `undefined` if all versions of the crate
* have been yanked.
* @return {string}
*/
get defaultVersion() {
if (this.max_stable_version) {
return this.max_stable_version;
}
if (this.max_version && this.max_version !== '0.0.0') {
return this.max_version;
}
}

@cached get versionIdsBySemver() {
let versions = this.versions.toArray() ?? [];
return versions.sort(compareVersionBySemver).map(v => v.id);
Expand Down
4 changes: 2 additions & 2 deletions app/routes/crate/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export default class VersionRoute extends Route {
let crate = this.modelFor('crate');
let versions = await crate.get('versions');

let { defaultVersion } = crate;
let version = versions.find(version => version.num === defaultVersion) ?? versions.lastObject;
let { default_version } = crate;
let version = versions.find(version => version.num === default_version) ?? versions.lastObject;

this.router.replaceWith('crate.version-dependencies', crate, version.num);
}
Expand Down
4 changes: 2 additions & 2 deletions app/routes/crate/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export default class VersionRoute extends Route {
return this.router.replaceWith('catch-all', { transition, title });
}
} else {
let { defaultVersion } = crate;
version = versions.find(version => version.num === defaultVersion);
let { default_version } = crate;
version = versions.find(version => version.num === default_version);

if (!version) {
let versionNums = versions.map(it => it.num);
Expand Down
Loading