@builttocreate/engine-utils 2.8.0-beta.12 → 2.8.0-beta.14
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.
- package/dist/joyDocHelper.js +7 -53
- package/package.json +1 -1
package/dist/joyDocHelper.js
CHANGED
|
@@ -101,7 +101,8 @@ var getDefaultJoyDoc = exports.getDefaultJoyDoc = function getDefaultJoyDoc() {
|
|
|
101
101
|
*/
|
|
102
102
|
var getCleanedJoyDoc = exports.getCleanedJoyDoc = function getCleanedJoyDoc(doc) {
|
|
103
103
|
if (!doc) return getDefaultJoyDoc();
|
|
104
|
-
var
|
|
104
|
+
var cleanedDoc = removeOrphanedFieldsFromJoydoc(doc);
|
|
105
|
+
var nextDoc = cleanedDoc.doc;
|
|
105
106
|
|
|
106
107
|
/**
|
|
107
108
|
* Step 1.1: Replace doc._id if it is not valid
|
|
@@ -161,58 +162,9 @@ var getCleanedJoyDoc = exports.getCleanedJoyDoc = function getCleanedJoyDoc(doc)
|
|
|
161
162
|
* Remove orphaned fields from doc
|
|
162
163
|
*/
|
|
163
164
|
|
|
164
|
-
// export const removeOrphanedFieldsFromJoydoc = (doc) => {
|
|
165
|
-
|
|
166
|
-
// const nextDoc = { ...doc };
|
|
167
|
-
|
|
168
|
-
// /**
|
|
169
|
-
// * Logic below removes orphaned fields (ie fields without fieldPositions)
|
|
170
|
-
// */
|
|
171
|
-
|
|
172
|
-
// nextDoc.fields = nextDoc.fields.filter((field) => {
|
|
173
|
-
|
|
174
|
-
// let isOrphanedField = true;
|
|
175
|
-
|
|
176
|
-
// nextDoc.files.forEach((file) => {
|
|
177
|
-
|
|
178
|
-
// const primaryViewPages = file.pages;
|
|
179
|
-
|
|
180
|
-
// // Check if field is associated with any field positions in primary view pages
|
|
181
|
-
// const isFieldAssociatedWithPrimaryView = primaryViewPages.some((page) => {
|
|
182
|
-
// return page.fieldPositions.some((fieldPosition) => fieldPosition.field === field._id);
|
|
183
|
-
// });
|
|
184
|
-
|
|
185
|
-
// // Check if field is associated with other views
|
|
186
|
-
// let isFieldAssociatedWithAnotherView;
|
|
187
|
-
|
|
188
|
-
// if (file.views && file.views.length > 0) {
|
|
189
|
-
|
|
190
|
-
// isFieldAssociatedWithAnotherView = file.views.some((view) => {
|
|
191
|
-
// return view.pages.some((page) => {
|
|
192
|
-
// return page.fieldPositions.some((fieldPosition) => fieldPosition.field === field._id);
|
|
193
|
-
// });
|
|
194
|
-
// });
|
|
195
|
-
|
|
196
|
-
// }
|
|
197
|
-
|
|
198
|
-
// if (isFieldAssociatedWithPrimaryView || isFieldAssociatedWithAnotherView) {
|
|
199
|
-
// isOrphanedField = false;
|
|
200
|
-
// }
|
|
201
|
-
|
|
202
|
-
// });
|
|
203
|
-
|
|
204
|
-
// if (!isOrphanedField) return field;
|
|
205
|
-
|
|
206
|
-
// return null;
|
|
207
|
-
|
|
208
|
-
// });
|
|
209
|
-
|
|
210
|
-
// return nextDoc;
|
|
211
|
-
|
|
212
|
-
// };
|
|
213
|
-
|
|
214
165
|
var removeOrphanedFieldsFromJoydoc = exports.removeOrphanedFieldsFromJoydoc = function removeOrphanedFieldsFromJoydoc(doc) {
|
|
215
166
|
var _nextDoc$files;
|
|
167
|
+
if (!doc) return getDefaultJoyDoc();
|
|
216
168
|
var nextDoc = _objectSpread({}, doc);
|
|
217
169
|
var associatedFieldIdLookup = {};
|
|
218
170
|
nextDoc === null || nextDoc === void 0 ? void 0 : (_nextDoc$files = nextDoc.files) === null || _nextDoc$files === void 0 ? void 0 : _nextDoc$files.forEach(function (file) {
|
|
@@ -248,8 +200,10 @@ var removeOrphanedFieldsFromJoydoc = exports.removeOrphanedFieldsFromJoydoc = fu
|
|
|
248
200
|
if (associatedFieldIdLookup[field._id]) validFields.push(field);else deletedFields.push(field);
|
|
249
201
|
});
|
|
250
202
|
nextDoc.fields = validFields;
|
|
251
|
-
|
|
252
|
-
|
|
203
|
+
return {
|
|
204
|
+
doc: nextDoc,
|
|
205
|
+
deletedFields: deletedFields
|
|
206
|
+
};
|
|
253
207
|
};
|
|
254
208
|
|
|
255
209
|
/**
|