@builttocreate/engine-utils 2.8.0-beta.2 → 2.8.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -97,7 +97,7 @@ var addDocumentDataToActivities = function addDocumentDataToActivities(activitie
97
97
 
98
98
  if (activity.document && activity.document.field) {
99
99
  var docFieldValue = fieldValues[activity.document.field];
100
- var templateField = templateFieldLookup[activity.document.field];
100
+ var templateField = templateFieldLookup[activity.document.field] || {};
101
101
  nextActivity.document.title = templateField.title;
102
102
  nextActivity.document.type = templateField.type;
103
103
  nextActivity.document.columns = templateField.tableColumns;
@@ -173,7 +173,7 @@ var addDocumentDataToActivities = function addDocumentDataToActivities(activitie
173
173
 
174
174
  nextActivity.document.value = _nextDocFieldValue;
175
175
  } //This should handle adding the display value for selection and regular input fields
176
- else {
176
+ else if (templateField.optionsLookup) {
177
177
  var option = templateField.optionsLookup[docFieldValue];
178
178
  nextActivity.document.value = option && option.value ? option.value : docFieldValue;
179
179
  }
@@ -117,6 +117,8 @@ var getDefaultJoyDoc = function getDefaultJoyDoc() {
117
117
  * 2. Valid page inside document file.
118
118
  * 3. All _id's (page, file, page, fieldPosition, field) are in a valid format
119
119
  * 4. Row order of table field is free from duplicate/deletedRow Ids
120
+ * 5. Remove orphaned fields from each page when no fieldPositions exist
121
+ *
120
122
  *
121
123
  * @param {Object} doc
122
124
  * @returns {Object}
@@ -191,6 +193,29 @@ var getCleanedJoyDoc = function getCleanedJoyDoc(doc) {
191
193
  });
192
194
  }
193
195
 
196
+ var fieldsWithFieldPositions = nextDoc.fields.filter(function (field) {
197
+ var _file$views$find;
198
+
199
+ var file = nextDoc.files[fileIndex];
200
+ var primaryViewPages = file.pages; // Check if field is associated with any field positions in primary view pages
201
+
202
+ var isFieldAssociatedWithPrimaryView = primaryViewPages.some(function (page) {
203
+ return page.fieldPositions.some(function (fieldPosition) {
204
+ return fieldPosition.field === field._id;
205
+ });
206
+ });
207
+ var mobileViewPages = file.views.length > 0 ? ((_file$views$find = file.views.find(function (view) {
208
+ return view.type === _FileViews["default"].mobile;
209
+ })) === null || _file$views$find === void 0 ? void 0 : _file$views$find.pages) || [] : null; // Check if field is associated with any field positions in mobile view pages
210
+
211
+ var isFieldAssociatedWithMobileView = mobileViewPages && mobileViewPages.length > 0 ? mobileViewPages.some(function (page) {
212
+ return page.fieldPositions.some(function (fieldPosition) {
213
+ return fieldPosition.field === field._id;
214
+ });
215
+ }) : false;
216
+ return isFieldAssociatedWithPrimaryView || isFieldAssociatedWithMobileView;
217
+ });
218
+ nextDoc.fields = fieldsWithFieldPositions;
194
219
  return nextDoc;
195
220
  };
196
221
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builttocreate/engine-utils",
3
- "version": "2.8.0-beta.2",
3
+ "version": "2.8.0-beta.4",
4
4
  "description": "Utility library for common logic shared across web and mobile",
5
5
  "main": "dist/index.js",
6
6
  "files": [