From c95092903a37159aa73073e31519ed363ed404b7 Mon Sep 17 00:00:00 2001
From: かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>
Date: Sun, 31 Aug 2025 19:53:38 +0900
Subject: refactor(frontend): フロントエンドの型エラー解消（途中まで） (#16477)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* refactor(frontend): フロントエンドの型エラー解消

* fix

---------

Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com>
---
 packages/frontend/src/components/MkFormDialog.vue | 28 +++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

(limited to 'packages/frontend/src/components/MkFormDialog.vue')

diff --git a/packages/frontend/src/components/MkFormDialog.vue b/packages/frontend/src/components/MkFormDialog.vue
index 6ac4441cac..8d697499a5 100644
--- a/packages/frontend/src/components/MkFormDialog.vue
+++ b/packages/frontend/src/components/MkFormDialog.vue
@@ -41,11 +41,11 @@ SPDX-License-Identifier: AGPL-3.0-only
 				</MkSwitch>
 				<MkSelect v-else-if="v.type === 'enum'" v-model="values[k]">
 					<template #label><span v-text="v.label || k"></span><span v-if="v.required === false"> ({{ i18n.ts.optional }})</span></template>
-					<option v-for="option in v.enum" :key="option.value" :value="option.value">{{ option.label }}</option>
+					<option v-for="option in v.enum" :key="getEnumKey(option)" :value="getEnumValue(option)">{{ getEnumLabel(option) }}</option>
 				</MkSelect>
 				<MkRadios v-else-if="v.type === 'radio'" v-model="values[k]">
 					<template #label><span v-text="v.label || k"></span><span v-if="v.required === false"> ({{ i18n.ts.optional }})</span></template>
-					<option v-for="option in v.options" :key="option.value" :value="option.value">{{ option.label }}</option>
+					<option v-for="option in v.options" :key="getRadioKey(option)" :value="option.value">{{ option.label }}</option>
 				</MkRadios>
 				<MkRange v-else-if="v.type === 'range'" v-model="values[k]" :min="v.min" :max="v.max" :step="v.step" :textConverter="v.textConverter">
 					<template #label><span v-text="v.label || k"></span><span v-if="v.required === false"> ({{ i18n.ts.optional }})</span></template>
@@ -77,7 +77,7 @@ import MkRange from './MkRange.vue';
 import MkButton from './MkButton.vue';
 import MkRadios from './MkRadios.vue';
 import XFile from './MkFormDialog.file.vue';
-import type { Form } from '@/utility/form.js';
+import type { EnumItem, Form, RadioFormItem } from '@/utility/form.js';
 import MkModalWindow from '@/components/MkModalWindow.vue';
 import { i18n } from '@/i18n.js';
 
@@ -99,7 +99,11 @@ const dialog = useTemplateRef('dialog');
 const values = reactive({});
 
 for (const item in props.form) {
-	values[item] = props.form[item].default ?? null;
+	if ('default' in props.form[item]) {
+		values[item] = props.form[item].default ?? null;
+	} else {
+		values[item] = null;
+	}
 }
 
 function ok() {
@@ -115,4 +119,20 @@ function cancel() {
 	});
 	dialog.value?.close();
 }
+
+function getEnumLabel(e: EnumItem) {
+	return typeof e === 'string' ? e : e.label;
+}
+
+function getEnumValue(e: EnumItem) {
+	return typeof e === 'string' ? e : e.value;
+}
+
+function getEnumKey(e: EnumItem) {
+	return typeof e === 'string' ? e : typeof e.value === 'string' ? e.value : JSON.stringify(e.value);
+}
+
+function getRadioKey(e: RadioFormItem['options'][number]) {
+	return typeof e.value === 'string' ? e.value : JSON.stringify(e.value);
+}
 </script>
-- 
cgit v1.2.3-freya

