Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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