mirror of
https://github.com/TryGhost/Ghost-Admin.git
synced 2023-12-14 02:33:04 +01:00
replace gh-select-native with one-way-select (#286)
no issue - removes `gh-select-native` component as ember-one-way-control's `one-way-select` component offers the same one-way-binding but also allows element attributes to be set
This commit is contained in:
parent
5913827646
commit
3afc43e2d2
7 changed files with 17 additions and 84 deletions
|
@ -1,40 +0,0 @@
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
|
@ -1,13 +1,13 @@
|
||||||
<label for="activeTimezone">Timezone</label>
|
<label for="activeTimezone">Timezone</label>
|
||||||
<span class="gh-select" data-select-text="{{selectedTimezone.label}}" tabindex="0">
|
<span class="gh-select" data-select-text="{{selectedTimezone.label}}" tabindex="0">
|
||||||
{{gh-select-native
|
{{one-way-select
|
||||||
id="activeTimezone"
|
id="activeTimezone"
|
||||||
name="general[activeTimezone]"
|
name="general[activeTimezone]"
|
||||||
content=selectableTimezones
|
options=selectableTimezones
|
||||||
optionValuePath="name"
|
optionValuePath="name"
|
||||||
optionLabelPath="label"
|
optionLabelPath="label"
|
||||||
selection=selectedTimezone
|
value=selectedTimezone
|
||||||
action="setTimezone"
|
update=(action "setTimezone")
|
||||||
}}
|
}}
|
||||||
</span>
|
</span>
|
||||||
{{#if hasTimezoneOverride}}
|
{{#if hasTimezoneOverride}}
|
||||||
|
|
|
@ -67,14 +67,14 @@
|
||||||
<label for="author-list">Author</label>
|
<label for="author-list">Author</label>
|
||||||
<span class="input-icon icon-user">
|
<span class="input-icon icon-user">
|
||||||
<span class="gh-select" tabindex="0">
|
<span class="gh-select" tabindex="0">
|
||||||
{{gh-select-native
|
{{one-way-select
|
||||||
name="post-setting-author"
|
|
||||||
id="author-list"
|
id="author-list"
|
||||||
content=authors
|
name="post-setting-author"
|
||||||
|
options=authors
|
||||||
optionValuePath="id"
|
optionValuePath="id"
|
||||||
optionLabelPath="name"
|
optionLabelPath="name"
|
||||||
selection=selectedAuthor
|
value=selectedAuthor
|
||||||
action="changeAuthor"
|
update=(action "changeAuthor")
|
||||||
}}
|
}}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -115,12 +115,13 @@
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="user-role">Role</label>
|
<label for="user-role">Role</label>
|
||||||
<span class="gh-select" tabindex="0">
|
<span class="gh-select" tabindex="0">
|
||||||
{{gh-select-native id="new-user-role"
|
{{one-way-select
|
||||||
content=roles
|
id="new-user-role"
|
||||||
|
options=roles
|
||||||
optionValuePath="id"
|
optionValuePath="id"
|
||||||
optionLabelPath="name"
|
optionLabelPath="name"
|
||||||
selection=model.role
|
value=model.role
|
||||||
action="changeRole"
|
update=(action "changeRole")
|
||||||
}}
|
}}
|
||||||
</span>
|
</span>
|
||||||
<p>What permissions should this user have?</p>
|
<p>What permissions should this user have?</p>
|
||||||
|
|
|
@ -208,7 +208,7 @@ describe('Acceptance: Editor', function() {
|
||||||
find('#activeTimezone option[value="Pacific/Kwajalein"]').prop('selected', true);
|
find('#activeTimezone option[value="Pacific/Kwajalein"]').prop('selected', true);
|
||||||
});
|
});
|
||||||
|
|
||||||
triggerEvent('#activeTimezone select', 'change');
|
triggerEvent('#activeTimezone', 'change');
|
||||||
// save the settings
|
// save the settings
|
||||||
click('.view-header .btn.btn-blue');
|
click('.view-header .btn.btn-blue');
|
||||||
|
|
||||||
|
|
|
@ -135,12 +135,12 @@ describe('Acceptance: Settings - General', function () {
|
||||||
andThen(() => {
|
andThen(() => {
|
||||||
expect(currentURL(), 'currentURL').to.equal('/settings/general');
|
expect(currentURL(), 'currentURL').to.equal('/settings/general');
|
||||||
|
|
||||||
expect(find('#activeTimezone select option').length, 'available timezones').to.equal(66);
|
expect(find('#activeTimezone option').length, 'available timezones').to.equal(66);
|
||||||
expect(find('#activeTimezone option:selected').text().trim()).to.equal('(GMT) UTC');
|
expect(find('#activeTimezone option:selected').text().trim()).to.equal('(GMT) UTC');
|
||||||
find('#activeTimezone option[value="Africa/Cairo"]').prop('selected', true);
|
find('#activeTimezone option[value="Africa/Cairo"]').prop('selected', true);
|
||||||
});
|
});
|
||||||
|
|
||||||
triggerEvent('#activeTimezone select', 'change');
|
triggerEvent('#activeTimezone', 'change');
|
||||||
click('.view-header .btn.btn-blue');
|
click('.view-header .btn.btn-blue');
|
||||||
|
|
||||||
andThen(() => {
|
andThen(() => {
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
/* 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');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
Loading…
Reference in a new issue