From 0d0fb83bd112de7f8ae010557f17fab7cac5a0fc Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 2 May 2024 14:57:56 +0200 Subject: [PATCH] FIX: various fixes for realtime validations feature See further https://coop.pavilion.tech/t/similar-posts-category-picker-not-working/3513 --- .../discourse/components/validator.js.es6 | 3 +-- .../components/wizard-realtime-validations.js.es6 | 13 ++++++------- .../components/custom-wizard-similar-topic.hbs | 2 +- .../components/wizard-realtime-validations.hbs | 13 +++++++------ .../realtime_validations/similar_topics.rb | 2 +- plugin.rb | 2 +- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/assets/javascripts/discourse/components/validator.js.es6 b/assets/javascripts/discourse/components/validator.js.es6 index 3c19cc3d..2d9f29ed 100644 --- a/assets/javascripts/discourse/components/validator.js.es6 +++ b/assets/javascripts/discourse/components/validator.js.es6 @@ -1,6 +1,6 @@ import Component from "@ember/component"; import { equal } from "@ember/object/computed"; -import { ajax, getToken } from "discourse/lib/ajax"; +import { ajax } from "discourse/lib/ajax"; export default Component.extend({ classNames: ["validator"], @@ -20,7 +20,6 @@ export default Component.extend({ return ajax("/realtime-validations", { data: { type: this.get("type"), - authenticity_token: getToken(), ...params, }, }); diff --git a/assets/javascripts/discourse/components/wizard-realtime-validations.js.es6 b/assets/javascripts/discourse/components/wizard-realtime-validations.js.es6 index b1d8a0f5..4d9f0ab7 100644 --- a/assets/javascripts/discourse/components/wizard-realtime-validations.js.es6 +++ b/assets/javascripts/discourse/components/wizard-realtime-validations.js.es6 @@ -35,13 +35,12 @@ export default Component.extend({ } const validationBuffer = cloneJSON(this.get("field.validations")); - let bufferCategories; - if ( - validationBuffer.similar_topics && - (bufferCategories = validationBuffer.similar_topics.categories) - ) { - const categories = Category.findByIds(bufferCategories); - validationBuffer.similar_topics.categories = categories; + let bufferCategories = validationBuffer.similar_topics?.categories || []; + if (bufferCategories) { + validationBuffer.similar_topics.categories = + Category.findByIds(bufferCategories); + } else { + validationBuffer.similar_topics.categories = []; } this.set("validationBuffer", validationBuffer); }, diff --git a/assets/javascripts/discourse/templates/components/custom-wizard-similar-topic.hbs b/assets/javascripts/discourse/templates/components/custom-wizard-similar-topic.hbs index 286521b3..2deaec45 100644 --- a/assets/javascripts/discourse/templates/components/custom-wizard-similar-topic.hbs +++ b/assets/javascripts/discourse/templates/components/custom-wizard-similar-topic.hbs @@ -1,6 +1,6 @@ {{html-safe topic.fancy_title}} -
{{date-node topic.created_at}} +
- {{html-safe topic.blurb}}
\ No newline at end of file diff --git a/assets/javascripts/discourse/templates/components/wizard-realtime-validations.hbs b/assets/javascripts/discourse/templates/components/wizard-realtime-validations.hbs index 04f2b1c4..00078cb2 100644 --- a/assets/javascripts/discourse/templates/components/wizard-realtime-validations.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-realtime-validations.hbs @@ -18,13 +18,14 @@ }}
- {{category-selector - categories=(get - this (concat "validationBuffer." type ".categories") - ) - onChange=(action "updateValidationCategories" type props) +
diff --git a/lib/custom_wizard/realtime_validations/similar_topics.rb b/lib/custom_wizard/realtime_validations/similar_topics.rb index 2c99cf43..d7682a28 100644 --- a/lib/custom_wizard/realtime_validations/similar_topics.rb +++ b/lib/custom_wizard/realtime_validations/similar_topics.rb @@ -27,7 +27,7 @@ class CustomWizard::RealtimeValidation::SimilarTopics result = CustomWizard::RealtimeValidation::Result.new(:similar_topic) - if title.length < SiteSetting.min_title_similar_length || !Topic.count_exceeds_minimum? + if title.length < SiteSetting.min_title_similar_length return result end diff --git a/plugin.rb b/plugin.rb index f4f73680..15723558 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-custom-wizard # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. -# version: 2.6.7 +# version: 2.6.8 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever, Juan Marcos Gutierrez Ramos # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech