Skip to content

Improve version selector sorting #322

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 1 commit into from
Feb 12, 2019
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
18 changes: 17 additions & 1 deletion addon/components/docs-header/version-selector/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,27 @@ export default Component.extend({
let versions = A(this.get('projectVersion.versions'));
let latest = versions.findBy('key', latestVersionName);
let primary = versions.findBy('key', primaryBranch);
let otherTags = versions
.reject(v => [ latest, primary ].includes(v))
.sort((tagA, tagB) => {
let keyA = tagA.key;
let keyB = tagB.key;

if (keyA > keyB) {
return -1;
}
if (keyA < keyB) {
return 1;
}

// names must be equal
return 0;
});

return [
latest,
primary,
...A(versions.reject(v => [ latest, primary ].includes(v))).sortBy('key')
...otherTags
].filter(Boolean);
}),

Expand Down
24 changes: 21 additions & 3 deletions tests/acceptance/version-selector-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,24 @@ module('Acceptance | Version selector test', function(hooks) {
"path": "master",
"name": "master"
},
"v0.2.x": {
"sha": "aca26720d930843dd084b508fce75b158ff0386e",
"tag": "v0.2.4",
"path": "versions/v0.2.x",
"name": "v0.2.x"
},
"v0.1.0": {
"sha": "d752437850bc9833ea3e354095b501473b0420ae",
"tag": "v0.1.0",
"path": "v0.1.0",
"name": "v0.1.0"
}
},
"v0.3.0": {
"sha": "833a8aa00df5918b07d0574a28a0adc41d5ac2e6",
"tag": "v0.3.0",
"path": "v0.3.0",
"name": "v0.3.0"
},
});

await visit('/');
Expand All @@ -68,8 +80,14 @@ module('Acceptance | Version selector test', function(hooks) {
assert.dom('[data-test-id="version"]:nth-child(2)').includesText('master', 'master is rendered secon');
assert.dom('[data-test-id="version"]:nth-child(2)').includesText('53b73');

assert.dom('[data-test-id="version"]:nth-child(3)').includesText('v0.1.0', 'tags are rendered last');
assert.dom('[data-test-id="version"]:nth-child(3)').includesText('d7524');
assert.dom('[data-test-id="version"]:nth-child(3)').includesText('v0.3.0', 'tags are rendered last, in desc order');
assert.dom('[data-test-id="version"]:nth-child(3)').includesText('833a8');

assert.dom('[data-test-id="version"]:nth-child(4)').includesText('v0.2.x');
assert.dom('[data-test-id="version"]:nth-child(4)').includesText('aca26');

assert.dom('[data-test-id="version"]:nth-child(5)').includesText('v0.1.0');
assert.dom('[data-test-id="version"]:nth-child(5)').includesText('d7524');
});

test(`the version selector renders a tag for latest if present`, async function(assert) {
Expand Down