FIX: display select kit body if no choices (#6237)

This commit is contained in:
Joffrey JAFFEUX
2018-08-06 11:22:48 -04:00
committed by GitHub
parent 74269ad585
commit c301111461
5 changed files with 35 additions and 23 deletions

View File

@ -11,13 +11,7 @@ export default Ember.Component.extend({
newValue: "", newValue: "",
collection: null, collection: null,
values: null, values: null,
noneKey: Ember.computed.alias("addKey"),
@computed("addKey", "filteredChoices.length")
noneKey(addKey, filteredChoicesLength) {
return addKey || filteredChoicesLength === 0
? "admin.site_settings.value_list.no_choices_none"
: "admin.site_settings.value_list.default_none";
},
@on("didReceiveAttrs") @on("didReceiveAttrs")
_setupCollection() { _setupCollection() {

View File

@ -50,7 +50,6 @@ export default Ember.Component.extend(
filterable: false, filterable: false,
filter: "", filter: "",
previousFilter: "", previousFilter: "",
filterPlaceholder: "select_kit.filter_placeholder",
filterIcon: "search", filterIcon: "search",
headerIcon: null, headerIcon: null,
rowComponent: "select-kit/select-kit-row", rowComponent: "select-kit/select-kit-row",
@ -235,8 +234,8 @@ export default Ember.Component.extend(
} }
}, },
validateCreate() { validateCreate(created) {
return !this.get("hasReachedMaximum"); return !this.get("hasReachedMaximum") && created.length > 0;
}, },
validateSelect() { validateSelect() {
@ -257,10 +256,10 @@ export default Ember.Component.extend(
return selection.length >= minimum; return selection.length >= minimum;
}, },
@computed("shouldFilter", "allowAny", "filter") @computed("shouldFilter", "allowAny")
shouldDisplayFilter(shouldFilter, allowAny, filter) { shouldDisplayFilter(shouldFilter, allowAny) {
if (shouldFilter) return true; if (shouldFilter) return true;
if (allowAny && filter.length > 0) return true; if (allowAny) return true;
return false; return false;
}, },
@ -290,6 +289,13 @@ export default Ember.Component.extend(
} }
}, },
@computed("allowAny")
filterPlaceholder(allowAny) {
return allowAny
? "select_kit.filter_placeholder_with_any"
: "select_kit.filter_placeholder";
},
@computed("filter", "filterable", "autoFilterable", "renderedFilterOnce") @computed("filter", "filterable", "autoFilterable", "renderedFilterOnce")
shouldFilter(filter, filterable, autoFilterable, renderedFilterOnce) { shouldFilter(filter, filterable, autoFilterable, renderedFilterOnce) {
if (renderedFilterOnce && filterable) return true; if (renderedFilterOnce && filterable) return true;
@ -315,12 +321,7 @@ export default Ember.Component.extend(
if (isLoading || hasReachedMaximum) return false; if (isLoading || hasReachedMaximum) return false;
if (collectionComputedContent.map(c => c.value).includes(filter)) if (collectionComputedContent.map(c => c.value).includes(filter))
return false; return false;
if ( if (this.get("allowAny") && this.validateCreate(filter)) return true;
this.get("allowAny") &&
filter.length > 0 &&
this.validateCreate(filter)
)
return true;
return false; return false;
}, },

View File

@ -25,7 +25,7 @@ export default Ember.Component.extend({
if (computedContentTitle) return computedContentTitle; if (computedContentTitle) return computedContentTitle;
if (name) return name; if (name) return name;
return null; return "";
}, },
// this might need a more advanced solution // this might need a more advanced solution

View File

@ -1276,6 +1276,7 @@ en:
default_header_text: Select... default_header_text: Select...
no_content: No matches found no_content: No matches found
filter_placeholder: Search... filter_placeholder: Search...
filter_placeholder_with_any: Search or create...
create: "Create: '{{content}}'" create: "Create: '{{content}}'"
max_content_reached: max_content_reached:
one: "You can only select {{count}} item." one: "You can only select {{count}} item."
@ -3829,9 +3830,6 @@ en:
clear_filter: "Clear" clear_filter: "Clear"
add_url: "add URL" add_url: "add URL"
add_host: "add host" add_host: "add host"
value_list:
default_none: "Type to filter or create..."
no_choices_none: "Type to create..."
uploaded_image_list: uploaded_image_list:
label: "Edit list" label: "Edit list"
empty: "There are no pictures yet. Please upload one." empty: "There are no pictures yet. Please upload one."

View File

@ -726,3 +726,22 @@ componentTest("with accents in content", {
); );
} }
}); });
componentTest("with no content and allowAny", {
template: "{{single-select allowAny=true}}",
async test(assert) {
await click(
this.get("subject")
.header()
.el()
);
const $filter = this.get("subject")
.filter()
.el();
assert.ok($filter.hasClass("is-focused"));
assert.ok(!$filter.hasClass("is-hidden"));
}
});