Skip to content

Commit

Permalink
fix(table): fix table rendering for dynamic choice fields (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
czosel authored May 15, 2019
1 parent b865220 commit 5d40c13
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions addon/components/cf-field-value.js
Original file line number Diff line number Diff line change
@@ -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,

Expand All @@ -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(", ")
};
}
Expand Down

0 comments on commit 5d40c13

Please sign in to comment.