feat(editor): finding dialog and citations side sheet in the history

Constats opens each element in one modal dialog (view, edit with a
local draft, creation) driven by the editor view layer of the browser
history. The citations panel becomes a modal side sheet stacked over
it; its geometry, exit machinery and page inertness are removed.
Back and Forward restore the layers, a dirty form asks first.
This commit is contained in:
bchanot committed 2026-11-13 18:51:35 +01:00
1 parent 8e4f02620a
commit 18085cecf8
50 files changed
+2642 -1504

No files matched your search

@@ -4,9 +4,12 @@ import type {
FindingCategoryKind,
FindingNode,
} from '@faunosteo/core-wasm/types'
import ActionButton from '@/components/editor/fields/ActionButton'
import DraftField from '@/components/editor/fields/DraftField'
import SelectField from '@/components/editor/fields/SelectField'
import DiscardConfirm from '@/components/editor/findings/DiscardConfirm'
import ReadOnlyNotice from '@/components/editor/findings/ReadOnlyNotice'
import { useDirtyGuard } from '@/components/editor/findings/useDirtyGuard'
import Button from '@/components/ui/Button'
import {
buildItems,
type FindingItem,
@@ -15,6 +18,7 @@ import {
import type { IdPrefix } from '@/editor/ids'
import { isBlank, useSheetDocument } from '@/editor/sheetDocument'
import { useEditCommand } from '@/editor/useEditCommand'
import type { Guards } from '@/editor/useEditorNavigation'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
@@ -31,26 +35,30 @@ export interface PendingFinding {
parent: FindingItem | null
}
export interface FindingCreateFormProps {
pending: PendingFinding
readOnly: boolean
guards: Guards
/** `created` is the new element's id, `parent` the element it went under. */
onCreated: (id: string, parent: FindingItem | null) => void
/** A close of the dialog; forced after « Abandonner ». */
onClose: (forced: boolean) => void
}
/**
* Collects what the core requires (names FR/EN, the kind of a category), then one
* `insert`: no element exists with default labels.
* `insert`: no element exists with default labels. The fields are a local draft: nothing
* is written before « Créer », a close or a move never creates (R2F-3).
*/
export default function FindingCreateForm({
pending,
onCreated,
onCancel,
}: {
pending: PendingFinding
onCreated: (id: string, parent: FindingItem | null) => void
onCancel: () => void
}) {
export default function FindingCreateForm(props: FindingCreateFormProps) {
const { pending, readOnly, guards, onCreated, onClose } = props
const t = useT()
const edit = useEditCommand()
const zones = useZoneChoice()
const title = useFormTitle(pending, zones.chosen)
const [fr, setFr] = useState('')
const [en, setEn] = useState('')
const [kind, setKind] = useState('')
const guard = useDirtyGuard(guards, fr !== '' || en !== '' || kind !== '')
const create = () => {
const parent = pending.kind === 'category' ? zones.chosen : pending.parent
const missingParent = pending.kind === 'category' && !parent
@@ -71,16 +79,27 @@ export default function FindingCreateForm({
})
if (added) onCreated(createdId, parent)
}
const category = pending.kind === 'category'
return (
<div className="space-y-2 rounded-lg border border-dashed border-[var(--color-border)] p-3">
<p className="text-sm font-medium">{title}</p>
<form
data-draft-form
className="space-y-3"
noValidate
onSubmit={(event) => {
event.preventDefault()
create()
}}
>
{readOnly && <ReadOnlyNotice />}
{category && zones.chosen && <ZoneTitle zone={zones.chosen} />}
<div className="grid gap-3 md:grid-cols-2">
{pending.kind === 'category' && <ZoneSelect zones={zones} />}
{pending.kind === 'category' && (
{category && <ZoneSelect zones={zones} readOnly={readOnly} />}
{category && (
<SelectField
id="finding-new-kind"
label={t('editor.findings.kind')}
value={kind}
readOnly={readOnly}
options={[
{ value: '', label: t('editor.field.choose') },
...CATEGORY_KINDS.map((k) => ({
@@ -96,12 +115,14 @@ export default function FindingCreateForm({
label={t('editor.general.name_fr')}
value={fr}
onChange={setFr}
readOnly={readOnly}
/>
<DraftField
id="finding-new-name-en"
label={t('editor.general.name_en')}
value={en}
onChange={setEn}
readOnly={readOnly}
/>
</div>
{edit.fieldError('form') && (
@@ -109,15 +130,26 @@ export default function FindingCreateForm({
{edit.fieldError('form')}
</p>
)}
<div className="flex gap-2">
<ActionButton readOnly={false} variant="secondary" onClick={create}>
{t('editor.findings.create')}
</ActionButton>
<ActionButton readOnly={false} variant="ghost" onClick={onCancel}>
{t('editor.findings.cancel')}
</ActionButton>
</div>
</div>
{guard.confirming ? (
<DiscardConfirm
onKeepTyping={guard.keepTyping}
onDiscard={() => onClose(true)}
/>
) : (
<div className="flex flex-wrap justify-end gap-2">
<Button
type="button"
variant="ghost"
onClick={() => onClose(readOnly)}
>
{t(readOnly ? 'editor.findings.discard' : 'editor.findings.cancel')}
</Button>
<Button type="submit" disabled={readOnly}>
{t('editor.findings.create')}
</Button>
</div>
)}
</form>
)
}
@@ -139,7 +171,13 @@ function useZoneChoice(): ZoneChoice {
return { zones, zoneId, setZoneId, chosen }
}
function ZoneSelect({ zones }: { zones: ZoneChoice }) {
function ZoneSelect({
zones,
readOnly,
}: {
zones: ZoneChoice
readOnly: boolean
}) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
return (
@@ -147,6 +185,7 @@ function ZoneSelect({ zones }: { zones: ZoneChoice }) {
id="finding-new-zone"
label={t('editor.findings.zone')}
value={zones.zoneId}
readOnly={readOnly}
options={[
{ value: '', label: t('editor.field.choose') },
...zones.zones.map((zone) => ({
@@ -159,19 +198,17 @@ function ZoneSelect({ zones }: { zones: ZoneChoice }) {
)
}
/** A category lands at zone level: its title names the zone chosen in the form. */
function useFormTitle(
pending: PendingFinding,
zone: FindingItem | null,
): string {
/** A category lands at zone level: the line under the dialog's title names the zone chosen. */
function ZoneTitle({ zone }: { zone: FindingItem }) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
if (pending.kind !== 'category')
return t(`editor.findings.new.${pending.kind}`)
if (!zone) return t('editor.findings.add_category')
return t('editor.findings.new.category_in_zone').replace(
'{zone}',
zone.name[locale],
return (
<p className="text-sm font-medium">
{t('editor.findings.new.category_in_zone').replace(
'{zone}',
zone.name[locale],
)}
</p>
)
}