@projectcaluma/ember-form 11.0.0-beta.36 → 11.0.0-beta.38

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.36",
3
+ "version": "11.0.0-beta.38",
4
4
  "description": "Ember addon for rendering Caluma forms.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -19,7 +19,7 @@
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.36",
22
+ "@projectcaluma/ember-core": "^11.0.0-beta.38",
23
23
  "ember-apollo-client": "~4.0.2",
24
24
  "ember-auto-import": "^2.4.3",
25
25
  "ember-autoresize-modifier": "^0.6.0",
@@ -30,7 +30,7 @@
30
30
  "ember-concurrency": "^2.3.7",
31
31
  "ember-fetch": "^8.1.2",
32
32
  "ember-flatpickr": "^3.2.3",
33
- "ember-in-viewport": "^4.0.2",
33
+ "ember-in-viewport": "^4.1.0",
34
34
  "ember-intl": "^5.7.2",
35
35
  "ember-math-helpers": "^3.0.0",
36
36
  "ember-power-select": "^6.0.1",
@@ -48,8 +48,8 @@
48
48
  "@ember/test-helpers": "2.7.0",
49
49
  "@embroider/test-setup": "1.8.3",
50
50
  "@faker-js/faker": "7.6.0",
51
- "@projectcaluma/ember-testing": "11.0.0-beta.36",
52
- "@projectcaluma/ember-workflow": "^11.0.0-beta.36",
51
+ "@projectcaluma/ember-testing": "11.0.0-beta.38",
52
+ "@projectcaluma/ember-workflow": "^11.0.0-beta.38",
53
53
  "broccoli-asset-rev": "3.0.0",
54
54
  "ember-cli": "4.8.0",
55
55
  "ember-cli-code-coverage": "1.0.3",
@@ -62,19 +62,19 @@
62
62
  "ember-load-initializers": "2.1.2",
63
63
  "ember-qunit": "6.0.0",
64
64
  "ember-resolver": "8.0.3",
65
- "ember-source": "4.8.1",
65
+ "ember-source": "4.8.2",
66
66
  "ember-source-channel-url": "3.0.0",
67
67
  "ember-try": "2.0.0",
68
68
  "loader.js": "4.7.0",
69
- "miragejs": "0.1.45",
69
+ "miragejs": "0.1.46",
70
70
  "npm-run-all": "4.1.5",
71
71
  "qunit": "2.19.3",
72
72
  "qunit-dom": "2.0.0",
73
73
  "uuid": "9.0.0",
74
- "webpack": "5.74.0"
74
+ "webpack": "5.75.0"
75
75
  },
76
76
  "peerDependencies": {
77
- "@projectcaluma/ember-workflow": "^11.0.0-beta.36"
77
+ "@projectcaluma/ember-workflow": "^11.0.0-beta.38"
78
78
  },
79
79
  "peerDependenciesMeta": {
80
80
  "@projectcaluma/ember-workflow": {