From e8f0d8fd15a7fa4ebcc1c1af599aba52a3de409e Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Wed, 1 Nov 2023 23:11:31 +0000 Subject: [PATCH] Ability to duplicate fields in blueprint/fieldset builders --- resources/js/components/blueprints/Fields.vue | 26 ++++++++++++++++++- .../js/components/blueprints/RegularField.vue | 3 +++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/resources/js/components/blueprints/Fields.vue b/resources/js/components/blueprints/Fields.vue index a721b7ce15..0eb161ce9d 100644 --- a/resources/js/components/blueprints/Fields.vue +++ b/resources/js/components/blueprints/Fields.vue @@ -21,6 +21,7 @@ @updated="$emit('field-updated', i, $event)" @deleted="$emit('field-deleted', i)" @editor-closed="$emit('editor-closed')" + @duplicate="duplicateField(field)" /> @@ -140,7 +141,30 @@ export default { this.$toast.success(__('Field added')); this.pendingCreatedField = null; - } + }, + + duplicateField(field) { + let handle = `${field.handle}-duplicate`; + let counter = 0; + + do { + counter++; + handle = `${field.handle}_duplicate${counter > 1 ? `_${counter}` : ''}`; + } while (this.suggestableConditionFields.includes(handle)); + + let duplicate = { + ...field, + _id: uniqid(), + handle: handle, + config: { + ...field.config, + display: field.config.display ? `${field.config.display} (Duplicate)` : `${field.handle} (Duplicate)`, + } + }; + + this.$emit('field-created', duplicate); + this.$toast.success(__('Field duplicated')); + }, } diff --git a/resources/js/components/blueprints/RegularField.vue b/resources/js/components/blueprints/RegularField.vue index 4142a56a42..86525aeffb 100644 --- a/resources/js/components/blueprints/RegularField.vue +++ b/resources/js/components/blueprints/RegularField.vue @@ -24,6 +24,9 @@ > +