From 3d9a564d63fe63582853c1cfff0e270222736289 Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Mon, 22 Feb 2021 16:25:47 +0530 Subject: [PATCH] IMPR: simplified similar topics template (#73) * IMPR: simplified similar topics template * renamed label to key * minor formatting * added dasherize logic for classnames --- .../similar-topics-validator.js.es6 | 48 ++++++++++++++++++- .../components/similar-topics-validator.hbs | 27 +++++------ 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/assets/javascripts/wizard/components/similar-topics-validator.js.es6 b/assets/javascripts/wizard/components/similar-topics-validator.js.es6 index ada70181..2625cdf2 100644 --- a/assets/javascripts/wizard/components/similar-topics-validator.js.es6 +++ b/assets/javascripts/wizard/components/similar-topics-validator.js.es6 @@ -7,6 +7,7 @@ import EmberObject, { computed } from "@ember/object"; import { notEmpty, and, equal, empty } from "@ember/object/computed"; import discourseComputed from "discourse-common/utils/decorators"; import { categoryBadgeHTML } from "discourse/helpers/category-link"; +import { dasherize } from "@ember/string"; export default WizardFieldValidator.extend({ classNames: ['similar-topics-validator'], @@ -27,6 +28,7 @@ export default WizardFieldValidator.extend({ return this.noSimilarTopics && !this.typing; }), hasValidationCategories: notEmpty('validationCategories'), + showValidationCategories: and('showDefault', 'hasValidationCategories'), @discourseComputed('validation.categories') validationCategories(categoryIds) { @@ -39,7 +41,51 @@ export default WizardFieldValidator.extend({ catLinks(categories) { return categories.map(category => categoryBadgeHTML(category)).join(""); }, - + + @discourseComputed( + 'loading', + 'showSimilarTopics', + 'showNoSimilarTopics', + 'showValidationCategories', + 'showDefault' + ) + currentState( + loading, + showSimilarTopics, + showNoSimilarTopics, + showValidationCategories, + showDefault + ) { + switch (true) { + case loading: + return 'loading'; + case showSimilarTopics: + return 'results'; + case showNoSimilarTopics: + return 'no_results'; + case showValidationCategories: + return 'default_categories'; + case showDefault: + return 'default'; + default: + return false; + } + }, + + @discourseComputed('currentState') + currentStateClass (currentState) { + if (currentState) return `similar-topics-${dasherize(currentState)}`; + + return "similar-topics"; + }, + + @discourseComputed('currentState') + currentStateKey (currentState) { + if (currentState) return `realtime_validations.similar_topics.${currentState}`; + + return false; + }, + validate() {}, @observes("field.value") diff --git a/assets/javascripts/wizard/templates/components/similar-topics-validator.hbs b/assets/javascripts/wizard/templates/components/similar-topics-validator.hbs index eb57e778..bba88c0f 100644 --- a/assets/javascripts/wizard/templates/components/similar-topics-validator.hbs +++ b/assets/javascripts/wizard/templates/components/similar-topics-validator.hbs @@ -1,16 +1,13 @@ -{{#if loading}} - -{{else if showSimilarTopics}} - - {{wizard-similar-topics topics=similarTopics}} -{{else if showNoSimilarTopics}} - -{{else if showDefault}} - {{#if hasValidationCategories}} - - {{else}} - + + +{{#if showSimilarTopics}} + {{wizard-similar-topics topics=similarTopics}} +{{/if}}