Skip to content

Commit

Permalink
feat(form): add main cases' form to jexl context
Browse files Browse the repository at this point in the history
  • Loading branch information
czosel committed May 17, 2024
1 parent 791f06a commit 16253b2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/form/addon/gql/queries/document-answers.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ query DocumentAnswers($id: ID!) {
}
workItem {
id
case {
id
family {
id
document {
id
form {
id
slug
}
}
}
}
}
case {
id
Expand Down
5 changes: 5 additions & 0 deletions packages/form/addon/lib/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ export default class Field extends Base {
* - `form`: Legacy property pointing to the root form.
* - `info.form`: The form this question is attached to.
* - `info.formMeta`: The meta of the form this question is attached to.
* - `info.mainCaseForm`: The main cases' form (can give useful context in task forms).
* - `info.parent.form`: The parent form if applicable.
* - `info.parent.formMeta`: The parent form meta if applicable.
* - `info.root.form`: The new property for the root form.
Expand All @@ -423,12 +424,16 @@ export default class Field extends Base {
get jexlContext() {
const parent = this.fieldset.field?.fieldset.form;

const rootDocument = this.document.parentDocument ?? this.document;

return {
...this.document.jexlContext,
info: {
...this.document.jexlContext.info,
form: this.fieldset.form.slug,
formMeta: this.fieldset.form.raw.meta,
mainCaseForm:
rootDocument.raw.workItem?.case.family.document?.form.slug,
parent: parent
? {
form: parent.slug,
Expand Down
17 changes: 17 additions & 0 deletions packages/form/tests/unit/lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,26 @@ const answers = {
],
};

const workItem = {
id: id("WorkItem"),
case: {
id: id("Case"),
family: {
id: id("Case"),
document: {
id: id("Document"),
form: {
slug: "main-case-form",
},
},
},
},
};

export default {
id: id("Document"),
answers,
form,
workItem,
__typename: "Document",
};
1 change: 1 addition & 0 deletions packages/form/tests/unit/lib/field-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ module("Unit | Library | field", function (hooks) {
"is-top-form": false,
level: 1,
},
mainCaseForm: "main-case-form",
parent: null,
root: {
form: "form",
Expand Down

0 comments on commit 16253b2

Please sign in to comment.