fix: edit cookbooks in a dialog like when creating them (#8950)

Co-authored-by: 菅野谷省吾 <syogosuganoya@Mac-Studio.local>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-11-28 16:26:33 +00:00
1 parent 8038009a45
commit 28dc998a2c
3 files changed
+115 -68

No files matched your search

@@ -0,0 +1,45 @@
import { mount } from "@vue/test-utils";
import { describe, expect, test } from "vitest";
import BaseDialog from "./BaseDialog.vue";
function mountDialog(props: Record<string, unknown>) {
return mount(BaseDialog, {
props: { modelValue: true, ...props },
global: {
mocks: {
$vuetify: { display: { xs: false } },
},
stubs: {
// the keydown listener falls through to this element
VDialog: { template: "<div class=\"dialog\"><slot /></div>" },
BaseDialogContent: { template: "<div><slot /></div>" },
},
},
});
}
describe("BaseDialog submit on Enter", () => {
test("submits when submit is enabled", async () => {
const wrapper = mountDialog({ canSubmit: true });
await wrapper.find(".dialog").trigger("keydown", { key: "Enter" });
expect(wrapper.emitted("submit")).toHaveLength(1);
});
test("does not submit when submit is disabled", async () => {
const wrapper = mountDialog({ canSubmit: true, submitDisabled: true });
await wrapper.find(".dialog").trigger("keydown", { key: "Enter" });
expect(wrapper.emitted("submit")).toBeUndefined();
});
test("does not confirm when submit is disabled", async () => {
const wrapper = mountDialog({ canConfirm: true, submitDisabled: true });
await wrapper.find(".dialog").trigger("keydown", { key: "Enter" });
expect(wrapper.emitted("confirm")).toBeUndefined();
});
test("does not submit when submit on Enter is turned off", async () => {
const wrapper = mountDialog({ canSubmit: true, disableSubmitOnEnter: true });
await wrapper.find(".dialog").trigger("keydown", { key: "Enter" });
expect(wrapper.emitted("submit")).toBeUndefined();
});
});
@@ -144,15 +144,14 @@ function submitEvent() {
}
function submitOnEnter() {
if (props.disableSubmitOnEnter) {
// Enter must respect submitDisabled like the buttons do, for both confirm and submit dialogs
if (props.disableSubmitOnEnter || props.submitDisabled) {
return;
}
if (props.canConfirm) {
if (!props.submitDisabled) {
emit("confirm");
dialog.value = false;
}
emit("confirm");
dialog.value = false;
return;
}
@@ -10,7 +10,7 @@
:title="$t('cookbook.create-a-cookbook')"
:submit-icon="$globals.icons.save"
:submit-text="$t('general.save')"
:submit-disabled="!createTarget.queryFilterString"
:submit-disabled="!createTarget.name?.trim() || !createTarget.queryFilterString"
can-submit
disable-submit-on-enter
@submit="actions.updateOne(createTarget)"
@@ -21,6 +21,27 @@
</v-card-text>
</BaseDialog>
<!-- Edit Dialog -->
<BaseDialog
v-if="editTarget"
v-model="dialogStates.edit"
width="100%"
max-width="1100px"
:icon="$globals.icons.pages"
:title="$t('general.edit')"
:submit-icon="$globals.icons.save"
:submit-text="$t('general.save')"
:submit-disabled="!editTarget.name?.trim() || !editTarget.queryFilterString"
can-submit
can-delete
@submit="actions.updateOne(editTarget)"
@delete="deleteEventHandler(editTarget)"
>
<v-card-text>
<CookbookEditor v-model="editTarget" />
</v-card-text>
</BaseDialog>
<!-- Delete Dialog -->
<BaseDialog
v-model="dialogStates.delete"
@@ -70,69 +91,42 @@
<BaseButton create @click="createCookbook" />
<!-- Cookbook List -->
<v-expansion-panels class="mt-2">
<VueDraggable
v-model="myCookbooks"
handle=".handle"
:delay="250"
:delay-on-touch-only="true"
style="width: 100%"
@end="updateAll(myCookbooks)"
<VueDraggable
v-model="myCookbooks"
handle=".handle"
:delay="250"
:delay-on-touch-only="true"
class="mt-2"
@end="updateAll(myCookbooks)"
>
<v-card
v-for="cookbook in myCookbooks"
:key="cookbook.id"
class="my-2 left-border"
>
<v-expansion-panel
v-for="(cookbook, index) in myCookbooks"
:key="cookbook.id"
class="my-2 left-border rounded"
>
<v-expansion-panel-title disable-icon-rotate class="text-h6 opacity-80">
<div class="d-flex align-center">
<v-icon size="large" start>
{{ $globals.icons.pages }}
</v-icon>
{{ cookbook.name }}
</div>
<template #actions>
<div class="d-flex align-center">
<v-btn icon variant="text" class="ml-2">
<v-icon>
{{ $globals.icons.edit }}
</v-icon>
</v-btn>
<v-icon class="handle" :size="40">
{{ $globals.icons.arrowUpDown }}
</v-icon>
</div>
</template>
</v-expansion-panel-title>
<v-expansion-panel-text>
<CookbookEditor
v-model="myCookbooks[index]"
:collapsable="false"
/>
<v-card-actions>
<v-spacer />
<BaseButtonGroup
:buttons="[
{
icon: $globals.icons.delete,
text: $t('general.delete'),
event: 'delete',
},
{
icon: $globals.icons.save,
text: $t('general.save'),
event: 'save',
disabled: !cookbook.queryFilterString,
},
]"
@delete="deleteEventHandler(myCookbooks[index])"
@save="actions.updateOne(myCookbooks[index])"
/>
</v-card-actions>
</v-expansion-panel-text>
</v-expansion-panel>
</VueDraggable>
</v-expansion-panels>
<v-card-title class="d-flex align-center text-h6 opacity-80">
<v-icon size="large" start>
{{ $globals.icons.pages }}
</v-icon>
{{ cookbook.name }}
<v-spacer />
<v-btn
icon
variant="text"
class="ml-2"
:title="$t('general.edit')"
@click="editEventHandler(cookbook)"
>
<v-icon>
{{ $globals.icons.edit }}
</v-icon>
</v-btn>
<v-icon class="handle" :size="40">
{{ $globals.icons.arrowUpDown }}
</v-icon>
</v-card-title>
</v-card>
</VueDraggable>
</v-container>
</div>
</template>
@@ -151,6 +145,7 @@ definePageMeta({
const dialogStates = reactive({
create: false,
edit: false,
delete: false,
});
@@ -202,6 +197,14 @@ async function createCookbook() {
dialogStates.create = true;
}
// edit
const editTarget = ref<CookBookOut | null>(null);
function editEventHandler(item: CookBookOut) {
// edit a copy, so cancelling the dialog discards the changes
editTarget.value = structuredClone(toRaw(item));
dialogStates.edit = true;
}
// delete
const deleteTarget = ref<CookBookOut | null>(null);
function deleteEventHandler(item: CookBookOut) {