feat(19.6.1-05): persist picked relation labels across FormView tab remount

- FORM_REMEMBER_LABEL inject so hosts keep picked option names
- RelationField choose() writes the label before emit
- Vitest backstops remount and tab-switch labeling

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jakub Zych
2026-10-22 14:40:35 +02:00
parent ba0501c274
commit 14baafb27c
6 changed files with 122 additions and 4 deletions

View File

@@ -4,7 +4,7 @@ import { onBeforeRouteLeave, onBeforeRouteUpdate, useRoute, useRouter } from 'vu
import { ArrowLeft, Trash2 } from '@lucide/vue'
import { api } from '../api/client'
import { parentFileRoutes } from '../api/files'
import type { AdminRecord, ErrorEnvelope, FormView, RecordEnvelope, RecordMeta } from '../api/types'
import type { AdminRecord, ErrorEnvelope, FormView, RecordEnvelope, RecordMeta, RelationOption } from '../api/types'
import { controllerIdFromParams, controllerPath } from '../app/controllerRoutes'
import { currentLocale, message, t } from '../app/i18n'
import { loadControllerAssets } from '../app/pluginAssets'
@@ -21,6 +21,7 @@ import {
FORM_LOCALE,
FORM_PATCH,
FORM_PERMISSION_LOCKS,
FORM_REMEMBER_LABEL,
FORM_SESSION,
FORM_TRIGGER_NOTES,
FORM_VALUES,
@@ -247,6 +248,18 @@ function adopt(record: RecordEnvelope | undefined): void {
saved.value = snapshot(editablePayload(fields.value, values.value, mode, permissionLocks.value))
}
function rememberRelationLabel(field: string, option: RelationOption): void {
const current = labels.value[field] ?? []
const index = current.findIndex((item) => item.value === option.value)
const next = [...current]
if (index >= 0) {
next[index] = option
} else {
next.push(option)
}
labels.value = { ...labels.value, [field]: next }
}
async function load(): Promise<void> {
loading.value = true
failed.value = false
@@ -336,6 +349,7 @@ function update(name: string, value: unknown): void {
// that field's errors like an edit (D-07, D-08).
provide(FORM_VALUES, computed(() => values.value))
provide(FORM_PATCH, update)
provide(FORM_REMEMBER_LABEL, rememberRelationLabel)
provide(FORM_LOCALE, computed(() => schema.value?.meta.locale || currentLocale.value))
provide(FORM_ENABLED_LOCALES, computed(() => schemaEnabledLocales(schema.value?.meta)))
provide(FORM_ASSETS, () => assetsReady)