diff --git a/assets/javascripts/discourse/components/wizard-mapper-connector.js.es6 b/assets/javascripts/discourse/components/wizard-mapper-connector.js.es6 index ee6c38b2..946acaed 100644 --- a/assets/javascripts/discourse/components/wizard-mapper-connector.js.es6 +++ b/assets/javascripts/discourse/components/wizard-mapper-connector.js.es6 @@ -1,6 +1,8 @@ import Component from "@ember/component"; import { gt } from '@ember/object/computed'; import { computed } from "@ember/object"; +import { defaultConnector } from '../lib/wizard-mapper'; +import { later } from "@ember/runloop"; export default Component.extend({ classNameBindings: [':mapper-connector', ':mapper-block', 'hasMultiple::single'], @@ -9,5 +11,16 @@ export default Component.extend({ let key = this.connector; let path = this.inputTypes ? `input.${key}.name` : `connector.${key}`; return I18n.t(`admin.wizard.${path}`); - }) + }), + + didReceiveAttrs() { + if (!this.connector) { + later(() => { + this.set( + 'connector', + defaultConnector(this.connectorType, this.inputType, this.options) + ); + }); + } + } }); \ No newline at end of file diff --git a/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 b/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 index 302949c8..4b1daad1 100644 --- a/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 +++ b/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 @@ -5,7 +5,7 @@ import { getOwner } from 'discourse-common/lib/get-owner'; import { defaultSelectionType, selectionTypes } from '../lib/wizard-mapper'; import { snakeCase } from '../lib/wizard'; import Component from "@ember/component"; -import { bind } from "@ember/runloop"; +import { bind, later } from "@ember/runloop"; export default Component.extend({ classNameBindings: [':mapper-selector', 'activeType'], @@ -33,6 +33,10 @@ export default Component.extend({ showTypes: false, didInsertElement() { + if (this.activeType && !this[`${this.activeType}Enabled`]) { + later(() => this.resetActiveType()); + } + $(document).on("click", bind(this, this.documentClick)); }, diff --git a/assets/javascripts/discourse/lib/wizard-mapper.js.es6 b/assets/javascripts/discourse/lib/wizard-mapper.js.es6 index 3d3ad034..514619a4 100644 --- a/assets/javascripts/discourse/lib/wizard-mapper.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-mapper.js.es6 @@ -22,13 +22,9 @@ function inputTypesContent(options = {}) { mapInputTypes(selectableInputTypes); } -// Connectors +// connectorTypes const connectors = { - output: [ - 'then', - 'set', - ], pair: [ 'equal', 'greater', @@ -36,16 +32,26 @@ const connectors = { 'greater_or_equal', 'less_or_equal', 'regex' - ] + ], + output: [ + 'then', + 'set', + ], } -function defaultConnector(connectorType, inputType, opts = {}) { - if (opts[`${connectorType}Connector`]) return opts[`${connectorType}Connector`]; - if (inputType === 'conditional' && connectorType === 'output') return 'then'; - if (inputType === 'conditional' && connectorType === 'pair') return 'equal'; - if (inputType === 'assignment' && connectorType === 'output') return 'set'; - if (inputType === 'association' && connectorType === 'pair') return 'association'; - if (inputType === 'validation' && connectorType === 'pair') return 'equal'; +function defaultConnector(connectorType, inputType, options={}) { + if (connectorType === 'input') { + return defaultInputType(options); + } + if (connectorType === 'pair') { + if (inputType === 'conditional') return 'equal'; + if (inputType === 'association') return 'association'; + if (inputType === 'validation') return 'equal'; + } + if (connectorType === 'output') { + if (inputType === 'conditional') return 'then'; + if (inputType === 'assignment') return 'set'; + } return 'equal'; } @@ -53,7 +59,7 @@ function connectorContent(connectorType, inputType, opts) { let connector = opts[`${connectorType}Connector`]; if ((!connector && connectorType === 'output') || inputType === 'association') { - connector = defaultConnector(connectorType, inputType, opts); + connector = defaultConnector(connectorType, inputType); } let content = connector ? [connector] : connectors[connectorType]; diff --git a/assets/javascripts/discourse/templates/components/wizard-mapper-connector.hbs b/assets/javascripts/discourse/templates/components/wizard-mapper-connector.hbs index 9ac7ddfe..2e30fbfb 100644 --- a/assets/javascripts/discourse/templates/components/wizard-mapper-connector.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-mapper-connector.hbs @@ -4,7 +4,9 @@ content=connectors onChange=(action (mut connector))}} {{else}} - - {{connectorLabel}} - + {{#if connector}} + + {{connectorLabel}} + + {{/if}} {{/if}} \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/components/wizard-mapper-input.hbs b/assets/javascripts/discourse/templates/components/wizard-mapper-input.hbs index 8e2ee7de..1e005fb8 100644 --- a/assets/javascripts/discourse/templates/components/wizard-mapper-input.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-mapper-input.hbs @@ -1,7 +1,10 @@ {{wizard-mapper-connector connector=input.type connectors=inputTypes - inputTypes=true}} + inputTypes=true + inputType=inputType + connectorType="type" + options=options}} {{#if hasPairs}}
@@ -26,7 +29,10 @@ {{#if hasPairs}} {{wizard-mapper-connector connector=input.output_connector - connectors=connectors}} + connectors=connectors + connectorType="output" + inputType=inputType + options=options}} {{/if}}
diff --git a/assets/javascripts/discourse/templates/components/wizard-mapper-pair.hbs b/assets/javascripts/discourse/templates/components/wizard-mapper-pair.hbs index df3a0ab1..d35e0fbb 100644 --- a/assets/javascripts/discourse/templates/components/wizard-mapper-pair.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-mapper-pair.hbs @@ -9,7 +9,10 @@ {{wizard-mapper-connector connector=pair.connector - connectors=connectors}} + connectors=connectors + connectorType="pair" + inputType=inputType + options=options}}
{{wizard-mapper-selector diff --git a/assets/javascripts/discourse/templates/components/wizard-mapper.hbs b/assets/javascripts/discourse/templates/components/wizard-mapper.hbs index 48e2a202..fe71dbd1 100644 --- a/assets/javascripts/discourse/templates/components/wizard-mapper.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-mapper.hbs @@ -1,6 +1,6 @@ {{#each inputs as |input|}} {{#if input.connector}} - {{wizard-mapper-connector connector=input.connector}} + {{wizard-mapper-connector connector=input.connector connectorType="input"}} {{/if}} {{wizard-mapper-input