Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] Ability to duplicate fields in blueprint/fieldset builders #8916

Merged
merged 4 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion resources/js/components/blueprints/Fields.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
@updated="$emit('field-updated', i, $event)"
@deleted="$emit('field-deleted', i)"
@editor-closed="$emit('editor-closed')"
@duplicate="duplicateField(field)"
/>
</div>

Expand Down Expand Up @@ -140,7 +141,24 @@ export default {

this.$toast.success(__('Field added'));
this.pendingCreatedField = null;
}
},

duplicateField(field) {
let handle = `${field.handle}_duplicate`;
let display = field.config.display ? `${field.config.display} (Duplicate)` : `${field.handle} (Duplicate)`;

let pending = {
...field,
_id: uniqid(),
handle: handle,
config: {
...field.config,
display,
}
};

this.$nextTick(() => this.pendingCreatedField = pending);
},

}

Expand Down
5 changes: 4 additions & 1 deletion resources/js/components/blueprints/RegularField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
>
<svg-icon name="light/earth" class="h-4 w-4" />
</button>
<button @click.prevent="$emit('deleted')" class="text-gray-600 hover:text-gray-950 flex items-center">
<button @click.prevent="$emit('duplicate')" class="text-gray-600 hover:text-gray-950 flex items-center mr-2" v-tooltip="__('Duplicate')">
<svg-icon name="light/duplicate" class="h-4 w-4" />
</button>
<button @click.prevent="$emit('deleted')" class="text-gray-600 hover:text-gray-950 flex items-center" v-tooltip="__('Remove')">
<svg-icon name="micro/trash" class="h-4 w-4" />
</button>
<stack name="field-settings" v-if="isEditing" @closed="editorClosed">
Expand Down
1 change: 1 addition & 0 deletions resources/svg/icons/light/duplicate.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading