From 5abc0f4a4c7276abd8706b9157b7c79176dc34fd Mon Sep 17 00:00:00 2001 From: angusmcleod Date: Wed, 20 Oct 2021 21:56:34 +0800 Subject: [PATCH] IMPROVE: Add value type to mapper selector --- .../components/wizard-mapper-selector.js.es6 | 26 ++++++++++++++++--- .../discourse/lib/wizard-mapper.js.es6 | 7 ++++- .../components/wizard-mapper-pair.hbs | 3 ++- config/locales/client.en.yml | 4 ++- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 b/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 index 7d9b0bbd..806e4072 100644 --- a/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 +++ b/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 @@ -24,6 +24,12 @@ const customFieldActionMap = { user: ["update_profile"], }; +const values = [ + "present", + "true", + "false" +]; + export default Component.extend({ classNameBindings: [":mapper-selector", "activeType"], @@ -60,6 +66,9 @@ export default Component.extend({ showCustomField: computed("activeType", function () { return this.showInput("customField"); }), + showValue: computed("activeType", function () { + return this.showInput("value"); + }), textEnabled: computed("options.textSelection", "inputType", function () { return this.optionEnabled("textSelection"); }), @@ -117,6 +126,9 @@ export default Component.extend({ listEnabled: computed("options.listSelection", "inputType", function () { return this.optionEnabled("listSelection"); }), + valueEnabled: computed("connector", function () { + return this.connector === "is"; + }), groups: alias("site.groups"), categories: alias("site.categories"), @@ -125,7 +137,8 @@ export default Component.extend({ "showWizardAction", "showUserField", "showUserFieldOptions", - "showCustomField" + "showCustomField", + "showValue" ), showMultiSelect: or("showCategory", "showGroup"), hasTypes: gt("selectorTypes.length", 1), @@ -157,7 +170,7 @@ export default Component.extend({ } }, - @discourseComputed + @discourseComputed("connector") selectorTypes() { return selectionTypes .filter((type) => this[`${type}Enabled`]) @@ -268,6 +281,13 @@ export default Component.extend({ })); } + if (activeType === "value") { + content = values.map((value) => ({ + id: value, + name: value + })); + } + return content; }, @@ -337,7 +357,7 @@ export default Component.extend({ resetActiveType() { this.set( "activeType", - defaultSelectionType(this.selectorType, this.options) + defaultSelectionType(this.selectorType, this.options, this.connector) ); }, diff --git a/assets/javascripts/discourse/lib/wizard-mapper.js.es6 b/assets/javascripts/discourse/lib/wizard-mapper.js.es6 index 29315b9c..9c4c3a1c 100644 --- a/assets/javascripts/discourse/lib/wizard-mapper.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-mapper.js.es6 @@ -105,13 +105,18 @@ const selectionTypes = [ "tag", "user", "customField", + "value" ]; -function defaultSelectionType(inputType, options = {}) { +function defaultSelectionType(inputType, options = {}, connector = null) { if (options[`${inputType}DefaultSelection`]) { return options[`${inputType}DefaultSelection`]; } + if (connector === "is") { + return "value"; + } + let type = selectionTypes[0]; for (let t of selectionTypes) { diff --git a/assets/javascripts/discourse/templates/components/wizard-mapper-pair.hbs b/assets/javascripts/discourse/templates/components/wizard-mapper-pair.hbs index ffb9eaf2..c4c15907 100644 --- a/assets/javascripts/discourse/templates/components/wizard-mapper-pair.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-mapper-pair.hbs @@ -23,7 +23,8 @@ value=pair.value activeType=pair.value_type options=options - onUpdate=onUpdate}} + onUpdate=onUpdate + connector=pair.connector}} {{#if showJoin}} diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index d9b34a87..b07fd84a 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -124,6 +124,7 @@ en: group: "group" list: "list" custom_field: "custom field" + value: "value" placeholder: text: "Enter text" @@ -138,7 +139,8 @@ en: group: "Select group" list: "Enter item" custom_field: "Select field" - + value: "Select value" + error: failed: "failed to save wizard" required: "{{type}} requires {{property}}"