-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from empress/fix-dropdown
fix version dropdown and add a test
- Loading branch information
Showing
2 changed files
with
63 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |