Skip to content
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

fix version dropdown and add a test #114

Merged
merged 1 commit into from
Jun 25, 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
74 changes: 48 additions & 26 deletions addon/controllers/version.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,61 @@
/* eslint-disable prettier/prettier, ember/no-classic-classes, ember/no-get, ember/no-actions-hash */
import Controller, {
inject as controller,
} from '@ember/controller';
import { get, computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import Controller, { inject as controller } from '@ember/controller';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import compareVersions from 'compare-versions';
import { deprecate } from '@ember/debug';

export default Controller.extend({
page: service(),
application: controller(),
store: service(),
router: service(),
export default class VersionController extends Controller {
@service page;
@controller application;

pages: alias('model.pages'),
@service store;
@service router;

versions: computed('application.model.allVersions.[]', function () {
let allVersions = get(this, 'application.model.allVersions');
get pages() {
return this.model.pages;
}

get versions() {
let allVersions = this.application.model.allVersions;

if(!allVersions) {
return;
if (!allVersions) {
return [];
}

return allVersions.sort(compareVersions).reverse();
}),
}

actions: {
selectVersion(version) {
// Navigate to same section/page if it exists
const path = get(this, 'page.currentPage.url');
this.store.queryRecord('content', {version, path}).then(() => {
@action
selectVersion(version) {
// Navigate to same section/page if it exists
const path = this.page.currentPage.url;
this.store
.queryRecord('content', { version, path })
.then(() => {
this.router.transitionTo(`/${version}/${path}`);
}).catch(() => {
this.router.transitionTo('version', version);
})
}
.catch(() => {
this.router.transitionTo('version', version);
});
}
});

// eslint-disable-next-line ember/no-actions-hash
actions = {
selectVersion: (version) => {
deprecate(
'Use of the actions block in the guidemaker version controller is deprecated. If you are accessing controller.actions.selectVersion you can now access controller.selectVersion',
false,
{
id: 'guidemaker-version-controller-actions',
until: '5.0.0',
for: 'guidemaker',
since: {
available: '4.0.3',
enabled: '4.0.3',
},
},
);
this.selectVersion(version);
},
};
}
15 changes: 15 additions & 0 deletions tests/acceptance/version-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { module, test } from 'qunit';
import { visit, currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'dummy/tests/helpers';
import { selectChoose } from 'ember-power-select/test-support';

module('Acceptance | version', function (hooks) {
setupApplicationTest(hooks);

test('the version dropdown works', async function (assert) {
await visit('/');
await selectChoose('.ember-basic-dropdown-trigger', '1.1');

assert.strictEqual(currentURL(), '/v1.1.0');
});
});
Loading