feat(mail): one admin record per mail template with a locale switcher

Gap G-35-1 (supersedes D-05), tracer slice:
- postcard: migration 202611130001_mail_template_base_code (base_code
  column and index); SyncIndex writes base_code; EnsureLocaleRows creates
  the <template>-<locale> rows of locales that ship no file; TemplateBase
  and Catalog.TemplateFor; send, preview and validation resolve a missing
  <template>-<locale> to the locale's customization, else the base's
  customization, else the base file. Names with their own file send as
  before.
- cabana: mail locales are the translator's plus the TranslationWriter's
  enabled locales; sync ensures the locale rows and re-syncs when the
  locale set changes; record lookups admit fallback-locale rows; the
  record title is the base code; RecordMeta.LocaleVariants
  (RecordLocaleVariant) on the show and update responses.
- admin: LocaleVariantSwitcher in the update form header, from
  meta.localeVariants, behind the unsaved-changes confirm.
- tests: TestMailOverrideSmoke/locale_fallback,
  TestMailScreensSmoke/locales, LocaleVariantSwitcher.test.ts.
This commit is contained in:
Jakub Zych
2026-11-13 20:29:42 +01:00
parent 9afe95ccef
commit 52c9c7eb18
22 changed files with 920 additions and 63 deletions

View File

@@ -0,0 +1,68 @@
<script setup lang="ts">
// The locale switcher of a record with locale versions (meta.localeVariants:
// the mail templates screen). Each version is its own record id; choosing one
// opens it on the same route, behind the form's unsaved-changes confirm. When
// that navigation is refused the selection goes back to the open version.
// Labels and state words come translated from the server.
import { computed, ref, watch } from 'vue'
import { isNavigationFailure, useRoute, useRouter } from 'vue-router'
import type { RecordMeta } from '../../api/types'
import { t } from '../../app/i18n'
type LocaleVariant = NonNullable<RecordMeta['localeVariants']>[number]
const props = defineProps<{ variants: LocaleVariant[]; controlId?: string }>()
const route = useRoute()
const router = useRouter()
const current = computed(() => props.variants.find((variant) => variant.current)?.id ?? props.variants[0]?.id ?? 0)
const selected = ref(current.value)
watch(current, (id) => {
selected.value = id
})
const selectId = computed(() => props.controlId ?? 'locale-variant')
function optionText(variant: LocaleVariant): string {
const states = variant.states ?? []
return states.length > 0 ? `${variant.label} — ${states.join(', ')}` : variant.label
}
async function onChange(event: Event): Promise<void> {
const select = event.target as HTMLSelectElement
const id = Number(select.value)
if (!Number.isFinite(id) || id === current.value) {
return
}
selected.value = id
let failed = false
try {
const result = await router.push({ name: route.name ?? undefined, params: { ...route.params, id: String(id) }, query: route.query })
failed = isNavigationFailure(result)
} catch {
failed = true
}
if (failed) {
selected.value = current.value
select.value = String(current.value)
}
}
</script>
<template>
<div class="flex flex-wrap items-center gap-2">
<label :for="selectId" class="text-[13px] text-muted">{{ t('backend::lang.form.locale_variant') }}</label>
<select
:id="selectId"
data-locale-variant
class="rounded-control border border-border-strong bg-surface px-2 py-1 text-[13px]"
:value="String(selected)"
@change="onChange"
>
<option v-for="variant in variants" :key="variant.id" :value="String(variant.id)" :data-locale="variant.locale">
{{ optionText(variant) }}
</option>
</select>
</div>
</template>