48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import ActionButton from '@/components/editor/fields/ActionButton'
|
|
import type { PendingFinding } from '@/components/editor/findings/FindingCreateForm'
|
|
import { canAddNode, type FindingItem } from '@/editor/findings/tree'
|
|
import { useT } from '@/i18n/useT'
|
|
|
|
/** « Ajouter une zone / une catégorie / un constat »: each starts a creation form. */
|
|
export default function AddBar({
|
|
selected,
|
|
readOnly,
|
|
onStart,
|
|
}: {
|
|
selected: FindingItem | undefined
|
|
readOnly: boolean
|
|
onStart: (pending: PendingFinding) => void
|
|
}) {
|
|
const t = useT()
|
|
return (
|
|
<div className="flex flex-wrap gap-2">
|
|
<ActionButton
|
|
readOnly={readOnly}
|
|
variant="secondary"
|
|
size="sm"
|
|
onClick={() => onStart({ kind: 'zone', parent: null })}
|
|
>
|
|
{t('editor.findings.add_zone')}
|
|
</ActionButton>
|
|
<ActionButton
|
|
readOnly={readOnly}
|
|
variant="secondary"
|
|
size="sm"
|
|
disabled={!selected}
|
|
onClick={() => onStart({ kind: 'category', parent: selected ?? null })}
|
|
>
|
|
{t('editor.findings.add_category')}
|
|
</ActionButton>
|
|
<ActionButton
|
|
readOnly={readOnly}
|
|
variant="secondary"
|
|
size="sm"
|
|
disabled={!canAddNode(selected)}
|
|
onClick={() => onStart({ kind: 'node', parent: selected ?? null })}
|
|
>
|
|
{t('editor.findings.add_node')}
|
|
</ActionButton>
|
|
</div>
|
|
)
|
|
}
|