fix(editor): plurals, trimmed names, default tab, parent drawing confirmation
This commit is contained in:
1 parent
b42c6ae844
commit
be4f468790
35 files changed
+385
-63
No files matched your search
@@ -9,9 +9,10 @@ import DraftField from '@/components/editor/fields/DraftField'
|
||||
import SelectField from '@/components/editor/fields/SelectField'
|
||||
import type { FindingItem, FindingKind } from '@/editor/findings/tree'
|
||||
import type { IdPrefix } from '@/editor/ids'
|
||||
import { isBlank } from '@/editor/sheetDocument'
|
||||
import { elementLabel, isBlank, useSheetDocument } from '@/editor/sheetDocument'
|
||||
import { useEditCommand } from '@/editor/useEditCommand'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
|
||||
export const CATEGORY_KINDS: readonly FindingCategoryKind[] = [
|
||||
'dysfunction',
|
||||
@@ -40,6 +41,7 @@ export default function FindingCreateForm({
|
||||
onCancel: () => void
|
||||
}) {
|
||||
const t = useT()
|
||||
const title = useFormTitle(pending)
|
||||
const edit = useEditCommand()
|
||||
const [fr, setFr] = useState('')
|
||||
const [en, setEn] = useState('')
|
||||
@@ -54,15 +56,13 @@ export default function FindingCreateForm({
|
||||
let createdId = ''
|
||||
const added = edit.runNew('form', PREFIX[pending.kind], (id) => {
|
||||
createdId = id
|
||||
return insertCommand(pending, id, { fr, en }, kind)
|
||||
return insertCommand(pending, id, { fr: fr.trim(), en: en.trim() }, kind)
|
||||
})
|
||||
if (added) onCreated(createdId)
|
||||
}
|
||||
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.findings.new.${pending.kind}`)}
|
||||
</p>
|
||||
<p className="text-sm font-medium">{title}</p>
|
||||
<div className="grid gap-3 md:grid-cols-2">
|
||||
{pending.kind === 'category' && (
|
||||
<SelectField
|
||||
@@ -109,6 +109,22 @@ export default function FindingCreateForm({
|
||||
)
|
||||
}
|
||||
|
||||
/** A category lands at zone level, so its title names the zone, whatever is selected. */
|
||||
function useFormTitle(pending: PendingFinding): string {
|
||||
const t = useT()
|
||||
const doc = useSheetDocument()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
if (pending.kind !== 'category' || !doc || !pending.parent) {
|
||||
return t(`editor.findings.new.${pending.kind}`)
|
||||
}
|
||||
const zone = elementLabel(
|
||||
doc,
|
||||
{ kind: 'zone', id: pending.parent.zoneId },
|
||||
locale,
|
||||
)
|
||||
return t('editor.findings.new.category_in_zone').replace('{zone}', zone)
|
||||
}
|
||||
|
||||
const PREFIX: Record<FindingKind, IdPrefix> = {
|
||||
zone: 'zone',
|
||||
category: 'fcat',
|
||||
|
||||
Reference in new issue
Block a user