feat(app): editor views tab, drawing upload and cleaning, guarded crops

This commit is contained in:
bchanot committed 2026-11-04 13:02:30 +01:00
1 parent d163b2ce9a
commit 8343528be9
22 files changed
+2164 -4

No files matched your search

@@ -1,14 +1,67 @@
import { useState } from 'react'
import DeleteDialog, {
type DeleteTarget,
} from '@/components/editor/DeleteDialog'
import DetailViewForm from '@/components/editor/views/DetailViewForm'
import DetailViewRow from '@/components/editor/views/DetailViewRow'
import MainViewCard from '@/components/editor/views/MainViewCard'
import { useSheetDocument } from '@/editor/sheetDocument'
import type { EditorTabProps } from '@/editor/tabs'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
/** Placeholder: Lot G replaces the body and keeps the props contract (`EditorTabProps`). */
export default function ViewsTab(_props: EditorTabProps) {
/**
* Vues et illustrations: the main view and its drawing, the detail views (parent, own
* drawing or crop), the upload of a drawing and the frame changes it brings.
*/
export default function ViewsTab({ readOnly }: EditorTabProps) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
const doc = useSheetDocument()
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
const [cropOpen, setCropOpen] = useState<string | null>(null)
const views = doc?.views ?? []
const main = views.find((view) => view.kind === 'main')
const details = views.filter((view) => view.kind === 'detail')
return (
<section
data-testid="editor-tab-views"
aria-label={t('editor.tab.views')}
className="min-h-24"
/>
className="min-h-24 space-y-4"
>
{main?.kind === 'main' && (
<MainViewCard view={main} readOnly={readOnly} />
)}
<h3 className="text-base font-semibold">
{t('editor.views.details_title')}
</h3>
{doc && details.length === 0 && (
<p className="text-sm text-[var(--color-ink-muted)]">
{t('editor.views.empty')}
</p>
)}
<ul className="space-y-3">
{details.map((view) => (
<DetailViewRow
key={view.id}
view={view}
views={views}
readOnly={readOnly}
cropOpen={cropOpen === view.id}
onToggleCrop={() =>
setCropOpen(cropOpen === view.id ? null : view.id)
}
onDelete={() =>
setDeleting({
key: { kind: 'view', id: view.id },
label: view.name[locale],
})
}
/>
))}
</ul>
{doc && !readOnly && <DetailViewForm views={views} />}
<DeleteDialog target={deleting} onClose={() => setDeleting(null)} />
</section>
)
}
@@ -0,0 +1,126 @@
import { useEffect, useRef, useState } from 'react'
import Button from '@/components/ui/Button'
import Dialog from '@/components/ui/Dialog'
import Notice from '@/components/ui/Notice'
import { buildView } from '@/components/catalogue/CatalogueCanvas'
import { composeCleaningPreview } from '@/editor/core/cleaning'
import type { Candidate } from '@/editor/drawingUpload'
import { useT } from '@/i18n/useT'
export interface CleaningDialogProps {
/** null = closed. */
candidate: Candidate | null
onConfirm: () => void
onCancel: () => void
}
/**
* The cleaned drawing the core composed from its own stored text (the uploaded file is
* never rendered), with what the cleaning removes, before the user accepts it.
*/
export default function CleaningDialog({
candidate,
onConfirm,
onCancel,
}: CleaningDialogProps) {
const t = useT()
return (
<Dialog
open={candidate !== null}
onClose={onCancel}
title={t('editor.cleaning.title')}
size="lg"
description={t('editor.cleaning.body')}
>
{candidate && (
<CleaningBody
candidate={candidate}
onConfirm={onConfirm}
onCancel={onCancel}
/>
)}
</Dialog>
)
}
/** Builds the throwaway preview once per candidate and frees it when the dialog closes. */
function useCleanedDrawing(candidate: Candidate) {
const host = useRef<HTMLDivElement | null>(null)
const [failed, setFailed] = useState(false)
useEffect(() => {
const composed = composeCleaningPreview({
stored: candidate.stored,
sha256: candidate.sha256,
})
const built = composed.ok
? buildView(composed.value.preview, composed.value.viewId)
: null
setFailed(!built?.ok)
if (built?.ok) host.current?.replaceChildren(built.svg)
return () => {
if (composed.ok) composed.value.preview.free()
}
}, [candidate])
return { host, failed }
}
function CleaningBody({
candidate,
onConfirm,
onCancel,
}: Omit<CleaningDialogProps, 'candidate'> & { candidate: Candidate }) {
const t = useT()
const { host, failed } = useCleanedDrawing(candidate)
return (
<div className="space-y-3">
<div
ref={host}
role="img"
aria-label={t('editor.cleaning.preview')}
data-testid="cleaning-preview"
className="aspect-[3/2] w-full overflow-hidden rounded-lg border border-[var(--color-border)] bg-white [&>svg]:block [&>svg]:h-full [&>svg]:w-full"
/>
{failed && (
<Notice tone="error">{t('editor.cleaning.preview_failed')}</Notice>
)}
<NameList title={t('editor.cleaning.active')} names={candidate.active} />
<NameList
title={t('editor.cleaning.removed')}
names={candidate.removed}
/>
{candidate.styleRemoved && (
<Notice tone="info">{t('editor.cleaning.style')}</Notice>
)}
<div className="flex flex-wrap justify-end gap-2">
<Button type="button" variant="ghost" onClick={onCancel}>
{t('editor.cleaning.cancel')}
</Button>
<Button type="button" disabled={failed} onClick={onConfirm}>
{t('editor.cleaning.confirm')}
</Button>
</div>
</div>
)
}
function NameList({
title,
names,
}: {
title: string
names: readonly string[]
}) {
if (names.length === 0) return null
return (
<div className="text-sm">
<p className="font-medium">{title}</p>
<ul className="mt-1 list-disc pl-5 text-[var(--color-ink-muted)]">
{names.map((name, index) => (
<li key={`${name}-${index}`}>
<code>{name}</code>
</li>
))}
</ul>
</div>
)
}
@@ -0,0 +1,84 @@
import { useEffect, useRef, useState } from 'react'
import type { ViewBox } from '@faunosteo/core-wasm/types'
import Notice from '@/components/ui/Notice'
import { buildView } from '@/components/catalogue/CatalogueCanvas'
import { useEditorStore } from '@/editor/state/editorStore'
import { useT } from '@/i18n/useT'
interface Frame {
viewBox: string
ratio: string
}
/**
* The parent view as the core composes it, with the crop rectangle over it. The overlay
* is page-drawn and holds numbers only (one rectangle in the composed root's own
* `viewBox`); it draws no annotation. It follows the handle, so an upload shows at once.
*/
export default function CropCanvas({
parentId,
box,
}: {
parentId: string
box: ViewBox | null
}) {
const t = useT()
const preview = useEditorStore((s) => s.preview)
const handleVersion = useEditorStore((s) => s.handleVersion)
const host = useRef<HTMLDivElement | null>(null)
const [frame, setFrame] = useState<Frame | 'failed' | null>(null)
useEffect(() => {
const element = host.current
if (!element || !preview) return
const built = buildView(preview, parentId)
element.replaceChildren(...(built.ok ? [built.svg] : []))
setFrame(
built.ok
? {
viewBox: built.svg.getAttribute('viewBox') ?? '0 0 100 100',
ratio:
built.svg.getAttribute('preserveAspectRatio') ?? 'xMidYMid meet',
}
: 'failed',
)
}, [preview, parentId, handleVersion])
return (
<div className="space-y-2">
<div
role="img"
aria-label={t('editor.views.crop.canvas')}
className="relative aspect-[4/3] w-full overflow-hidden rounded-lg border border-[var(--color-border)] bg-white"
>
<div
ref={host}
data-testid="crop-canvas-drawing"
className="h-full w-full [&>svg]:block [&>svg]:h-full [&>svg]:w-full"
/>
{frame !== null && frame !== 'failed' && box !== null && (
<svg
aria-hidden="true"
data-testid="crop-overlay"
viewBox={frame.viewBox}
preserveAspectRatio={frame.ratio}
className="pointer-events-none absolute inset-0 h-full w-full"
>
<rect
x={box.min_x}
y={box.min_y}
width={Math.max(box.width, 0)}
height={Math.max(box.height, 0)}
fill="none"
stroke="var(--color-accent)"
strokeWidth={2}
strokeDasharray="6 4"
vectorEffect="non-scaling-stroke"
/>
</svg>
)}
</div>
{frame === 'failed' && (
<Notice tone="error">{t('editor.views.crop.canvas_failed')}</Notice>
)}
</div>
)
}
@@ -0,0 +1,160 @@
import { useEffect, useRef, useState } from 'react'
import type { ViewBox } from '@faunosteo/core-wasm/types'
import ActionButton from '@/components/editor/fields/ActionButton'
import DraftField from '@/components/editor/fields/DraftField'
import ReadOnlyValue from '@/components/editor/fields/ReadOnlyValue'
import {
BOX_KEYS,
fieldsOf,
parseBox,
sameBox,
type BoxFields,
} from '@/editor/viewBox'
import { useViewUpdate } from '@/editor/useViewUpdate'
import { useT } from '@/i18n/useT'
import CropCanvas from './CropCanvas'
/**
* The four `view_box` fields as ONE group: leaving the group or Enter proposes all four
* together (a frame change under the geometry check). A refused group stays shown,
* marked « non appliqué », with the refusal naming what it would break.
*/
export default function CropEditor({
viewId,
parentId,
box,
readOnly,
}: {
viewId: string
parentId: string
box: ViewBox | null
readOnly: boolean
}) {
const t = useT()
if (readOnly) {
const fields = fieldsOf(box)
return (
<div className="grid gap-3 sm:grid-cols-4">
{BOX_KEYS.map((key) => (
<ReadOnlyValue
key={key}
id={`view-${viewId}-crop-${key}`}
label={t(`editor.views.crop.${key}`)}
value={fields[key]}
/>
))}
</div>
)
}
return <EditableCrop viewId={viewId} parentId={parentId} box={box} />
}
type Gate = { state: 'applied' } | { state: 'refused' }
function EditableCrop({
viewId,
parentId,
box,
}: {
viewId: string
parentId: string
box: ViewBox | null
}) {
const t = useT()
const views = useViewUpdate()
const saved = fieldsOf(box)
const [draft, setDraft] = useState<BoxFields>(saved)
const [seen, setSeen] = useState<BoxFields>(saved)
const [gate, setGate] = useState<Gate>({ state: 'applied' })
// A new saved box (undo, reload, restore, an accepted apply) replaces what was typed.
if (BOX_KEYS.some((key) => seen[key] !== saved[key])) {
setSeen(saved)
setDraft(saved)
setGate({ state: 'applied' })
}
const apply = (fields: BoxFields): void => {
const parsed = parseBox(fields)
if (!parsed.ok) {
views.reject('crop', `editor.views.crop.${parsed.reason}`)
setGate({ state: 'refused' })
} else if (sameBox(parsed.box, box)) {
views.clear()
setGate({ state: 'applied' })
} else {
const done = views.update('crop', viewId, { view_box: parsed.box }, true)
setGate({ state: done ? 'applied' : 'refused' })
}
}
const latest = useRef({ draft, saved, apply })
useEffect(() => {
latest.current = { draft, saved, apply }
})
useEffect(
() => () => {
const pending = latest.current
if (BOX_KEYS.some((key) => pending.draft[key] !== pending.saved[key])) {
pending.apply(pending.draft)
}
},
[],
)
const shown = parseBox(draft)
const rectangle = shown.ok ? shown.box : box
const revert = () => {
setDraft(saved)
setGate({ state: 'applied' })
views.clear()
}
return (
<div className="grid gap-4 md:grid-cols-2">
<div
role="group"
aria-label={t('editor.views.crop.title')}
className="space-y-3"
onBlur={(event) => {
if (!event.currentTarget.contains(event.relatedTarget)) apply(draft)
}}
onKeyDown={(event) => {
if (
event.key === 'Enter' &&
event.target instanceof HTMLInputElement
) {
apply(draft)
}
}}
>
<p className="text-sm text-[var(--color-ink-muted)]">
{t('editor.views.crop.hint')}
</p>
<div className="grid grid-cols-2 gap-3">
{BOX_KEYS.map((key) => (
<DraftField
key={key}
id={`view-${viewId}-crop-${key}`}
label={t(`editor.views.crop.${key}`)}
value={draft[key]}
onChange={(value) => setDraft({ ...draft, [key]: value })}
/>
))}
</div>
{gate.state === 'refused' && (
<div role="alert" className="space-y-2 text-sm">
<p className="font-medium text-[var(--color-danger-strong)]">
{t('editor.views.crop.not_applied')}
</p>
{views.error('crop') && <p>{views.error('crop')}</p>}
<ActionButton
readOnly={false}
variant="ghost"
size="sm"
onClick={revert}
>
{t('editor.views.crop.revert')}
</ActionButton>
</div>
)}
</div>
<CropCanvas parentId={parentId} box={rectangle} />
</div>
)
}
@@ -0,0 +1,108 @@
import { useState } from 'react'
import type { SheetView } from '@faunosteo/core-wasm/types'
import ActionButton from '@/components/editor/fields/ActionButton'
import DraftField from '@/components/editor/fields/DraftField'
import FormField from '@/components/ui/FormField'
import Select from '@/components/ui/Select'
import { isBlank } from '@/editor/sheetDocument'
import { useEditCommand } from '@/editor/useEditCommand'
import { BOX_KEYS, fieldsOf, parseBox, type BoxFields } from '@/editor/viewBox'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
const EMPTY = { fr: '', en: '', parent: '', ...fieldsOf(null) }
/**
* Adds a detail view: names, parent, and the crop values when it is a crop (all four, or
* none for a view that will carry its own drawing, chosen once it exists).
*/
export default function DetailViewForm({
views,
}: {
views: readonly SheetView[]
}) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
const edit = useEditCommand()
const [form, setForm] = useState(EMPTY)
const set = (patch: Partial<typeof EMPTY>) => setForm({ ...form, ...patch })
const parent =
form.parent || views.find((view) => view.kind === 'main')?.id || ''
const create = () => {
const box = parseBox(form as BoxFields)
if (isBlank(form.fr) || isBlank(form.en) || parent === '') {
return edit.reject('form', 'editor.views.required')
}
if (!box.ok) return edit.reject('form', `editor.views.crop.${box.reason}`)
const added = edit.runNew('form', 'view', (id) => ({
op: 'insert',
element: {
kind: 'view',
value: {
kind: 'detail',
id,
name: { fr: form.fr, en: form.en },
svg_asset_id: null,
view_box: box.box,
parent_view_id: parent,
},
},
}))
if (added) setForm(EMPTY)
return added
}
return (
<div className="space-y-2 rounded-lg border border-dashed border-[var(--color-border)] p-3">
<p className="text-sm font-medium">{t('editor.views.new')}</p>
<div className="grid gap-3 md:grid-cols-3">
<DraftField
id="view-new-fr"
label={t('editor.views.name_fr')}
value={form.fr}
onChange={(fr) => set({ fr })}
/>
<DraftField
id="view-new-en"
label={t('editor.views.name_en')}
value={form.en}
onChange={(en) => set({ en })}
/>
<FormField id="view-new-parent" label={t('editor.views.parent')}>
<Select
id="view-new-parent"
value={parent}
onChange={(e) => set({ parent: e.target.value })}
>
{views.map((view) => (
<option key={view.id} value={view.id}>
{view.name[locale]}
</option>
))}
</Select>
</FormField>
</div>
<p className="text-sm text-[var(--color-ink-muted)]">
{t('editor.views.new_hint')}
</p>
<div className="grid grid-cols-2 gap-3 md:grid-cols-4">
{BOX_KEYS.map((key) => (
<DraftField
key={key}
id={`view-new-crop-${key}`}
label={t(`editor.views.crop.${key}`)}
value={form[key]}
onChange={(value) => set({ [key]: value })}
/>
))}
</div>
{edit.fieldError('form') && (
<p role="alert" className="text-sm text-[var(--color-danger-strong)]">
{edit.fieldError('form')}
</p>
)}
<ActionButton readOnly={false} variant="secondary" onClick={create}>
{t('editor.views.add')}
</ActionButton>
</div>
)
}
@@ -0,0 +1,90 @@
import type { DetailView, SheetView } from '@faunosteo/core-wasm/types'
import ActionButton from '@/components/editor/fields/ActionButton'
import SelectField from '@/components/editor/fields/SelectField'
import { useViewUpdate } from '@/editor/useViewUpdate'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
import CropEditor from './CropEditor'
import ViewDrawing from './ViewDrawing'
import ViewNames from './ViewNames'
/** One detail view: names, parent, own drawing, crop (one crop canvas open at a time). */
export default function DetailViewRow({
view,
views,
readOnly,
cropOpen,
onToggleCrop,
onDelete,
}: {
view: DetailView
views: readonly SheetView[]
readOnly: boolean
cropOpen: boolean
onToggleCrop: () => void
onDelete: () => void
}) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
const edit = useViewUpdate()
const parents = views
.filter((candidate) => candidate.id !== view.id)
.map((candidate) => ({
value: candidate.id,
label: candidate.name[locale],
}))
return (
<li
aria-label={view.name[locale]}
className="space-y-3 rounded-lg border border-[var(--color-border)] p-3"
>
<div className="grid gap-3 md:grid-cols-3">
<ViewNames view={view} readOnly={readOnly} views={edit} />
<SelectField
id={`view-${view.id}-parent`}
label={t('editor.views.parent')}
value={view.parent_view_id}
options={parents}
onCommit={(parent) =>
edit.update('parent', view.id, { parent_view_id: parent }, true)
}
readOnly={readOnly}
error={edit.error('parent')}
/>
</div>
<ViewDrawing view={view} readOnly={readOnly} />
<div className="space-y-2">
<div className="flex items-center justify-between gap-2">
<p className="text-sm font-medium">{t('editor.views.crop.title')}</p>
<ActionButton
readOnly={readOnly}
variant="secondary"
size="sm"
aria-expanded={cropOpen}
onClick={onToggleCrop}
>
{t('editor.views.crop.toggle')}
</ActionButton>
</div>
{(readOnly || cropOpen) && (
<CropEditor
viewId={view.id}
parentId={view.parent_view_id}
box={view.view_box}
readOnly={readOnly}
/>
)}
</div>
<div className="flex justify-end">
<ActionButton
readOnly={readOnly}
variant="danger"
size="sm"
onClick={onDelete}
>
{t('editor.action.delete')}
</ActionButton>
</div>
</li>
)
}
@@ -0,0 +1,31 @@
import type { MainView } from '@faunosteo/core-wasm/types'
import { useViewUpdate } from '@/editor/useViewUpdate'
import { useT } from '@/i18n/useT'
import ViewDrawing from './ViewDrawing'
import ViewNames from './ViewNames'
/** The main view: its names and its drawing (state, detail, « Choisir une illustration »). */
export default function MainViewCard({
view,
readOnly,
}: {
view: MainView
readOnly: boolean
}) {
const t = useT()
const views = useViewUpdate()
return (
<section
aria-labelledby="views-main-title"
className="space-y-3 rounded-lg border border-[var(--color-border)] p-3"
>
<h3 id="views-main-title" className="text-base font-semibold">
{t('editor.views.main_title')}
</h3>
<div className="grid gap-3 md:grid-cols-2">
<ViewNames view={view} readOnly={readOnly} views={views} />
</div>
<ViewDrawing view={view} readOnly={readOnly} />
</section>
)
}
@@ -0,0 +1,140 @@
import { useRef, type ChangeEvent } from 'react'
import type { SheetView } from '@faunosteo/core-wasm/types'
import ActionButton from '@/components/editor/fields/ActionButton'
import Notice from '@/components/ui/Notice'
import { drawingStatusOf, drawingStatusText } from '@/editor/drawingStatus'
import { unmeasuredViews } from '@/editor/issues'
import { useDrawingUpload } from '@/editor/useDrawingUpload'
import { uploadErrorMessage } from '@/editor/uploadMessages'
import { useSheetDocument } from '@/editor/sheetDocument'
import { useEditorStore } from '@/editor/state/editorStore'
import { useViewUpdate } from '@/editor/useViewUpdate'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
import CleaningDialog from './CleaningDialog'
/**
* A view's drawing: its state with the core's detail, the hint when it is not usable,
* « Choisir une illustration » (check, clean, upload, attach) and, on a detail view that
* has its own drawing, the way back to the parent's.
*/
export default function ViewDrawing({
view,
readOnly,
}: {
view: SheetView
readOnly: boolean
}) {
const t = useT()
const state = useEditorStore((s) => s.previewState)
const failures = useEditorStore((s) => s.drawingFailures)
if (!state) return null
const status = drawingStatusOf(view, state, failures)
const inherits = view.kind === 'detail' && status.kind === 'none'
const unmeasured = unmeasuredViews(state).has(view.id)
const unusable = status.kind !== 'ok' && !inherits
return (
<div className="space-y-2" data-testid={`view-${view.id}-drawing`}>
<p className="text-sm font-medium">{t('editor.views.drawing')}</p>
<p className="text-sm text-[var(--color-ink-muted)]">
{inherits
? t('editor.views.drawing.inherited')
: drawingStatusText(t, status)}
</p>
{!readOnly && (unusable || unmeasured) && (
<p className="text-sm text-[var(--color-ink-muted)]">
{t('editor.views.drawing.hint')}
</p>
)}
{unmeasured && (
<p className="text-sm text-[var(--color-ink-muted)]">
{t('editor.views.drawing.unmeasured')}
</p>
)}
<DrawingActions
view={view}
readOnly={readOnly}
ownDrawing={status.kind !== 'none'}
/>
</div>
)
}
function DrawingActions({
view,
readOnly,
ownDrawing,
}: {
view: SheetView
readOnly: boolean
ownDrawing: boolean
}) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
const doc = useSheetDocument()
const input = useRef<HTMLInputElement | null>(null)
const upload = useDrawingUpload(view.id)
const views = useViewUpdate()
const pick = (event: ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0]
event.target.value = ''
if (file) void upload.start(file)
}
const failure =
upload.ui.phase === 'failed'
? uploadErrorMessage(t, upload.ui.error, { doc, locale })
: null
if (readOnly) return null
return (
<>
<div className="flex flex-wrap items-center gap-2">
<input
ref={input}
type="file"
accept=".svg,image/svg+xml"
className="sr-only"
tabIndex={-1}
aria-label={t('editor.views.drawing.file')}
data-testid={`view-${view.id}-file`}
onChange={pick}
/>
<ActionButton
readOnly={false}
variant="secondary"
size="sm"
disabled={upload.ui.phase === 'working'}
onClick={() => input.current?.click()}
>
{t('editor.views.drawing.choose')}
</ActionButton>
{view.kind === 'detail' && ownDrawing && (
<ActionButton
readOnly={false}
variant="ghost"
size="sm"
onClick={() =>
views.update('drawing', view.id, { svg_asset_id: null }, true)
}
>
{t('editor.views.drawing.use_parent')}
</ActionButton>
)}
</div>
{upload.ui.phase === 'working' && (
<Notice tone="info">{t('editor.upload.working')}</Notice>
)}
{upload.ui.phase === 'done' && (
<Notice tone="success">{t('editor.upload.done')}</Notice>
)}
{failure && <Notice tone="error">{failure}</Notice>}
{views.error('drawing') && (
<Notice tone="error">{views.error('drawing')}</Notice>
)}
<CleaningDialog
candidate={upload.ui.phase === 'cleaning' ? upload.ui.candidate : null}
onConfirm={() => void upload.confirmCleaning()}
onCancel={upload.cancelCleaning}
/>
</>
)
}
@@ -0,0 +1,43 @@
import type { SheetView } from '@faunosteo/core-wasm/types'
import TextField from '@/components/editor/fields/TextField'
import { isBlank } from '@/editor/sheetDocument'
import type { ViewUpdateApi } from '@/editor/useViewUpdate'
import type { Locale } from '@/i18n/types'
import { useT } from '@/i18n/useT'
/** The two names of a view (required); each commits on blur or Enter. */
export default function ViewNames({
view,
readOnly,
views,
}: {
view: SheetView
readOnly: boolean
views: ViewUpdateApi
}) {
const t = useT()
const rename = (locale: Locale) => (value: string) =>
isBlank(value)
? views.reject(locale, 'editor.field.required')
: views.update(
locale,
view.id,
{ name: { ...view.name, [locale]: value } },
false,
)
return (
<>
{(['fr', 'en'] as const).map((locale) => (
<TextField
key={locale}
id={`view-${view.id}-name-${locale}`}
label={t(`editor.views.name_${locale}`)}
value={view.name[locale]}
onCommit={rename(locale)}
readOnly={readOnly}
error={views.error(locale)}
/>
))}
</>
)
}