Skip to content

Commit 8b02ee0

Browse files
jaygeorgeclaudejasonvarga
authored
[6.x] Apply regenerate handle pattern for replicator sections (#14745)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Jason Varga <jason@pixelfear.com>
1 parent f909e18 commit 8b02ee0

2 files changed

Lines changed: 42 additions & 18 deletions

File tree

resources/js/components/blueprints/Section.vue

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,18 @@
5454
class="font-mono text-sm"
5555
v-model="editingSection.handle"
5656
@input="handleSyncedWithDisplay = false"
57-
/>
57+
>
58+
<template #append>
59+
<ui-button
60+
icon="sync"
61+
size="sm"
62+
variant="ghost"
63+
:aria-label="__('Regenerate from: :field', { field: __('Display') })"
64+
@click="regenerateHandle"
65+
v-tooltip="__('Regenerate from: :field', { field: __('Display') })"
66+
/>
67+
</template>
68+
</ui-input>
5869
</ui-field>
5970
<ui-field :label="__('Instructions')">
6071
<ui-input type="text" v-model="editingSection.instructions" />
@@ -219,15 +230,15 @@ export default {
219230
},
220231
},
221232
222-
created() {
223-
// This logic isn't ideal, but it was better than passing along a 'isNew' boolean and having
224-
// to deal with stripping it out and making it not new, etc. Good enough for a quick win.
225-
if (!this.section.handle || this.section.handle == 'new_section' || this.section.handle == 'new_set') {
226-
this.handleSyncedWithDisplay = true;
227-
}
228-
},
229-
230233
methods: {
234+
regenerateHandle() {
235+
if (!this.editingSection) {
236+
return;
237+
}
238+
239+
this.editingSection.handle = snake_case(this.editingSection.display);
240+
},
241+
231242
fieldLinked(field) {
232243
this.section.fields.push(field);
233244
this.$toast.success(__('Field added'));
@@ -250,6 +261,7 @@ export default {
250261
},
251262
252263
edit() {
264+
this.handleSyncedWithDisplay = !this.section.handle || ['new_section', 'new_set'].includes(this.section.handle);
253265
this.editingSection = {
254266
display: this.section.display,
255267
handle: this.section.handle,

resources/js/components/blueprints/Tab.vue

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,18 @@
3232
<Input ref="title" :model-value="display" @update:model-value="fieldUpdated('display', $event)" />
3333
</Field>
3434
<Field :label="__('Handle')" class="form-group field-w-100">
35-
<Input class="font-mono" :model-value="handle" @update:model-value="fieldUpdated('handle', $event)" />
35+
<Input class="font-mono" :model-value="handle" @update:model-value="fieldUpdated('handle', $event)">
36+
<template #append>
37+
<Button
38+
icon="sync"
39+
size="sm"
40+
variant="ghost"
41+
:aria-label="__('Regenerate from: :field', { field: __('Title') })"
42+
@click="regenerateHandle"
43+
v-tooltip="__('Regenerate from: :field', { field: __('Title') })"
44+
/>
45+
</template>
46+
</Input>
3647
</Field>
3748
<Field v-if="showInstructions" :label="__('Instructions')" class="form-group field-w-100">
3849
<Input :model-value="instructions" @update:model-value="fieldUpdated('instructions', $event)" />
@@ -103,14 +114,6 @@ export default {
103114
};
104115
},
105116
106-
created() {
107-
// This logic isn't ideal, but it was better than passing along a 'isNew' boolean and having
108-
// to deal with stripping it out and making it not new, etc. Good enough for a quick win.
109-
if (!this.handle || this.handle == 'new_tab' || this.handle == 'new_set_group') {
110-
this.handleSyncedWithDisplay = true;
111-
}
112-
},
113-
114117
computed: {
115118
isActive() {
116119
return this.currentTab === this.tab._id;
@@ -149,7 +152,16 @@ export default {
149152
},
150153
151154
methods: {
155+
regenerateHandle() {
156+
this.handle = snake_case(this.display);
157+
},
158+
152159
edit() {
160+
this.display = this.tab.display;
161+
this.handle = this.tab.handle;
162+
this.instructions = this.tab.instructions;
163+
this.icon = this.tab.icon;
164+
this.handleSyncedWithDisplay = !this.tab.handle || ['new_tab', 'new_set_group'].includes(this.tab.handle);
153165
this.editing = true;
154166
},
155167

0 commit comments

Comments
 (0)