FIX: improves uncategorized support for category-select-box

This commit is contained in:
Joffrey JAFFEUX 2017-08-29 12:48:26 +02:00 committed by GitHub
parent 861dbe3b51
commit f101fec19c
8 changed files with 21 additions and 55 deletions

View File

@ -7,6 +7,8 @@ import Category from "discourse/models/category";
export default SelectBoxComponent.extend({
classNames: ["category-select-box"],
selectBoxRowComponent: "category-select-box/category-select-box-row",
textKey: "name",
filterable: true,

View File

@ -0,0 +1,13 @@
import computed from 'ember-addons/ember-computed-decorators';
import SelectBoxRowComponent from "discourse/components/select-box/select-box-row";
import Category from "discourse/models/category";
export default SelectBoxRowComponent.extend({
classNameBindings: ["isUncategorized"],
@computed("content")
isUncategorized(content) {
const category = Category.findById(content.id);
return category.get("isUncategorizedCategory");
}
});

View File

@ -5,29 +5,16 @@ export default Ember.Component.extend({
classNameBindings: ["focused:is-focused"],
showClearButton: false,
didReceiveAttrs() {
this._super();
this._setCaretIcon();
},
@computed("clearable", "selectedId")
showClearButton(clearable, selectedId) {
return clearable === true && !Ember.isNone(selectedId);
},
click() {
this.sendAction("onToggle");
},
actions: {
clearSelection() {
this.sendAction("onClearSelection");
}
},
_setCaretIcon() {
if(this.get("expanded")) {
this.set("caretIcon", this.get("caretUpIcon"));

View File

@ -13,9 +13,7 @@
caretUpIcon=caretUpIcon
caretDownIcon=caretDownIcon
onToggle=(action "onToggle")
onClearSelection=(action "onClearSelection")
icon=icon
clearable=clearable
expanded=expanded
value=value
}}

View File

@ -6,10 +6,4 @@
{{text}}
</span>
{{#if showClearButton}}
<button class="btn btn-primary clear-selection" {{action "clearSelection" bubbles=false}}>
{{d-icon "times"}}
</button>
{{/if}}
{{d-icon caretIcon class="caret-icon"}}

View File

@ -8,6 +8,12 @@
-ms-flex-direction: column;
flex-direction: column;
&.is-uncategorized {
.topic-count {
display: none;
}
}
.topic-count {
font-size: 11px;
color: $primary;

View File

@ -91,18 +91,6 @@
-webkit-box-shadow: $tertiary 0px 0px 6px 0px;
box-shadow: $tertiary 0px 0px 6px 0px;
}
.clear-selection {
margin: 0 5px;
padding: 0;
outline: none;
.d-icon {
margin: 0;
padding-left: 10px;
padding-right: 10px;
}
}
}
.select-box-body {

View File

@ -324,28 +324,6 @@ componentTest('static headerText', {
}
});
componentTest('clearable selection', {
template: '{{select-box value=1 content=content clearable=true}}',
beforeEach() {
this.set("content", [{ id: 1, text: "robin" }, { id: 2, text: "regis" }]);
},
test(assert) {
click(".select-box-header");
andThen(() => {
assert.ok(exists(".select-box-row.is-highlighted"));
assert.equal(find(".select-box-header .current-selection").html().trim(), "robin");
});
click(".select-box-header .clear-selection");
andThen(() => {
assert.notOk(exists(".select-box-row.is-highlighted"));
assert.equal(find(".select-box-header .current-selection").html().trim(), "Select...");
});
}
});
componentTest('supports custom row title', {
template: '{{select-box content=content titleForRow=titleForRow}}',