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

View File

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

View File

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

View File

@ -30,22 +30,26 @@
}} }}
{{/if}} {{/if}}
{{#each filteredComputedContent as |computedContent|}} {{#if maxContentRow}}
{{component rowComponent <li class="select-kit-row max-content">
computedContent=computedContent {{maxContentRow}}
highlightedValue=highlightedValue </li>
computedValue=computedValue {{else}}
templateForRow=templateForRow {{#if noContentRow}}
select=select
highlight=highlight
options=rowComponentOptions
}}
{{/each}}
{{#if shouldDisplayNoContentRow}}
{{#if noContentLabel}}
<li class="select-kit-row no-content"> <li class="select-kit-row no-content">
{{i18n noContentLabel}} {{noContentRow}}
</li> </li>
{{else}}
{{#each filteredComputedContent as |computedContent|}}
{{component rowComponent
computedContent=computedContent
highlightedValue=highlightedValue
computedValue=computedValue
templateForRow=templateForRow
select=select
highlight=highlight
options=rowComponentOptions
}}
{{/each}}
{{/if}} {{/if}}
{{/if}} {{/if}}

View File

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

View File

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