Skip to content
Permalink
Browse files

fix(table): fix table rendering for dynamic choice fields (#239)

  • Loading branch information...
czosel committed May 15, 2019
1 parent b865220 commit 5d40c1362b15585c0d295f042a3c38ff05cbdda7
Showing with 15 additions and 7 deletions.
  1. +15 −7 addon/components/cf-field-value.js
@@ -1,9 +1,14 @@
import Component from "@ember/component";
import layout from "../templates/components/cf-field-value";
import { computed } from "@ember/object";
import { camelize } from "@ember/string";
import { inject as service } from "@ember/service";
import getFileAnswerInfoQuery from "ember-caluma/gql/queries/get-fileanswer-info";

function getOptionKey(questionType) {
return `${camelize(questionType.replace(/Question$/, ""))}Options`;
}

export default Component.extend({
layout,

@@ -13,23 +18,26 @@ export default Component.extend({

value: computed("field.answer.value", function() {
const field = this.get("field");
const options = field.question[getOptionKey(field.question.__typename)];

switch (field.question.__typename) {
case "ChoiceQuestion": {
const option = field.question.choiceOptions.edges.find(
case "ChoiceQuestion":
case "DynamicChoiceQuestion": {
const option = options.edges.find(
edge => edge.node.slug === field.answer.value
);
return { label: option ? option.node.label : field.answer.value };
}
case "MultipleChoiceQuestion": {
case "MultipleChoiceQuestion":
case "DynamicMultipleChoiceQuestion": {
const answerValue = field.answer.value || [];
const options = field.question.multipleChoiceOptions.edges.filter(
edge => answerValue.includes(edge.node.slug)
const selectedOptions = options.edges.filter(edge =>
answerValue.includes(edge.node.slug)
);
return {
label:
options && options.length
? options.map(edge => edge.node.label).join(", ")
selectedOptions && selectedOptions.length
? selectedOptions.map(edge => edge.node.label).join(", ")
: answerValue.join(", ")
};
}

0 comments on commit 5d40c13

Please sign in to comment.
You can’t perform that action at this time.