@builttocreate/engine-utils 2.10.1-beta.v593.10 → 2.10.1-beta.v593.12
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/fieldHelper.js +40 -1
- package/dist/generateReadableId.js +4 -3
- package/dist/validateReadableId.js +18 -2
- package/package.json +1 -1
package/dist/fieldHelper.js
CHANGED
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.isTargetOptionDeleted = exports.isFieldEmpty = exports.handleMultiSelectOptionToggle = exports.getTemplateWithLookups = exports.getMultiSelectFieldValue = exports.getImportFieldValues = exports.getDefaultOption = exports.getDefaultFieldValuesFromTemplate = exports.getChartFieldValue = exports["default"] = void 0;
|
|
7
|
+
exports.isTargetOptionDeleted = exports.isFieldEmpty = exports.handleMultiSelectOptionToggle = exports.getTemplateWithLookups = exports.getMultiSelectFieldValue = exports.getImportFieldValues = exports.getDefaultOption = exports.getDefaultFieldValuesFromTemplate = exports.getChartFieldValue = exports.flattenSchemaTree = exports["default"] = void 0;
|
|
8
8
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
9
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
10
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
@@ -298,6 +298,45 @@ var isTargetOptionDeleted = exports.isTargetOptionDeleted = function isTargetOpt
|
|
|
298
298
|
var result = !(undeletedOptions.length > 0);
|
|
299
299
|
return result;
|
|
300
300
|
};
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
*
|
|
304
|
+
* Flattens a nested schema tree into an array of objects and adds a depth property to each object.
|
|
305
|
+
*
|
|
306
|
+
* @param {Object} schemaObj
|
|
307
|
+
* @returns {Array} // An array of objects with the schema's id, depth, and other properties.
|
|
308
|
+
*/
|
|
309
|
+
var flattenSchemaTree = exports.flattenSchemaTree = function flattenSchemaTree(schemaObj) {
|
|
310
|
+
var flattened = [];
|
|
311
|
+
|
|
312
|
+
// Recursive function to traverse the tree.
|
|
313
|
+
function traverse(schemaId, depth, parentId) {
|
|
314
|
+
var node = schemaObj[schemaId];
|
|
315
|
+
if (!node) return;
|
|
316
|
+
|
|
317
|
+
// Create a new object that includes the schema's id and its depth.
|
|
318
|
+
flattened.push(_objectSpread({
|
|
319
|
+
id: schemaId,
|
|
320
|
+
parentId: parentId,
|
|
321
|
+
depth: depth
|
|
322
|
+
}, node));
|
|
323
|
+
|
|
324
|
+
// If the node has children, traverse them with increased depth.
|
|
325
|
+
if (node.children && node.children.length > 0) {
|
|
326
|
+
node.children.forEach(function (childId) {
|
|
327
|
+
return traverse(childId, depth + 1, schemaId);
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Find and traverse each root node.
|
|
333
|
+
Object.keys(schemaObj).forEach(function (schemaId) {
|
|
334
|
+
if (schemaObj[schemaId].root) {
|
|
335
|
+
traverse(schemaId, 0);
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
return flattened;
|
|
339
|
+
};
|
|
301
340
|
var _default = exports["default"] = {
|
|
302
341
|
getDefaultOption: getDefaultOption,
|
|
303
342
|
getChartFieldValue: getChartFieldValue,
|
|
@@ -165,10 +165,11 @@ function generateReadableTableColumnId(tableId, tableColumns, columnId) {
|
|
|
165
165
|
var readableId = "".concat(type).concat(counts[type]);
|
|
166
166
|
if (col._id === columnId) {
|
|
167
167
|
/**
|
|
168
|
-
* If the
|
|
169
|
-
* need to
|
|
168
|
+
* If the generatedReadableId is already present in the tableColumns,
|
|
169
|
+
* we need to increment the count until we find a unique ID.
|
|
170
|
+
* This ensures that the new column ID is unique.
|
|
170
171
|
*/
|
|
171
|
-
|
|
172
|
+
validColumns.forEach(function (column) {
|
|
172
173
|
if (column._id === readableId) {
|
|
173
174
|
readableId = "".concat(type).concat(counts[type] + 1);
|
|
174
175
|
}
|
|
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports["default"] = void 0;
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
9
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
10
|
+
var _fieldHelper = require("./fieldHelper");
|
|
11
|
+
var _FieldTypes = require("./FieldTypes.js");
|
|
10
12
|
// Check if value follows a valid readableId pattern for use in JavaScript formulas
|
|
11
13
|
// Note to test this please run npm test src/validateReadableId.test.js
|
|
12
14
|
|
|
@@ -81,7 +83,7 @@ var JOYDOC_PROPERTIES = new Set(['_id', 'identifier', 'name', 'type', 'files', '
|
|
|
81
83
|
* @param {*} readableId - The ID to validate
|
|
82
84
|
* @returns {boolean} - True if valid, false otherwise
|
|
83
85
|
*/
|
|
84
|
-
var _default = exports["default"] = function _default(readableId, fields, tableColumns) {
|
|
86
|
+
var _default = exports["default"] = function _default(readableId, fields, tableColumns, fieldId) {
|
|
85
87
|
// Must be a non-empty string
|
|
86
88
|
if (typeof readableId !== 'string' || readableId.length === 0) {
|
|
87
89
|
console.warn("validateReadableId: Invalid input - expected non-empty string, got ".concat(typeof readableId === 'string' ? 'empty string' : (0, _typeof2["default"])(readableId)));
|
|
@@ -145,13 +147,27 @@ var _default = exports["default"] = function _default(readableId, fields, tableC
|
|
|
145
147
|
|
|
146
148
|
//6. Check for duplicateIds
|
|
147
149
|
if (fields && Array.isArray(fields)) {
|
|
150
|
+
var targetField = fields.find(function (field) {
|
|
151
|
+
return field._id === fieldId;
|
|
152
|
+
});
|
|
148
153
|
var duplicateField = fields.find(function (field) {
|
|
149
|
-
return field._id ===
|
|
154
|
+
return field._id === targetField._id;
|
|
150
155
|
});
|
|
151
156
|
if (duplicateField) {
|
|
152
157
|
console.warn("validateReadableId: \"".concat(readableId, "\" is invalid - it already exists in fields"));
|
|
153
158
|
return false;
|
|
154
159
|
}
|
|
160
|
+
if (targetField.type === _FieldTypes.FieldTypes.collection) {
|
|
161
|
+
//Flatten the schema and check for duplicates
|
|
162
|
+
var flattenedSchema = (0, _fieldHelper.flattenSchemaTree)(targetField.schema);
|
|
163
|
+
var readableIdExists = flattenedSchema.find(function (schema) {
|
|
164
|
+
return schema._id === readableId;
|
|
165
|
+
});
|
|
166
|
+
if (readableIdExists) {
|
|
167
|
+
console.warn("validateReadableId: \"".concat(readableId, "\" is invalid - it already exists in fields"));
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
155
171
|
}
|
|
156
172
|
if (tableColumns && Array.isArray(tableColumns)) {
|
|
157
173
|
var duplicateColumnId = tableColumns.find(function (column) {
|