FIX: displays an error when reaching tags limit

This commit is contained in:
Joffrey JAFFEUX 2018-02-14 00:30:09 +01:00 committed by GitHub
parent 5a56746610
commit 548db91c76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 67 additions and 30 deletions

View File

@ -14,16 +14,33 @@ export default ComboBox.extend({
filterable: true,
noTags: Ember.computed.empty("computedTags"),
allowAny: true,
maximumSelectionSize: Ember.computed.alias("siteSettings.max_tags_per_topic"),
caretUpIcon: Ember.computed.alias("caretIcon"),
caretDownIcon: Ember.computed.alias("caretIcon"),
@computed("computedTags", "siteSettings.max_tags_per_topic")
caretIcon(computedTags, maxTagsPerTopic) {
if (computedTags.length >= maxTagsPerTopic) {
return null;
@computed("limitReached", "maximumSelectionSize")
maxContentRow(limitReached, count) {
if (limitReached) {
return I18n.t("select_kit.max_content_reached", { count });
}
},
mutateAttributes() {
this.set("value", null);
},
@computed("limitReached")
caretIcon(limitReached) {
return limitReached ? null : "plus";
},
@computed("computedTags.[]", "maximumSelectionSize")
limitReached(computedTags, maximumSelectionSize) {
if (computedTags.length >= maximumSelectionSize) {
return true;
}
return "plus";
return false;
},
init() {
@ -46,6 +63,10 @@ export default ComboBox.extend({
},
validateCreate(term) {
if (this.get("limitReached")) {
return false;
}
const filterRegexp = new RegExp(this.site.tags_filter_regexp, "g");
term = term.replace(filterRegexp, "").trim().toLowerCase();
@ -65,6 +86,10 @@ export default ComboBox.extend({
this.site.get("can_create_tag");
},
filterComputedContent(computedContent) {
return computedContent;
},
didRender() {
this._super();
@ -143,13 +168,16 @@ export default ComboBox.extend({
computeHeaderContent() {
let content = this.baseHeaderComputedContent();
const joinedTags = this.get("computedTags").join(", ");
if (isEmpty(this.get("computedTags"))) {
content.label = I18n.t("tagging.choose_for_topic");
} else {
content.label = this.get("computedTags").join(", ");
content.label = joinedTags;
}
content.title = content.name = content.value = joinedTags;
return content;
},
@ -183,10 +211,6 @@ export default ComboBox.extend({
}
},
muateAttributes() {
this.set("value", null);
},
_searchTags(query) {
this.startLoading();

View File

@ -37,7 +37,6 @@ export default Ember.Component.extend(UtilsMixin, PluginApiMixin, DomHelpersMixi
tabindex: 0,
none: null,
highlightedValue: null,
noContentLabel: "select_kit.no_content",
valueAttribute: "id",
nameProperty: "name",
autoFilterable: false,
@ -70,6 +69,8 @@ export default Ember.Component.extend(UtilsMixin, PluginApiMixin, DomHelpersMixi
allowContentReplacement: false,
collectionHeader: null,
allowAutoSelectFirst: true,
maximumSelectionSize: null,
maxContentRow: null,
init() {
this._super();
@ -155,8 +156,10 @@ export default Ember.Component.extend(UtilsMixin, PluginApiMixin, DomHelpersMixi
},
@computed("filter", "filteredComputedContent.[]")
shouldDisplayNoContentRow(filter, filteredComputedContent) {
return filter.length > 0 && filteredComputedContent.length === 0;
noContentRow(filter, filteredComputedContent) {
if (filter.length > 0 && filteredComputedContent.length === 0) {
return I18n.t("select_kit.no_content");
}
},
@computed("filter", "filterable", "autoFilterable", "renderedFilterOnce")

View File

@ -40,11 +40,11 @@
select=(action "select")
highlight=(action "highlight")
create=(action "create")
noContentLabel=noContentLabel
highlightedValue=highlightedValue
computedValue=computedValue
shouldDisplayNoContentRow=shouldDisplayNoContentRow
rowComponentOptions=rowComponentOptions
noContentRow=noContentRow
maxContentRow=maxContentRow
}}
{{/if}}
</div>

View File

@ -30,7 +30,17 @@
}}
{{/if}}
{{#each filteredComputedContent as |computedContent|}}
{{#if maxContentRow}}
<li class="select-kit-row max-content">
{{maxContentRow}}
</li>
{{else}}
{{#if noContentRow}}
<li class="select-kit-row no-content">
{{noContentRow}}
</li>
{{else}}
{{#each filteredComputedContent as |computedContent|}}
{{component rowComponent
computedContent=computedContent
highlightedValue=highlightedValue
@ -40,12 +50,6 @@
highlight=highlight
options=rowComponentOptions
}}
{{/each}}
{{#if shouldDisplayNoContentRow}}
{{#if noContentLabel}}
<li class="select-kit-row no-content">
{{i18n noContentLabel}}
</li>
{{/each}}
{{/if}}
{{/if}}

View File

@ -165,6 +165,11 @@
white-space: nowrap;
}
&.max-content {
white-space: nowrap;
color: $danger;
}
.name {
margin: 0;
overflow: hidden;

View File

@ -1184,6 +1184,7 @@ en:
no_content: No matches found
filter_placeholder: Search...
create: "Create: '{{content}}'"
max_content_reached: "You can only select {{count}} items."
emoji_picker:
filter_placeholder: Search for emoji