Skip to content

Commit

Permalink
fix(form): fix loading of subforms and improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Metzener authored and anehx committed Jun 24, 2019
1 parent f38ccce commit b47cd4d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
14 changes: 10 additions & 4 deletions addon/components/cf-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { later, once } from "@ember/runloop";

import getNavigationDocumentsQuery from "ember-caluma/gql/queries/get-navigation-documents";
import getNavigationFormsQuery from "ember-caluma/gql/queries/get-navigation-forms";
import { assert } from "@ember/debug";

const isDisplayableDocument = doc =>
doc &&
Expand Down Expand Up @@ -38,11 +39,16 @@ const buildTree = (rootDocument, documents, forms) => {

rootDocument.answers.edges.forEach(answer => {
if (answer.node.__typename === "FormAnswer") {
answer.node.formValue = buildTree(
documents.find(doc => doc.form.slug === answer.node.question.slug),
documents,
forms
const childDocument = documents.find(
doc => doc.form.slug === answer.node.question.subForm.slug
);

assert(
`Document for form "${answer.node.question.subForm.slug}" not found`,
childDocument
);

answer.node.formValue = buildTree(childDocument, documents, forms);
}
});

Expand Down
10 changes: 10 additions & 0 deletions addon/gql/fragments/field-answer.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ fragment SimpleAnswer on Answer {
... on DateAnswer {
dateValue: value
}
... on FormAnswer {
question {
slug
... on FormQuestion {
subForm {
slug
}
}
}
}
}

fragment FieldAnswer on Answer {
Expand Down

0 comments on commit b47cd4d

Please sign in to comment.