Skip to content

Commit 0e597c1

Browse files
committed
chore: refactor, add more properties
1 parent 16253b2 commit 0e597c1

File tree

8 files changed

+167
-36
lines changed

8 files changed

+167
-36
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
fragment CaseFormAndWorkflow on Case {
2+
id
3+
workflow {
4+
id
5+
slug
6+
}
7+
document {
8+
id
9+
form {
10+
id
11+
slug
12+
}
13+
}
14+
family {
15+
id
16+
workflow {
17+
id
18+
slug
19+
}
20+
document {
21+
id
22+
form {
23+
id
24+
slug
25+
}
26+
}
27+
}
28+
}

packages/form/addon/gql/queries/document-answers.graphql

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#import * from '../fragments/field.graphql'
2+
#import * from '../fragments/case-form-and-workflow.graphql'
23

34
query DocumentAnswers($id: ID!) {
45
allDocuments(filter: [{ id: $id }]) {
@@ -12,21 +13,11 @@ query DocumentAnswers($id: ID!) {
1213
workItem {
1314
id
1415
case {
15-
id
16-
family {
17-
id
18-
document {
19-
id
20-
form {
21-
id
22-
slug
23-
}
24-
}
25-
}
16+
...CaseFormAndWorkflow
2617
}
2718
}
2819
case {
29-
id
20+
...CaseFormAndWorkflow
3021
workItems {
3122
edges {
3223
node {

packages/form/addon/lib/document.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ export default class Document extends Base {
198198
* @property {Object} jexlContext
199199
*/
200200
get jexlContext() {
201+
const _case = this.raw.workItem?.case ?? this.raw.case;
201202
return (
202203
this.parentDocument?.jexlContext ?? {
203204
// JEXL interprets null in an expression as variable instead of a
@@ -209,6 +210,14 @@ export default class Document extends Base {
209210
form: this.rootForm.slug,
210211
formMeta: this.rootForm.raw.meta,
211212
},
213+
case: {
214+
form: _case?.document?.form.slug,
215+
workflow: _case?.workflow.slug,
216+
root: {
217+
form: _case?.family.document?.form.slug,
218+
workflow: _case?.family.workflow.slug,
219+
},
220+
},
212221
},
213222
}
214223
);

packages/form/addon/lib/field.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,27 +413,26 @@ export default class Field extends Base {
413413
* - `form`: Legacy property pointing to the root form.
414414
* - `info.form`: The form this question is attached to.
415415
* - `info.formMeta`: The meta of the form this question is attached to.
416-
* - `info.mainCaseForm`: The main cases' form (can give useful context in task forms).
417416
* - `info.parent.form`: The parent form if applicable.
418417
* - `info.parent.formMeta`: The parent form meta if applicable.
419418
* - `info.root.form`: The new property for the root form.
420419
* - `info.root.formMeta`: The new property for the root form meta.
420+
* - `info.case.form`: The cases' form (works for task forms and case forms).
421+
* - `info.case.workflow`: The cases' workflow (works for task forms and case forms).
422+
* - `info.case.root.form`: The _root_ cases' form (works for task forms and case forms).
423+
* - `info.case.root.workflow`: The _root_ cases' workflow (works for task forms and case forms).
421424
*
422425
* @property {Object} jexlContext
423426
*/
424427
get jexlContext() {
425428
const parent = this.fieldset.field?.fieldset.form;
426429

427-
const rootDocument = this.document.parentDocument ?? this.document;
428-
429430
return {
430431
...this.document.jexlContext,
431432
info: {
432433
...this.document.jexlContext.info,
433434
form: this.fieldset.form.slug,
434435
formMeta: this.fieldset.form.raw.meta,
435-
mainCaseForm:
436-
rootDocument.raw.workItem?.case.family.document?.form.slug,
437436
parent: parent
438437
? {
439438
form: parent.slug,

packages/form/tests/integration/components/document-validity-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { hbs } from "ember-cli-htmlbars";
33
import { setupMirage } from "ember-cli-mirage/test-support";
44
import { module, test } from "qunit";
55

6-
import data from "../../unit/lib/data";
6+
import { rawDocumentWithWorkItem } from "../../unit/lib/data";
77

88
import { parseDocument } from "@projectcaluma/ember-form/lib/parsers";
99
import { setupRenderingTest } from "dummy/tests/helpers";
@@ -14,7 +14,7 @@ module("Integration | Component | document-validity", function (hooks) {
1414

1515
hooks.beforeEach(function () {
1616
this.document = new (this.owner.factoryFor("caluma-model:document").class)({
17-
raw: parseDocument(data),
17+
raw: parseDocument(rawDocumentWithWorkItem),
1818
owner: this.owner,
1919
});
2020

packages/form/tests/unit/lib/data.js

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -236,26 +236,59 @@ const answers = {
236236
],
237237
};
238238

239-
const workItem = {
240-
id: id("WorkItem"),
241-
case: {
239+
const _case = {
240+
id: id("Case"),
241+
workflow: {
242+
id: id("Workflow", "child-case-workflow"),
243+
slug: "child-case-workflow",
244+
},
245+
document: {
246+
id: id("Document"),
247+
form: {
248+
id: id("Form", "child-case-form"),
249+
slug: "child-case-form",
250+
},
251+
},
252+
family: {
242253
id: id("Case"),
243-
family: {
244-
id: id("Case"),
245-
document: {
246-
id: id("Document"),
247-
form: {
248-
slug: "main-case-form",
249-
},
254+
workflow: {
255+
id: id("Workflow", "root-case-workflow"),
256+
slug: "root-case-workflow",
257+
},
258+
document: {
259+
id: id("Document"),
260+
form: {
261+
id: id("Form", "root-case-form"),
262+
slug: "root-case-form",
250263
},
251264
},
252265
},
253266
};
254267

255-
export default {
268+
const workItem = {
269+
id: id("WorkItem"),
270+
case: _case,
271+
};
272+
273+
export const rawDocumentWithCase = {
274+
id: id("Document"),
275+
answers,
276+
form,
277+
case: _case,
278+
__typename: "Document",
279+
};
280+
281+
export const rawDocumentWithWorkItem = {
256282
id: id("Document"),
257283
answers,
258284
form,
259285
workItem,
260286
__typename: "Document",
261287
};
288+
289+
export const rawUnlinkedDocument = {
290+
id: id("Document"),
291+
answers,
292+
form,
293+
__typename: "Document",
294+
};

packages/form/tests/unit/lib/document-test.js

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { settled } from "@ember/test-helpers";
22
import { module, test, skip } from "qunit";
33

4-
import data from "./data";
4+
import {
5+
rawDocumentWithCase,
6+
rawDocumentWithWorkItem,
7+
rawUnlinkedDocument,
8+
} from "./data";
59

610
import { parseDocument } from "@projectcaluma/ember-form/lib/parsers";
711
import { setupTest } from "dummy/tests/helpers";
@@ -23,7 +27,7 @@ module("Unit | Library | document", function (hooks) {
2327
this.set(
2428
"document",
2529
new (this.owner.factoryFor("caluma-model:document").class)({
26-
raw: parseDocument(data),
30+
raw: parseDocument(rawDocumentWithWorkItem),
2731
owner: this.owner,
2832
}),
2933
);
@@ -261,13 +265,73 @@ module("Unit | Library | document", function (hooks) {
261265
);
262266
});
263267

264-
test("computes the correct jexl context", async function (assert) {
268+
test("computes the correct jexl context (task form)", async function (assert) {
265269
assert.expect(1);
266270

267271
assert.deepEqual(this.document.jexlContext, {
268272
null: null,
269273
form: "form",
270274
info: {
275+
case: {
276+
form: "child-case-form",
277+
root: {
278+
form: "root-case-form",
279+
workflow: "root-case-workflow",
280+
},
281+
workflow: "child-case-workflow",
282+
},
283+
root: { form: "form", formMeta: { "is-top-form": true, level: 0 } },
284+
},
285+
});
286+
});
287+
288+
test("computes the correct jexl context (case form)", async function (assert) {
289+
assert.expect(1);
290+
291+
const documentWithCase = new (this.owner.factoryFor(
292+
"caluma-model:document",
293+
).class)({
294+
raw: parseDocument(rawDocumentWithCase),
295+
owner: this.owner,
296+
});
297+
assert.deepEqual(documentWithCase.jexlContext, {
298+
null: null,
299+
form: "form",
300+
info: {
301+
case: {
302+
form: "child-case-form",
303+
root: {
304+
form: "root-case-form",
305+
workflow: "root-case-workflow",
306+
},
307+
workflow: "child-case-workflow",
308+
},
309+
root: { form: "form", formMeta: { "is-top-form": true, level: 0 } },
310+
},
311+
});
312+
});
313+
314+
test("computes the correct jexl context (unlinked document)", async function (assert) {
315+
assert.expect(1);
316+
317+
const documentWithCase = new (this.owner.factoryFor(
318+
"caluma-model:document",
319+
).class)({
320+
raw: parseDocument(rawUnlinkedDocument),
321+
owner: this.owner,
322+
});
323+
assert.deepEqual(documentWithCase.jexlContext, {
324+
null: null,
325+
form: "form",
326+
info: {
327+
case: {
328+
form: undefined,
329+
root: {
330+
form: undefined,
331+
workflow: undefined,
332+
},
333+
workflow: undefined,
334+
},
271335
root: { form: "form", formMeta: { "is-top-form": true, level: 0 } },
272336
},
273337
});

packages/form/tests/unit/lib/field-test.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { setupMirage } from "ember-cli-mirage/test-support";
33
import { setupIntl } from "ember-intl/test-support";
44
import { module, test } from "qunit";
55

6-
import data from "./data";
6+
import { rawDocumentWithWorkItem } from "./data";
77

88
import { getDependenciesFromJexl } from "@projectcaluma/ember-form/lib/dependencies";
99
import { parseDocument } from "@projectcaluma/ember-form/lib/parsers";
@@ -18,7 +18,7 @@ module("Unit | Library | field", function (hooks) {
1818
this.set(
1919
"document",
2020
new (this.owner.factoryFor("caluma-model:document").class)({
21-
raw: parseDocument(data),
21+
raw: parseDocument(rawDocumentWithWorkItem),
2222
owner: this.owner,
2323
}),
2424
);
@@ -146,7 +146,6 @@ module("Unit | Library | field", function (hooks) {
146146
"is-top-form": false,
147147
level: 1,
148148
},
149-
mainCaseForm: "main-case-form",
150149
parent: null,
151150
root: {
152151
form: "form",
@@ -155,6 +154,14 @@ module("Unit | Library | field", function (hooks) {
155154
level: 0,
156155
},
157156
},
157+
case: {
158+
form: "child-case-form",
159+
workflow: "child-case-workflow",
160+
root: {
161+
form: "root-case-form",
162+
workflow: "root-case-workflow",
163+
},
164+
},
158165
},
159166
});
160167
});

0 commit comments

Comments
 (0)