@builttocreate/engine-utils 2.10.1-beta.v593.25 → 2.10.1-beta.v593.26
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/generateReadableId.js +29 -14
- package/package.json +1 -1
|
@@ -114,23 +114,38 @@ function generateReadableId(parts, type) {
|
|
|
114
114
|
throw new Error('generateReadableId: at least one of fields, pages, or views is required');
|
|
115
115
|
}
|
|
116
116
|
if (!fields) console.warn('generateReadableId: fields parameter is missing');
|
|
117
|
-
var count = 0;
|
|
118
|
-
if (fields) count += getFieldsCount(fields, type);
|
|
119
|
-
// Note: leaving for now until we allow targeting fieldPositions
|
|
120
|
-
// if (pages) count += getFieldPositionsCount(pages, type);
|
|
121
|
-
// if (views && views.length > 1) count += getViewsFieldPositionsCount(views, type);
|
|
122
117
|
|
|
123
|
-
|
|
124
|
-
count++;
|
|
118
|
+
// let count = 0;
|
|
125
119
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
120
|
+
// if (fields) count += getFieldsCount(fields, type);
|
|
121
|
+
// // Note: leaving for now until we allow targeting fieldPositions
|
|
122
|
+
// // if (pages) count += getFieldPositionsCount(pages, type);
|
|
123
|
+
// // if (views && views.length > 1) count += getViewsFieldPositionsCount(views, type);
|
|
130
124
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
125
|
+
// let readableId = `${type}${splitterId}${count + 1}`
|
|
126
|
+
// count++;
|
|
127
|
+
|
|
128
|
+
// /**
|
|
129
|
+
// * If the user drags one text field and renames it to text 2, we need to ensure
|
|
130
|
+
// * the newly generatedId is different than text2
|
|
131
|
+
// * */
|
|
132
|
+
|
|
133
|
+
// fields.forEach((field ) => {
|
|
134
|
+
|
|
135
|
+
// if(field._id === readableId) readableId = `${type}${splitterId}${count + 1}`
|
|
136
|
+
|
|
137
|
+
// })
|
|
138
|
+
|
|
139
|
+
// return readableId;
|
|
140
|
+
|
|
141
|
+
var count = fields.length ? getFieldsCount(fields, type) : 0;
|
|
142
|
+
var readableId = "".concat(type).concat(splitterId).concat(count + 1);
|
|
143
|
+
while (fields.some(function (field) {
|
|
144
|
+
return field._id === readableId;
|
|
145
|
+
})) {
|
|
146
|
+
count++;
|
|
147
|
+
readableId = "".concat(type).concat(splitterId).concat(count + 1);
|
|
148
|
+
}
|
|
134
149
|
return readableId;
|
|
135
150
|
}
|
|
136
151
|
;
|