From 92bd7953f1c5514e30f4991b5d1aba87194ac3b5 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 15 Apr 2020 15:41:27 +1000 Subject: [PATCH] Handle incorrect data in mapped inputs --- .../discourse/components/wizard-mapper.js.es6 | 15 ++++++++++++--- .../javascripts/discourse/lib/wizard-json.js.es6 | 15 ++++++++++----- assets/stylesheets/common/wizard-admin.scss | 4 ++++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/assets/javascripts/discourse/components/wizard-mapper.js.es6 b/assets/javascripts/discourse/components/wizard-mapper.js.es6 index 2d1875bc..525cf4ba 100644 --- a/assets/javascripts/discourse/components/wizard-mapper.js.es6 +++ b/assets/javascripts/discourse/components/wizard-mapper.js.es6 @@ -1,17 +1,26 @@ import { getOwner } from 'discourse-common/lib/get-owner'; import { newInput, selectionTypes } from '../lib/wizard-mapper'; import { default as discourseComputed, observes, on } from 'discourse-common/utils/decorators'; +import { later } from "@ember/runloop"; import Component from "@ember/component"; import { A } from "@ember/array"; export default Component.extend({ classNames: 'wizard-mapper', + didReceiveAttrs() { + if (this.inputs && this.inputs.constructor !== Array) { + later(() => this.set('inputs', null)); + } + }, + @discourseComputed('inputs.@each.type') canAdd(inputs) { - return !inputs || inputs.every(i => { - return ['assignment','association'].indexOf(i.type) === -1; - }); + return !inputs || + inputs.constructor !== Array || + inputs.every(i => { + return ['assignment','association'].indexOf(i.type) === -1; + }); }, @discourseComputed('options.@each.inputType') diff --git a/assets/javascripts/discourse/lib/wizard-json.js.es6 b/assets/javascripts/discourse/lib/wizard-json.js.es6 index 670fcee7..c1325514 100644 --- a/assets/javascripts/discourse/lib/wizard-json.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-json.js.es6 @@ -22,11 +22,16 @@ function castCase(property, value) { return property.indexOf('_type') > -1 ? camelCase(value) : value; } -function buildProperty(json, property, type) { - if (mapped(property, type) && present(json[property])) { - let inputs = []; +function buildProperty(json, property, type) { + let value = json[property]; + + if (mapped(property, type) && + present(value) && + value.constructor === Array) { - json[property].forEach(inputJson => { + let inputs = []; + + value.forEach(inputJson => { let input = {} Object.keys(inputJson).forEach(inputKey => { @@ -61,7 +66,7 @@ function buildProperty(json, property, type) { return A(inputs); } else { - return json[property]; + return value; } } diff --git a/assets/stylesheets/common/wizard-admin.scss b/assets/stylesheets/common/wizard-admin.scss index 23bdf5fe..31ebeb8b 100644 --- a/assets/stylesheets/common/wizard-admin.scss +++ b/assets/stylesheets/common/wizard-admin.scss @@ -34,6 +34,10 @@ .wizard-submissions { overflow: scroll; + + table td { + min-width: 150px; + } } .admin-wizards-logs {