Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Revert "replace gh-select-native with one-way-select"
Browse files Browse the repository at this point in the history
This reverts commit e9d75da.
  • Loading branch information
ErisDS committed Sep 30, 2016
1 parent 94a7181 commit 7bec3f7
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 17 deletions.
40 changes: 40 additions & 0 deletions app/components/gh-select-native.js
@@ -0,0 +1,40 @@
import Component from 'ember-component';
import {reads} from 'ember-computed';

function K() {
return this;
}

export default Component.extend({
content: null,
prompt: null,
optionValuePath: 'id',
optionLabelPath: 'title',
selection: null,
action: K, // action to fire on change

// shadow the passed-in `selection` to avoid
// leaking changes to it via a 2-way binding
_selection: reads('selection'),

actions: {
change() {
// jscs:disable requireArrayDestructuring
let selectEl = this.$('select')[0];
// jscs:enable requireArrayDestructuring
let {selectedIndex} = selectEl;

// decrement index by 1 if we have a prompt
let hasPrompt = !!this.get('prompt');
let contentIndex = hasPrompt ? selectedIndex - 1 : selectedIndex;

let selection = this.get('content').objectAt(contentIndex);

// set the local, shadowed selection to avoid leaking
// changes to `selection` out via 2-way binding
this.set('_selection', selection);

this.sendAction('action', selection);
}
}
});
8 changes: 4 additions & 4 deletions app/templates/components/gh-timezone-select.hbs
@@ -1,13 +1,13 @@
<label for="activeTimezone">Timezone</label>
<span class="gh-select" data-select-text="{{selectedTimezone.label}}" tabindex="0">
{{one-way-select
{{gh-select-native
id="activeTimezone"
name="general[activeTimezone]"
options=selectableTimezones
content=selectableTimezones
optionValuePath="name"
optionLabelPath="label"
value=selectedTimezone
update=(action "setTimezone")
selection=selectedTimezone
action="setTimezone"
}}
</span>
{{#if hasTimezoneOverride}}
Expand Down
10 changes: 5 additions & 5 deletions app/templates/post-settings-menu.hbs
Expand Up @@ -67,14 +67,14 @@
<label for="author-list">Author</label>
<span class="input-icon icon-user">
<span class="gh-select" tabindex="0">
{{one-way-select
id="author-list"
{{gh-select-native
name="post-setting-author"
options=authors
id="author-list"
content=authors
optionValuePath="id"
optionLabelPath="name"
value=selectedAuthor
update=(action "changeAuthor")
selection=selectedAuthor
action="changeAuthor"
}}
</span>
</span>
Expand Down
9 changes: 4 additions & 5 deletions app/templates/team/user.hbs
Expand Up @@ -115,13 +115,12 @@
<div class="form-group">
<label for="user-role">Role</label>
<span class="gh-select" tabindex="0">
{{one-way-select
id="new-user-role"
options=roles
{{gh-select-native id="new-user-role"
content=roles
optionValuePath="id"
optionLabelPath="name"
value=model.role
update=(action "changeRole")
selection=model.role
action="changeRole"
}}
</span>
<p>What permissions should this user have?</p>
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/editor-test.js
Expand Up @@ -208,7 +208,7 @@ describe('Acceptance: Editor', function() {
find('#activeTimezone option[value="Pacific/Kwajalein"]').prop('selected', true);
});

triggerEvent('#activeTimezone', 'change');
triggerEvent('#activeTimezone select', 'change');
// save the settings
click('.view-header .btn.btn-blue');

Expand Down
4 changes: 2 additions & 2 deletions tests/acceptance/settings/general-test.js
Expand Up @@ -135,12 +135,12 @@ describe('Acceptance: Settings - General', function () {
andThen(() => {
expect(currentURL(), 'currentURL').to.equal('/settings/general');

expect(find('#activeTimezone option').length, 'available timezones').to.equal(66);
expect(find('#activeTimezone select option').length, 'available timezones').to.equal(66);
expect(find('#activeTimezone option:selected').text().trim()).to.equal('(GMT) UTC');
find('#activeTimezone option[value="Africa/Cairo"]').prop('selected', true);
});

triggerEvent('#activeTimezone', 'change');
triggerEvent('#activeTimezone select', 'change');
click('.view-header .btn.btn-blue');

andThen(() => {
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/components/gh-select-native-test.js
@@ -0,0 +1,28 @@
/* jshint expr:true */
import {expect} from 'chai';
import {
describeComponent,
it
} from 'ember-mocha';

describeComponent(
'gh-select-native',
'Unit: Component: gh-select-native',
{
unit: true
// specify the other units that are required for this test
// needs: ['component:foo', 'helper:bar']
},
function () {
it('renders', function () {
// creates the component instance
let component = this.subject();

expect(component._state).to.equal('preRender');

// renders the component on the page
this.render();
expect(component._state).to.equal('inDOM');
});
}
);

0 comments on commit 7bec3f7

Please sign in to comment.