@projectcaluma/ember-form 11.0.0-beta.37 → 11.0.0-beta.39

Sign up to get free protection for your applications and to get access to all the features.
@@ -158,7 +158,11 @@ export default class CfContentComponent extends Component {
158
158
 
159
159
  const raw = parseDocument({ ...answerDocument, form });
160
160
 
161
- const document = new Document({ raw, owner });
161
+ const document = new Document({
162
+ raw,
163
+ owner,
164
+ dataSourceContext: this.args.context,
165
+ });
162
166
  const navigation = new Navigation({ document, owner });
163
167
 
164
168
  registerDestructor(this, () => {
@@ -1,11 +1,11 @@
1
- query DynamicOptions($question: String!) {
1
+ query DynamicOptions($question: String!, $context: JSONString) {
2
2
  allQuestions(filter: [{ slugs: [$question] }], first: 1) {
3
3
  edges {
4
4
  node {
5
5
  id
6
6
  slug
7
7
  ... on DynamicChoiceQuestion {
8
- dynamicChoiceOptions: options {
8
+ dynamicChoiceOptions: options(context: $context) {
9
9
  edges {
10
10
  node {
11
11
  slug
@@ -15,7 +15,7 @@ query DynamicOptions($question: String!) {
15
15
  }
16
16
  }
17
17
  ... on DynamicMultipleChoiceQuestion {
18
- dynamicMultipleChoiceOptions: options {
18
+ dynamicMultipleChoiceOptions: options(context: $context) {
19
19
  edges {
20
20
  node {
21
21
  slug
@@ -18,7 +18,7 @@ const sum = (nums) => nums.reduce((num, base) => base + num, 0);
18
18
  * @class Document
19
19
  */
20
20
  export default class Document extends Base {
21
- constructor({ raw, parentDocument, ...args }) {
21
+ constructor({ raw, parentDocument, dataSourceContext, ...args }) {
22
22
  assert(
23
23
  "A graphql document `raw` must be passed",
24
24
  raw?.__typename === "Document"
@@ -27,6 +27,7 @@ export default class Document extends Base {
27
27
  super({ raw, ...args });
28
28
 
29
29
  this.parentDocument = parentDocument;
30
+ this.dataSourceContext = dataSourceContext;
30
31
 
31
32
  this.pushIntoStore();
32
33
 
@@ -83,6 +84,13 @@ export default class Document extends Base {
83
84
  */
84
85
  fieldsets = [];
85
86
 
87
+ /**
88
+ * Context object for data sources
89
+ *
90
+ * @property {Object} dataSourceContext
91
+ */
92
+ dataSourceContext = null;
93
+
86
94
  /**
87
95
  * The primary key of the document.
88
96
  *
@@ -89,6 +89,8 @@ export default class Field extends Base {
89
89
  raw: this.raw.question,
90
90
  owner,
91
91
  });
92
+
93
+ this.question.dataSourceContext = this.document.dataSourceContext;
92
94
  }
93
95
 
94
96
  _createAnswer() {
@@ -545,18 +547,24 @@ export default class Field extends Base {
545
547
 
546
548
  const type = this.answer.raw.__typename;
547
549
 
550
+ const value = this.answer.serializedValue;
551
+ const input = {
552
+ question: this.question.slug,
553
+ document: this.document.uuid,
554
+ };
555
+
556
+ if (value !== null) {
557
+ input.value = value;
558
+ }
559
+
560
+ if (this.document.dataSourceContext) {
561
+ input.dataSourceContext = JSON.stringify(this.document.dataSourceContext);
562
+ }
563
+
548
564
  const response = yield this.apollo.mutate(
549
565
  {
550
566
  mutation: MUTATION_MAP[type],
551
- variables: {
552
- input: {
553
- question: this.question.slug,
554
- document: this.document.uuid,
555
- ...(this.answer.serializedValue !== null
556
- ? { value: this.answer.serializedValue }
557
- : {}),
558
- },
559
- },
567
+ variables: { input },
560
568
  },
561
569
  `saveDocument${type}.answer`
562
570
  );
@@ -66,7 +66,12 @@ export default class Question extends Base {
66
66
  {
67
67
  query: getDynamicOptions,
68
68
  fetchPolicy: "network-only",
69
- variables: { question: this.slug },
69
+ variables: {
70
+ question: this.slug,
71
+ context: this.dataSourceContext
72
+ ? JSON.stringify(this.dataSourceContext)
73
+ : null,
74
+ },
70
75
  },
71
76
  "allQuestions.edges"
72
77
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectcaluma/ember-form",
3
- "version": "11.0.0-beta.37",
3
+ "version": "11.0.0-beta.39",
4
4
  "description": "Ember addon for rendering Caluma forms.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -15,11 +15,11 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@ember/string": "^3.0.0",
18
- "@embroider/macros": "^1.9.0",
18
+ "@embroider/macros": "^1.10.0",
19
19
  "@embroider/util": "^1.9.0",
20
20
  "@glimmer/component": "^1.1.2",
21
21
  "@glimmer/tracking": "^1.1.2",
22
- "@projectcaluma/ember-core": "^11.0.0-beta.37",
22
+ "@projectcaluma/ember-core": "^11.0.0-beta.39",
23
23
  "ember-apollo-client": "~4.0.2",
24
24
  "ember-auto-import": "^2.4.3",
25
25
  "ember-autoresize-modifier": "^0.6.0",
@@ -46,10 +46,10 @@
46
46
  "devDependencies": {
47
47
  "@ember/optional-features": "2.0.0",
48
48
  "@ember/test-helpers": "2.7.0",
49
- "@embroider/test-setup": "1.8.3",
49
+ "@embroider/test-setup": "2.0.0",
50
50
  "@faker-js/faker": "7.6.0",
51
- "@projectcaluma/ember-testing": "11.0.0-beta.37",
52
- "@projectcaluma/ember-workflow": "^11.0.0-beta.37",
51
+ "@projectcaluma/ember-testing": "11.0.0-beta.39",
52
+ "@projectcaluma/ember-workflow": "^11.0.0-beta.39",
53
53
  "broccoli-asset-rev": "3.0.0",
54
54
  "ember-cli": "4.8.0",
55
55
  "ember-cli-code-coverage": "1.0.3",
@@ -74,7 +74,7 @@
74
74
  "webpack": "5.75.0"
75
75
  },
76
76
  "peerDependencies": {
77
- "@projectcaluma/ember-workflow": "^11.0.0-beta.37"
77
+ "@projectcaluma/ember-workflow": "^11.0.0-beta.39"
78
78
  },
79
79
  "peerDependenciesMeta": {
80
80
  "@projectcaluma/ember-workflow": {