feat(editor): references dialog over the finding, view mode
A modal Dialog replaces the citations side sheet; families open it too (isCitable). The finding dialog shows only « Références citées » and « X références », also at zero; its edit form no longer carries reference_ids. A dirty form refusing « Aller à » or « Tout afficher » closes the clean references dialog first.
This commit is contained in:
1 parent
ff21b0315e
commit
abc781df52
29 files changed
+432
-858
No files matched your search
@@ -33,7 +33,7 @@ import EditorTabBody from './EditorTabBody'
|
||||
import EditorTabs from './EditorTabs'
|
||||
import ModeNotice from './ModeNotice'
|
||||
import RecoveryNotice from './RecoveryNotice'
|
||||
import CitationsSheet from './references/CitationsSheet'
|
||||
import CitationsDialog from './references/CitationsDialog'
|
||||
import ReferenceDialog from './references/ReferenceDialog'
|
||||
|
||||
interface Props {
|
||||
@@ -85,7 +85,7 @@ interface PlacesProps {
|
||||
}
|
||||
|
||||
/**
|
||||
* The tab panels, then the citations sheet and the reference dialog: each comes after the
|
||||
* The tab panels, then the references dialog and the reference dialog: each comes after the
|
||||
* one under it in the tree (the tab body holds the finding dialog), so it is shown after
|
||||
* it and lies over it.
|
||||
*/
|
||||
@@ -112,13 +112,11 @@ function Places({ nav, readOnly, reloadSheet }: PlacesProps) {
|
||||
onBack: nav.backToDrawing,
|
||||
}}
|
||||
/>
|
||||
<CitationsSheet
|
||||
<CitationsDialog
|
||||
citedBy={cited}
|
||||
readOnly={readOnly}
|
||||
onClose={nav.closeCitations}
|
||||
onShowAll={() => cited && nav.showAllReferences(cited)}
|
||||
navigate={nav.navigate}
|
||||
onEdit={nav.references.open}
|
||||
returnFocus={nav.citationsTrigger}
|
||||
/>
|
||||
<ReferenceDialog layer={references} readOnly={readOnly} />
|
||||
@@ -206,8 +204,8 @@ function LeftDraftNotice({ shown }: { shown: boolean }) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The draft page once the version is ready: header, notices, tab row, the citations
|
||||
* panel and the shown place. Owns the navigation state, so the first tab is known at
|
||||
* The draft page once the version is ready: header, notices, tab row, the dialogs
|
||||
* and the shown place. Owns the navigation state, so the first tab is known at
|
||||
* mount and later edits never move the user off their tab.
|
||||
*/
|
||||
function Workspace(props: Props & Who) {
|
||||
|
||||
@@ -7,9 +7,9 @@ import { useT } from '@/i18n/useT'
|
||||
|
||||
interface CitationsProps {
|
||||
item: FindingItem
|
||||
/** The citations sheet is open over the dialog (the trigger reads « expanded »). */
|
||||
sheetOpen: boolean
|
||||
/** Opens the citations sheet; a family has none (it lists its citations here). */
|
||||
/** The references dialog is open over the finding dialog (the trigger reads « expanded »). */
|
||||
citationsOpen: boolean
|
||||
/** Opens the references dialog of the family or node. */
|
||||
onShowReferences: (opener: HTMLElement) => void
|
||||
}
|
||||
|
||||
@@ -19,21 +19,19 @@ const PILL =
|
||||
const RING =
|
||||
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]'
|
||||
|
||||
/** « X références »: the way to the sheet of a finding node's citations. */
|
||||
function SheetTrigger({
|
||||
/** « X références »: the way to the references dialog, at zero too (Rev 5). */
|
||||
function CitationsTrigger({
|
||||
item,
|
||||
count,
|
||||
sheetOpen,
|
||||
citationsOpen,
|
||||
onShowReferences,
|
||||
}: Pick<CitationsProps, 'item' | 'sheetOpen' | 'onShowReferences'> & {
|
||||
count: number
|
||||
}) {
|
||||
}: CitationsProps & { count: number }) {
|
||||
const plural = usePlural()
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
data-citations-trigger={JSON.stringify(item.key)}
|
||||
aria-expanded={sheetOpen}
|
||||
aria-expanded={citationsOpen}
|
||||
aria-controls="editor-citations-panel"
|
||||
onClick={(event) => onShowReferences(event.currentTarget)}
|
||||
className={`${PILL} ${RING}`}
|
||||
@@ -44,7 +42,7 @@ function SheetTrigger({
|
||||
)
|
||||
}
|
||||
|
||||
/** A family's inline list of cited references; removable only where `remove` is given. */
|
||||
/** A list of cited references; removable only where `remove` is given. */
|
||||
export function CitationList({
|
||||
ids,
|
||||
readOnly,
|
||||
@@ -80,52 +78,22 @@ export function CitationList({
|
||||
)
|
||||
}
|
||||
|
||||
/** « Références citées » and « X références »: the heading row of both modes. */
|
||||
export function CitationsHeader({
|
||||
item,
|
||||
count,
|
||||
sheetOpen,
|
||||
onShowReferences,
|
||||
}: Pick<CitationsProps, 'item' | 'sheetOpen' | 'onShowReferences'> & {
|
||||
count: number
|
||||
}) {
|
||||
const t = useT()
|
||||
return (
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<p className="text-sm font-medium">{t('editor.findings.references')}</p>
|
||||
{count > 0 && item.element.kind === 'finding_node' && (
|
||||
<SheetTrigger
|
||||
item={item}
|
||||
count={count}
|
||||
sheetOpen={sheetOpen}
|
||||
onShowReferences={onShowReferences}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* « Références citées » of a category or a node, read: a finding node shows « X références »
|
||||
* (the sheet), a family its list. Nothing here cites or removes: that is the edit form's
|
||||
* (FindingEditCitations).
|
||||
* « Références citées » and « X références » of a family or a node, the same in the view
|
||||
* and the edit mode (Rev 5): the count is the document's, the citations are read and
|
||||
* changed in the references dialog only. A zone cites nothing: no row.
|
||||
*/
|
||||
export default function FindingCitations(props: CitationsProps) {
|
||||
export default function CitationsHeader(props: CitationsProps) {
|
||||
const { item } = props
|
||||
const t = useT()
|
||||
if (item.element.kind === 'zone') return null
|
||||
const ids = item.element.value.reference_ids
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<CitationsHeader {...props} count={ids.length} />
|
||||
{ids.length === 0 && (
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
{t('editor.findings.references_none')}
|
||||
</p>
|
||||
)}
|
||||
{item.element.kind === 'finding_category' && (
|
||||
<CitationList ids={ids} readOnly />
|
||||
)}
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<p className="text-sm font-medium">{t('editor.findings.references')}</p>
|
||||
<CitationsTrigger
|
||||
{...props}
|
||||
count={item.element.value.reference_ids.length}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -65,7 +65,8 @@ function ItemBody(props: ItemBodyProps) {
|
||||
const { layer } = props
|
||||
const t = useT()
|
||||
const mode = useItemMode()
|
||||
const sheetOpen = !!layer.view && 'key' in layer.view && layer.view.citations
|
||||
const citationsOpen =
|
||||
!!layer.view && 'key' in layer.view && layer.view.citations
|
||||
const showReferences = (opener: HTMLElement) =>
|
||||
layer.openCitations(props.item.key, opener)
|
||||
return (
|
||||
@@ -77,14 +78,14 @@ function ItemBody(props: ItemBodyProps) {
|
||||
guards={layer.guards}
|
||||
onDone={mode.done}
|
||||
onDiscardClose={() => layer.close(true)}
|
||||
sheetOpen={sheetOpen}
|
||||
citationsOpen={citationsOpen}
|
||||
onShowReferences={showReferences}
|
||||
/>
|
||||
) : (
|
||||
<FindingView
|
||||
item={props.item}
|
||||
readOnly={props.readOnly}
|
||||
sheetOpen={sheetOpen}
|
||||
citationsOpen={citationsOpen}
|
||||
onEdit={mode.startEdit}
|
||||
onDelete={() => props.onDelete(props.item)}
|
||||
onShowReferences={showReferences}
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
import SelectField from '@/components/editor/fields/SelectField'
|
||||
import {
|
||||
CitationList,
|
||||
CitationsHeader,
|
||||
} from '@/components/editor/findings/FindingCitations'
|
||||
import type { FindingItem } from '@/editor/findings/tree'
|
||||
import { CitationList } from '@/components/editor/findings/FindingCitations'
|
||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
interface Props {
|
||||
item: FindingItem
|
||||
/** The draft's cited ids: what the form shows, counts and hands to the sheet. */
|
||||
/** The draft's cited ids: what the form shows. */
|
||||
ids: readonly string[]
|
||||
readOnly: boolean
|
||||
sheetOpen: boolean
|
||||
onChange: (ids: string[]) => void
|
||||
onShowReferences: (opener: HTMLElement) => void
|
||||
}
|
||||
|
||||
/** The references the draft does not cite yet, after the « choose » placeholder. */
|
||||
@@ -28,8 +21,9 @@ function useCitableOptions(ids: readonly string[]) {
|
||||
}
|
||||
|
||||
/**
|
||||
* « Références citées » in the edit form of a category or a node: the draft's list, each
|
||||
* « Retirer », and « Citer une référence ». Nothing is written before « Enregistrer ».
|
||||
* The cited references of a draft: the list, each « Retirer », and « Citer une référence ».
|
||||
* Nothing is written before « Enregistrer ». Mounted by no form since Rev 5 Task 11: the
|
||||
* references dialog's edit mode (Task 12) takes it over.
|
||||
*/
|
||||
export default function FindingEditCitations(props: Props) {
|
||||
const { ids, readOnly, onChange } = props
|
||||
@@ -37,7 +31,6 @@ export default function FindingEditCitations(props: Props) {
|
||||
const options = useCitableOptions(ids)
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<CitationsHeader {...props} count={ids.length} />
|
||||
{ids.length === 0 ? (
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
{t('editor.findings.references_none')}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useState } from 'react'
|
||||
import DraftField from '@/components/editor/fields/DraftField'
|
||||
import { FormActions } from '@/components/editor/findings/DiscardConfirm'
|
||||
import { useFormDraft } from '@/components/editor/findings/useDirtyGuard'
|
||||
import FindingEditCitations from '@/components/editor/findings/FindingEditCitations'
|
||||
import CitationsHeader from '@/components/editor/findings/FindingCitations'
|
||||
import ReadOnlyNotice from '@/components/editor/findings/ReadOnlyNotice'
|
||||
import { useCitationDraft } from '@/editor/findings/citationDraft'
|
||||
import { patchElement, type FindingItem } from '@/editor/findings/tree'
|
||||
import { isBlank, optionalText } from '@/editor/sheetDocument'
|
||||
import { useEditCommand } from '@/editor/useEditCommand'
|
||||
@@ -18,7 +17,6 @@ interface Draft {
|
||||
descriptionFr: string
|
||||
descriptionEn: string
|
||||
vet: boolean
|
||||
referenceIds: string[]
|
||||
}
|
||||
|
||||
function draftOf(item: FindingItem): Draft {
|
||||
@@ -30,8 +28,6 @@ function draftOf(item: FindingItem): Draft {
|
||||
descriptionFr: described.fr ?? '',
|
||||
descriptionEn: described.en ?? '',
|
||||
vet: element.kind === 'finding_node' && element.value.requires_vet_referral,
|
||||
referenceIds:
|
||||
element.kind === 'zone' ? [] : [...element.value.reference_ids],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +45,11 @@ function normalized(draft: Draft): Draft {
|
||||
const sameDraft = (a: Draft, b: Draft) =>
|
||||
JSON.stringify(normalized(a)) === JSON.stringify(normalized(b))
|
||||
|
||||
/** The one `update` the form makes: names, and for a family or a node texts and citations. */
|
||||
/**
|
||||
* The one `update` the form makes: names, and for a family or a node its texts. The
|
||||
* citations are the element's current ones (`patchElement` keeps them): the references
|
||||
* dialog changes them, never this save.
|
||||
*/
|
||||
function patchOf(item: FindingItem, draft: Draft) {
|
||||
const now = normalized(draft)
|
||||
const { element } = item
|
||||
@@ -65,7 +65,6 @@ function patchOf(item: FindingItem, draft: Draft) {
|
||||
return patchElement(item, {
|
||||
name,
|
||||
description,
|
||||
reference_ids: now.referenceIds,
|
||||
...(element.kind === 'finding_node' ? vet : {}),
|
||||
})
|
||||
}
|
||||
@@ -78,9 +77,9 @@ export interface FindingEditFormProps {
|
||||
onDone: (saved: boolean) => void
|
||||
/** « Abandonner » after a close request: the draft goes, so does the dialog. */
|
||||
onDiscardClose: () => void
|
||||
/** The citations sheet is open over the dialog (the trigger reads « expanded »). */
|
||||
sheetOpen: boolean
|
||||
/** Opens the citations sheet, which then lists the draft's citations. */
|
||||
/** The references dialog is open over the finding dialog (the trigger reads « expanded »). */
|
||||
citationsOpen: boolean
|
||||
/** Opens the references dialog, which lists the element's citations. */
|
||||
onShowReferences: (opener: HTMLElement) => void
|
||||
}
|
||||
|
||||
@@ -177,20 +176,10 @@ function useEditSave(props: FindingEditFormProps, form: EditDraft) {
|
||||
|
||||
type EditDraft = ReturnType<typeof useFormDraft<Draft>>
|
||||
|
||||
/** The sheet opened from the form lists the draft's citations: they are published there. */
|
||||
function usePublishedCitations(item: FindingItem, ids: readonly string[]) {
|
||||
const publish = useCitationDraft((s) => s.publish)
|
||||
useEffect(() => {
|
||||
publish({ key: item.key, ids })
|
||||
return () => publish(null)
|
||||
}, [publish, item.key, ids])
|
||||
}
|
||||
|
||||
/** The form's state: draft, blank names, save and cancel. */
|
||||
function useEditForm(props: FindingEditFormProps) {
|
||||
const form = useFormDraft(draftOf(props.item), props.guards, sameDraft)
|
||||
const saving = useEditSave(props, form)
|
||||
usePublishedCitations(props.item, form.draft.referenceIds)
|
||||
const cancel = () =>
|
||||
form.dirty && !props.readOnly
|
||||
? form.guard.askToLeave()
|
||||
@@ -199,9 +188,9 @@ function useEditForm(props: FindingEditFormProps) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The element edited in the finding dialog (R2F-3): a local draft, one `update` on
|
||||
* « Enregistrer », citations included (none when nothing changed), nothing on « Annuler »
|
||||
* or a close. When the
|
||||
* The element edited in the finding dialog (R2F-3): a local draft of its properties, one
|
||||
* `update` on « Enregistrer » (none when nothing changed), nothing on « Annuler » or a
|
||||
* close. Its citations are shown as « X références » only (Rev 5). When the
|
||||
* editor turns read-only the draft stays, its fields read-only, and only « Abandonner »
|
||||
* is left.
|
||||
*/
|
||||
@@ -238,16 +227,11 @@ export default function FindingEditForm(props: FindingEditFormProps) {
|
||||
onChange={(vet) => form.set({ vet })}
|
||||
/>
|
||||
)}
|
||||
{props.item.kind !== 'zone' && (
|
||||
<FindingEditCitations
|
||||
item={props.item}
|
||||
ids={form.draft.referenceIds}
|
||||
readOnly={props.readOnly}
|
||||
sheetOpen={props.sheetOpen}
|
||||
onChange={(referenceIds) => form.set({ referenceIds })}
|
||||
onShowReferences={props.onShowReferences}
|
||||
/>
|
||||
)}
|
||||
<CitationsHeader
|
||||
item={props.item}
|
||||
citationsOpen={props.citationsOpen}
|
||||
onShowReferences={props.onShowReferences}
|
||||
/>
|
||||
{form.error && (
|
||||
<p role="alert" className="text-sm text-[var(--color-danger-strong)]">
|
||||
{form.error}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import ReadOnlyValue from '@/components/editor/fields/ReadOnlyValue'
|
||||
import FindingActions from '@/components/editor/findings/FindingActions'
|
||||
import FindingCitations from '@/components/editor/findings/FindingCitations'
|
||||
import CitationsHeader from '@/components/editor/findings/FindingCitations'
|
||||
import StatusBadge from '@/components/editor/findings/StatusBadge'
|
||||
import type { FindingItem } from '@/editor/findings/tree'
|
||||
import { useEditCommand } from '@/editor/useEditCommand'
|
||||
@@ -9,7 +9,7 @@ import { useT } from '@/i18n/useT'
|
||||
export interface FindingViewProps {
|
||||
item: FindingItem
|
||||
readOnly: boolean
|
||||
sheetOpen: boolean
|
||||
citationsOpen: boolean
|
||||
onEdit: () => void
|
||||
onDelete: () => void
|
||||
onShowReferences: (opener: HTMLElement) => void
|
||||
@@ -49,11 +49,11 @@ function Texts({ item }: { item: FindingItem }) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The element read in the finding dialog (R2F-3): type and status, names, texts, its
|
||||
* citations, and the actions of the edit tier. Nothing here edits a field in place.
|
||||
* The element read in the finding dialog (R2F-3): type and status, names, texts, the way
|
||||
* to its references dialog, and the actions of the edit tier. Nothing here edits a field in place.
|
||||
*/
|
||||
export default function FindingView(props: FindingViewProps) {
|
||||
const { item, readOnly, sheetOpen } = props
|
||||
const { item, readOnly, citationsOpen } = props
|
||||
const t = useT()
|
||||
const edit = useEditCommand()
|
||||
return (
|
||||
@@ -75,9 +75,9 @@ export default function FindingView(props: FindingViewProps) {
|
||||
))}
|
||||
</div>
|
||||
<Texts item={item} />
|
||||
<FindingCitations
|
||||
<CitationsHeader
|
||||
item={item}
|
||||
sheetOpen={sheetOpen}
|
||||
citationsOpen={citationsOpen}
|
||||
onShowReferences={props.onShowReferences}
|
||||
/>
|
||||
<FindingActions
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||
import Dialog from '@/components/ui/Dialog'
|
||||
import type { EditorTarget } from '@/editor/navigation'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import CitationsPanel from './CitationsPanel'
|
||||
import { CITATIONS_TITLE_ID } from './useCitationsPanel'
|
||||
|
||||
export interface CitationsDialogProps {
|
||||
/** The family or finding node whose citations it shows; null while it is closed. */
|
||||
citedBy: ElementKey | null
|
||||
/** A user close (✕, Escape, the backdrop). */
|
||||
onClose: () => boolean
|
||||
/** « Tout afficher dans l'onglet Références ». */
|
||||
onShowAll: () => void
|
||||
/** « Aller à » a citing finding or a reference. */
|
||||
navigate: (target: EditorTarget) => void
|
||||
/** « X références » of the finding dialog under it, where the focus returns. */
|
||||
returnFocus: () => HTMLElement | null
|
||||
}
|
||||
|
||||
/**
|
||||
* The references dialog of a family or a finding node (Rev 5): a modal layer over the
|
||||
* finding dialog. The host sits after the tab body in the tree, so it is shown after the
|
||||
* finding dialog and lies on top of it; Escape, ✕ and the backdrop close it only. The
|
||||
* view mode reads the cited references.
|
||||
*/
|
||||
export default function CitationsDialog(props: CitationsDialogProps) {
|
||||
const { citedBy, onClose } = props
|
||||
const t = useT()
|
||||
return (
|
||||
<Dialog
|
||||
open={citedBy !== null}
|
||||
layer
|
||||
size="lg"
|
||||
title={t('editor.references.dialog_title')}
|
||||
titleId={CITATIONS_TITLE_ID}
|
||||
returnFocus={props.returnFocus}
|
||||
onClose={() => (onClose() ? undefined : 'kept')}
|
||||
>
|
||||
{citedBy && (
|
||||
<CitationsPanel
|
||||
citedBy={citedBy}
|
||||
onShowAll={props.onShowAll}
|
||||
navigate={props.navigate}
|
||||
/>
|
||||
)}
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { RefObject } from 'react'
|
||||
import type { LocalizedText, Reference } from '@faunosteo/core-wasm/types'
|
||||
import Icon from '@/components/ui/Icon'
|
||||
import { targetOfKey, type EditorTarget } from '@/editor/navigation'
|
||||
@@ -7,53 +6,22 @@ import type { CitationEntry } from '@/editor/references/panel'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import ReferenceTile from './ReferenceTile'
|
||||
import { useCitationsPanel, type PanelHooks } from './useCitationsPanel'
|
||||
import {
|
||||
CITATIONS_TITLE_ID,
|
||||
useCitationsPanel,
|
||||
type PanelHooks,
|
||||
} from './useCitationsPanel'
|
||||
|
||||
interface Props extends PanelHooks {
|
||||
/** ✕ (Escape and the scrim close the sheet itself): a close the tile in edit may refuse. */
|
||||
onClose: () => void
|
||||
/** « Tout afficher dans l'onglet Références ». */
|
||||
onShowAll: () => void
|
||||
/** « Aller à » a citing finding or family: closes the panel, then moves. */
|
||||
/** « Aller à » a citing finding or family: closes the dialog, then moves. */
|
||||
navigate: (target: EditorTarget) => void
|
||||
/** « Modifier »: the reference dialog over the sheet, `opener` is where the focus returns. */
|
||||
onEdit: (id: string, opener: HTMLElement) => void
|
||||
}
|
||||
|
||||
const RING =
|
||||
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]'
|
||||
|
||||
interface HeaderProps {
|
||||
onClose: () => void
|
||||
headingRef: RefObject<HTMLHeadingElement | null>
|
||||
}
|
||||
|
||||
function PanelHeader({ onClose, headingRef }: HeaderProps) {
|
||||
const t = useT()
|
||||
return (
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<h2
|
||||
ref={headingRef}
|
||||
id="editor-citations-title"
|
||||
tabIndex={-1}
|
||||
data-place-heading
|
||||
className="flex items-center gap-2 font-serif text-xl outline-none"
|
||||
>
|
||||
<Icon name="book" size={20} />
|
||||
{t('editor.references.panel_title')}
|
||||
</h2>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={t('editor.references.close')}
|
||||
onClick={onClose}
|
||||
className={`inline-flex h-11 w-11 items-center justify-center rounded-md ${RING}`}
|
||||
>
|
||||
<Icon name="close" size={18} />
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** « Zone › Famille › **Constat** »: where the finding sits, the finding itself in bold. */
|
||||
function FindingPath({ path }: { path: readonly LocalizedText[] }) {
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
@@ -102,7 +70,7 @@ function Summary({
|
||||
)
|
||||
}
|
||||
|
||||
/** A cited id the sheet no longer holds (P30): named; only the edit form removes it. */
|
||||
/** A cited id the sheet no longer holds (P30): named, never removed in the view mode. */
|
||||
function MissingRow({ entry }: { entry: CitationEntry }) {
|
||||
const t = useT()
|
||||
return (
|
||||
@@ -115,7 +83,7 @@ function MissingRow({ entry }: { entry: CitationEntry }) {
|
||||
|
||||
type Panel = ReturnType<typeof useCitationsPanel>
|
||||
|
||||
/** One cited reference as a tile (« Modifier »). */
|
||||
/** One cited reference as a tile, read only: its facts and its citers' « Aller à ». */
|
||||
function EntryTile({
|
||||
entry,
|
||||
reference,
|
||||
@@ -128,7 +96,7 @@ function EntryTile({
|
||||
props: Props
|
||||
}) {
|
||||
const { tiles, keys, citers, entries } = panel
|
||||
const { readOnly, citedBy, navigate } = props
|
||||
const { citedBy, navigate } = props
|
||||
const key = keys[entry.index]
|
||||
return (
|
||||
<ReferenceTile
|
||||
@@ -139,11 +107,12 @@ function EntryTile({
|
||||
count={entries.length}
|
||||
citers={citers.get(reference.id) ?? []}
|
||||
open={tiles.openKeys.has(key)}
|
||||
readOnly={readOnly}
|
||||
readOnly
|
||||
movable={false}
|
||||
on={{
|
||||
toggle: () => tiles.toggle(key),
|
||||
edit: (opener) => props.onEdit(reference.id, opener),
|
||||
// Never offered: a read-only tile has no « Modifier ».
|
||||
edit: () => undefined,
|
||||
goTo: (target) => navigate(targetOfKey(target)),
|
||||
}}
|
||||
/>
|
||||
@@ -176,13 +145,13 @@ function Entries({ panel, props }: { panel: Panel; props: Props }) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The citations of one finding: the references it cites as tiles, « Tout afficher » for
|
||||
* the whole library. No search, add, remove or order (P7): citing is the edit form's.
|
||||
* The content of the side sheet
|
||||
* (CitationsSheet), which is the modal; opens from a finding's trigger only.
|
||||
* The citations of one family or finding node, the body of the references dialog
|
||||
* (CitationsDialog): where it sits, the references it cites as tiles, the dangling ids
|
||||
* named, « Tout afficher » for the whole library. The view mode: no search, add, remove,
|
||||
* order or « Modifier » (P7).
|
||||
*/
|
||||
export default function CitationsPanel(props: Props) {
|
||||
const { onClose, onShowAll } = props
|
||||
const { onShowAll } = props
|
||||
const t = useT()
|
||||
const panel = useCitationsPanel(props)
|
||||
const count = panel.entries.length
|
||||
@@ -190,20 +159,18 @@ export default function CitationsPanel(props: Props) {
|
||||
<section
|
||||
id="editor-citations-panel"
|
||||
data-testid="editor-citations-panel"
|
||||
aria-labelledby="editor-citations-title"
|
||||
className="flex h-full flex-col gap-3 border-l border-[var(--color-border)] bg-[var(--color-surface)] p-4 shadow-xl"
|
||||
data-place="citations"
|
||||
aria-labelledby={CITATIONS_TITLE_ID}
|
||||
className="space-y-3"
|
||||
>
|
||||
<PanelHeader onClose={onClose} headingRef={panel.heading} />
|
||||
<FindingPath path={panel.path} />
|
||||
<Summary count={count} onShowAll={onShowAll} />
|
||||
<div className="min-h-0 flex-1 space-y-3 overflow-y-auto pr-2">
|
||||
{count === 0 && (
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
{t('editor.references.panel_empty')}
|
||||
</p>
|
||||
)}
|
||||
<Entries panel={panel} props={props} />
|
||||
</div>
|
||||
{count === 0 && (
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
{t('editor.references.panel_empty')}
|
||||
</p>
|
||||
)}
|
||||
<Entries panel={panel} props={props} />
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
import { AnimatePresence, motion, useReducedMotion } from 'motion/react'
|
||||
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||
import ModalDialog from '@/components/ui/ModalDialog'
|
||||
import type { EditorTarget } from '@/editor/navigation'
|
||||
import CitationsPanel from './CitationsPanel'
|
||||
|
||||
/** Sheet motion (board 25): enter decelerates, the shorter exit accelerates (P9). */
|
||||
const ENTER_S = 0.18
|
||||
const EXIT_S = 0.14
|
||||
|
||||
export interface CitationsSheetProps {
|
||||
/** The finding whose citations the view shows; null while the sheet is closed. */
|
||||
citedBy: ElementKey | null
|
||||
readOnly: boolean
|
||||
/** A user close (✕, Escape, scrim). */
|
||||
onClose: () => boolean
|
||||
/** « Tout afficher dans l'onglet Références ». */
|
||||
onShowAll: () => void
|
||||
/** « Aller à » a citing finding or a reference. */
|
||||
navigate: (target: EditorTarget) => void
|
||||
/** « Modifier » on a tile: the reference dialog over the sheet. */
|
||||
onEdit: (id: string, opener: HTMLElement) => void
|
||||
/** « X références » of the dialog under the sheet, where the focus returns. */
|
||||
returnFocus: () => HTMLElement | null
|
||||
}
|
||||
|
||||
/** The slide and its timings; under reduced motion nothing moves and nothing waits. */
|
||||
function useSheetMotion() {
|
||||
const reduced = useReducedMotion()
|
||||
return {
|
||||
slide: reduced ? { x: 0 } : { x: '100%' },
|
||||
enter: { duration: reduced ? 0 : ENTER_S, ease: 'easeOut' } as const,
|
||||
leave: { duration: reduced ? 0 : EXIT_S, ease: 'easeIn' } as const,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The citations of a finding as a modal side sheet at the right edge, over the finding
|
||||
* dialog (R2F-4): the host sits after the tab body in the tree, so it is shown after the
|
||||
* dialog and lies on top of it. Escape and the scrim close the sheet only.
|
||||
*/
|
||||
function SheetSurface(props: CitationsSheetProps & { citedBy: ElementKey }) {
|
||||
const { citedBy, onClose } = props
|
||||
const sheetMotion = useSheetMotion()
|
||||
const close = () => (onClose() ? undefined : 'kept')
|
||||
return (
|
||||
<ModalDialog
|
||||
layer
|
||||
onClose={close}
|
||||
returnFocus={props.returnFocus}
|
||||
labelledBy="editor-citations-title"
|
||||
className="open:block"
|
||||
>
|
||||
<motion.div
|
||||
aria-hidden="true"
|
||||
data-testid="references-scrim"
|
||||
onClick={close}
|
||||
className="absolute inset-0 bg-[rgba(31,27,22,0.25)]"
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1, transition: sheetMotion.enter }}
|
||||
exit={{ opacity: 0, transition: sheetMotion.leave }}
|
||||
/>
|
||||
<motion.div
|
||||
data-place="citations"
|
||||
className="absolute inset-y-0 right-0 w-[min(34rem,100vw)]"
|
||||
initial={sheetMotion.slide}
|
||||
animate={{ x: 0, transition: sheetMotion.enter }}
|
||||
exit={{ ...sheetMotion.slide, transition: sheetMotion.leave }}
|
||||
>
|
||||
<CitationsPanel
|
||||
readOnly={props.readOnly}
|
||||
citedBy={citedBy}
|
||||
onClose={onClose}
|
||||
onShowAll={props.onShowAll}
|
||||
navigate={props.navigate}
|
||||
onEdit={props.onEdit}
|
||||
/>
|
||||
</motion.div>
|
||||
</ModalDialog>
|
||||
)
|
||||
}
|
||||
|
||||
export default function CitationsSheet(props: CitationsSheetProps) {
|
||||
const { citedBy } = props
|
||||
return (
|
||||
<AnimatePresence>
|
||||
{citedBy && <SheetSurface key="citations" {...props} citedBy={citedBy} />}
|
||||
</AnimatePresence>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import { useEffect, useMemo, useRef, useState, type FocusEvent } from 'react'
|
||||
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||
import { draftIdsFor, useCitationDraft } from '@/editor/findings/citationDraft'
|
||||
import type { FindingItem } from '@/editor/findings/tree'
|
||||
import { citersOf } from '@/editor/references/citations'
|
||||
import { citedIds, citingFinding } from '@/editor/references/filter'
|
||||
@@ -9,10 +8,12 @@ import { useSheetDocument } from '@/editor/sheetDocument'
|
||||
import { tileKeys, useTileState } from './useTileState'
|
||||
|
||||
export interface PanelHooks {
|
||||
readOnly: boolean
|
||||
citedBy: ElementKey
|
||||
}
|
||||
|
||||
/** The references dialog's title: its name, and the focus of last resort (P20). */
|
||||
export const CITATIONS_TITLE_ID = 'editor-citations-title'
|
||||
|
||||
/** The finding read from the current document; null once the document lacks it. */
|
||||
function useCitedFinding(citedBy: ElementKey) {
|
||||
const doc = useSheetDocument()
|
||||
@@ -33,13 +34,12 @@ interface Held {
|
||||
/**
|
||||
* P20: when the row that holds the focus leaves the list (an undo that removes the
|
||||
* reference), the focus goes to the next row's button, else the
|
||||
* previous row's, else the heading. A row swapped for another at the same index (a
|
||||
* previous row's, else the dialog's title. A row swapped for another at the same index (a
|
||||
* tile turned into « Référence introuvable ») counts as gone, so « next » is the one
|
||||
* after it.
|
||||
*/
|
||||
function useFocusRescue() {
|
||||
const list = useRef<HTMLUListElement>(null)
|
||||
const heading = useRef<HTMLHeadingElement>(null)
|
||||
const held = useRef<Held | null>(null)
|
||||
const rowsOf = () => [...(list.current?.children ?? [])]
|
||||
const hold = (element: Element, at: number) => {
|
||||
@@ -58,34 +58,30 @@ function useFocusRescue() {
|
||||
const rows = rowsOf()
|
||||
const next = rows.length < was.rows ? was.at : was.at + 1
|
||||
const row = rows[next] ?? rows[was.at - 1]
|
||||
const target = row?.querySelector('button') ?? heading.current
|
||||
const target =
|
||||
row?.querySelector('button') ??
|
||||
document.getElementById(CITATIONS_TITLE_ID)
|
||||
target?.focus()
|
||||
})
|
||||
return {
|
||||
list,
|
||||
heading,
|
||||
track,
|
||||
}
|
||||
return { list, track }
|
||||
}
|
||||
|
||||
/**
|
||||
* What the panel shows of the finding: its cited ids and its path. Once the finding is
|
||||
* gone (the sheet is leaving) the last known answer stays, so the sheet does not empty
|
||||
* while it slides out and a tile in edit can still be asked to apply its draft. Opened
|
||||
* from the edit form, it lists the form's staged citations, not the document's.
|
||||
* What the dialog shows of the finding: the ids the document says it cites, and its
|
||||
* path. Once the finding is gone (the dialog is leaving) the last known answer stays, so
|
||||
* the dialog does not empty during its exit.
|
||||
*/
|
||||
function useShownFinding(
|
||||
doc: ReturnType<typeof useSheetDocument>,
|
||||
item: FindingItem | null,
|
||||
citedBy: ElementKey,
|
||||
) {
|
||||
const staged = useCitationDraft((s) => draftIdsFor(s.draft, citedBy))
|
||||
const found = useMemo(
|
||||
() =>
|
||||
doc && item
|
||||
? { ids: staged ?? citedIds(item), path: findingPath(doc, citedBy) }
|
||||
? { ids: citedIds(item), path: findingPath(doc, citedBy) }
|
||||
: null,
|
||||
[doc, item, citedBy, staged],
|
||||
[doc, item, citedBy],
|
||||
)
|
||||
const [last, setLast] = useState(found)
|
||||
if (found !== null && found !== last) setLast(found)
|
||||
@@ -100,7 +96,7 @@ function useCitedEntries(hooks: PanelHooks) {
|
||||
return { doc, path, entries, keys: tileKeys(entries) }
|
||||
}
|
||||
|
||||
/** What the citations panel reads: the cited entries and their tiles. */
|
||||
/** What the references dialog reads: the cited entries and their tiles. */
|
||||
export function useCitationsPanel(hooks: PanelHooks) {
|
||||
const { doc, path, entries, keys } = useCitedEntries(hooks)
|
||||
const tiles = useTileState(doc ? keys : null)
|
||||
@@ -113,7 +109,6 @@ export function useCitationsPanel(hooks: PanelHooks) {
|
||||
citers: doc ? citersOf(doc) : new Map<string, never[]>(),
|
||||
path,
|
||||
list: focus.list,
|
||||
heading: focus.heading,
|
||||
trackFocus: focus.track,
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,11 @@ export interface DialogProps {
|
||||
/** A view layer of the editor (ModalDialog): a Back may close it. */
|
||||
layer?: boolean
|
||||
title: string
|
||||
/**
|
||||
* A fixed id for the title, for parts that point at it; the title then also takes a
|
||||
* programmatic focus (a fallback when the control holding it leaves).
|
||||
*/
|
||||
titleId?: string
|
||||
/** The dialog's message, announced with its name (aria-describedby). */
|
||||
description?: ReactNode
|
||||
children: ReactNode
|
||||
@@ -25,6 +30,9 @@ const SIZE: Record<NonNullable<DialogProps['size']>, string> = {
|
||||
xl: 'max-w-4xl',
|
||||
}
|
||||
|
||||
/** The title; `outline-none`: only a script focuses it (`titleId`), never a key. */
|
||||
const TITLE = 'text-lg font-semibold text-[var(--color-ink)] outline-none'
|
||||
|
||||
export default function Dialog({ open, ...surface }: DialogProps) {
|
||||
return (
|
||||
<AnimatePresence>{open && <DialogSurface {...surface} />}</AnimatePresence>
|
||||
@@ -36,6 +44,7 @@ function DialogSurface({
|
||||
returnFocus,
|
||||
layer,
|
||||
title,
|
||||
titleId,
|
||||
description,
|
||||
children,
|
||||
size = 'md',
|
||||
@@ -43,14 +52,14 @@ function DialogSurface({
|
||||
const t = useT()
|
||||
const reduced = useReducedMotion()
|
||||
const scale = reduced ? 1 : 0.96
|
||||
const titleId = useId()
|
||||
const ownTitleId = useId()
|
||||
const descriptionId = useId()
|
||||
return (
|
||||
<ModalDialog
|
||||
onClose={onClose}
|
||||
returnFocus={returnFocus}
|
||||
layer={layer}
|
||||
labelledBy={titleId}
|
||||
labelledBy={titleId ?? ownTitleId}
|
||||
describedBy={description ? descriptionId : undefined}
|
||||
className="open:flex items-center justify-center p-3 sm:p-4"
|
||||
>
|
||||
@@ -72,8 +81,9 @@ function DialogSurface({
|
||||
>
|
||||
<header className="flex items-center justify-between px-4 sm:px-6 py-3 sm:py-4 border-b border-[var(--color-border)]">
|
||||
<h2
|
||||
id={titleId}
|
||||
className="text-lg font-semibold text-[var(--color-ink)]"
|
||||
id={titleId ?? ownTitleId}
|
||||
tabIndex={titleId ? -1 : undefined}
|
||||
className={TITLE}
|
||||
>
|
||||
{title}
|
||||
</h2>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { FindingLayer, ReferenceLayer } from './tabs'
|
||||
import type { EditorNavigation } from './useEditorNavigation'
|
||||
|
||||
/** What Constats needs of the navigation for its dialog and the sheet over it. */
|
||||
/** What Constats needs of the navigation for its dialog and the citations dialog over it. */
|
||||
export function findingLayerOf(nav: EditorNavigation): FindingLayer {
|
||||
return {
|
||||
view: nav.state.finding,
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
import { create } from 'zustand'
|
||||
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||
|
||||
/** The citations an open edit form holds, for the side sheet opened from that form. */
|
||||
interface CitationDraft {
|
||||
key: ElementKey
|
||||
ids: readonly string[]
|
||||
}
|
||||
|
||||
interface CitationDraftStore {
|
||||
draft: CitationDraft | null
|
||||
publish: (draft: CitationDraft | null) => void
|
||||
}
|
||||
|
||||
// shortcut: module-level store because the citations sheet is a sibling of the finding
|
||||
// dialog, so no React context reaches both. It holds one draft at a time (one edit form
|
||||
// is open at once). Upgrade path: a provider above the dialog and the sheet.
|
||||
export const useCitationDraft = create<CitationDraftStore>((set) => ({
|
||||
draft: null,
|
||||
publish: (draft) => set({ draft }),
|
||||
}))
|
||||
|
||||
/** The ids the sheet of `key` lists instead of the document's, null when none are staged. */
|
||||
export function draftIdsFor(
|
||||
draft: CitationDraft | null,
|
||||
key: ElementKey,
|
||||
): readonly string[] | null {
|
||||
if (!draft || JSON.stringify(draft.key) !== JSON.stringify(key)) return null
|
||||
return draft.ids
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||
import { MAX_FINDING_PATH } from '../findings/tree'
|
||||
import {
|
||||
ANNOTATION_SECTIONS,
|
||||
isFindingNode,
|
||||
isCitable,
|
||||
sameView,
|
||||
type AnnotationSection,
|
||||
type EditorView,
|
||||
@@ -67,18 +67,18 @@ function sanitizeCreation(raw: unknown): EditorView['finding'] {
|
||||
return { create: { kind, parent: key } }
|
||||
}
|
||||
|
||||
/** The finding layer of a view: its dialog, with its citations sheet over it. */
|
||||
/** The finding layer of a view: its dialog, with its citations dialog over it. */
|
||||
function sanitizeFinding(raw: unknown, forms: boolean): EditorView['finding'] {
|
||||
if (!isRecord(raw)) return null
|
||||
if ('create' in raw) return forms ? sanitizeCreation(raw) : null
|
||||
const key = sanitizeKey(raw.key)
|
||||
if (!key) return null
|
||||
const sheet = raw.citations === true && isFindingNode(key)
|
||||
return { key, citations: sheet }
|
||||
const citations = raw.citations === true && isCitable(key)
|
||||
return { key, citations }
|
||||
}
|
||||
|
||||
/**
|
||||
* The reference dialog of a view: over the References tab, or over the citations sheet
|
||||
* The reference dialog of a view: over the References tab, or over the citations dialog
|
||||
* (the only other place that opens it). A form, so only read back where forms are kept;
|
||||
* whether the reference still exists is the dialog's own gone rule.
|
||||
*/
|
||||
@@ -88,17 +88,17 @@ function sanitizeReference(
|
||||
tab: unknown,
|
||||
): EditorView['reference'] {
|
||||
if (!isRecord(raw)) return null
|
||||
const sheet = !!finding && 'key' in finding && finding.citations
|
||||
const cited = !!finding && 'key' in finding && finding.citations
|
||||
if (raw.create === true) return tab === 'references' ? { create: true } : null
|
||||
const id = raw.edit
|
||||
if (!isId(id) || id === '') return null
|
||||
return tab === 'references' || sheet ? { edit: id } : null
|
||||
return tab === 'references' || cited ? { edit: id } : null
|
||||
}
|
||||
|
||||
/** The finding the References tab is filtered by: a finding node, on that tab only. */
|
||||
/** The element the References tab is filtered by: a family or a node, on that tab only. */
|
||||
function sanitizeFilter(raw: unknown, tab: unknown): ElementKey | null {
|
||||
const key = tab === 'references' ? sanitizeKey(raw) : null
|
||||
return key && isFindingNode(key) ? key : null
|
||||
return key && isCitable(key) ? key : null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,13 +166,13 @@ export function ownedEntry(
|
||||
export const entryState = (entry: HistoryEntry) => ({ [ENTRY_KEY]: entry })
|
||||
|
||||
/**
|
||||
* Layers over the place: the finding dialog and the citations sheet over it, the
|
||||
* Layers over the place: the finding dialog and the citations dialog over it, the
|
||||
* reference dialog, each count one.
|
||||
*/
|
||||
export function layerCount(view: EditorView): number {
|
||||
const { finding } = view
|
||||
const sheet = finding && 'key' in finding && finding.citations
|
||||
return (finding ? 1 : 0) + (sheet ? 1 : 0) + (view.reference ? 1 : 0)
|
||||
const cited = finding && 'key' in finding && finding.citations
|
||||
return (finding ? 1 : 0) + (cited ? 1 : 0) + (view.reference ? 1 : 0)
|
||||
}
|
||||
|
||||
/** An Annotations section other than the drawing is a step over it, like a layer. */
|
||||
@@ -192,7 +192,7 @@ function isRemoval(top: EditorView, view: EditorView): boolean {
|
||||
/** What a changed view asks of the history. */
|
||||
export type HistoryWrite = 'none' | 'push' | 'replace' | 'back'
|
||||
|
||||
/** True when `view` shows the finding `key` (its dialog, with or without the sheet). */
|
||||
/** True when `view` shows the finding `key` (its dialog, with or without its citations). */
|
||||
export function showsFinding(view: EditorView, key: ElementKey): boolean {
|
||||
const { finding } = view
|
||||
const shown = finding && 'key' in finding ? finding.key : null
|
||||
|
||||
@@ -211,14 +211,14 @@ function sameLayers(a: EditorView, b: EditorView): boolean {
|
||||
)
|
||||
}
|
||||
|
||||
/** The finding dialog a view shows, without its sheet: the sheet is no form. */
|
||||
/** The finding dialog a view shows, without its citations dialog: that one holds no form. */
|
||||
function dialogOf({ finding }: EditorView): unknown {
|
||||
return finding && 'key' in finding ? { key: finding.key } : finding
|
||||
}
|
||||
|
||||
/**
|
||||
* The layers holding a form that a POP from `from` to `to` takes away, top down: the
|
||||
* citations sheet alone is no such layer, so a Back that only closes it asks nothing.
|
||||
* citations dialog alone is no such layer, so a Back that only closes it asks nothing.
|
||||
*/
|
||||
function leavingLayers(from: EditorView, to: EditorView): LayerName[] {
|
||||
const same = (a: unknown, b: unknown) =>
|
||||
@@ -249,7 +249,7 @@ function refusal(
|
||||
return leaving.find((layer) => !nav.guards.ask(layer, false).allowed) ?? null
|
||||
}
|
||||
|
||||
/** The view under the finding dialog's sheet: what lies over it is clean, it goes. */
|
||||
/** The finding dialog alone: the clean citations and reference dialogs over it go. */
|
||||
function bareFinding(view: EditorView): EditorView {
|
||||
const { finding } = view
|
||||
const shown =
|
||||
@@ -278,7 +278,7 @@ function landOnForeign(ctx: PopContext): Landing | null {
|
||||
|
||||
/**
|
||||
* A POP refused (see `refusal`): the view stays, pushed again above the entry landed on.
|
||||
* When the finding dialog refused, the clean sheet and reference dialog over it close
|
||||
* When the finding dialog refused, the clean citations and reference dialogs over it close
|
||||
* first, so its question is not hidden under them. True when refused.
|
||||
*/
|
||||
function refusePop(ctx: PopContext, landed: HistoryEntry | null): boolean {
|
||||
|
||||
@@ -41,7 +41,7 @@ function leavesEditor(event: NavigateEventLike, path: string): boolean {
|
||||
interface Watch {
|
||||
guards: Guards
|
||||
/**
|
||||
* Closes the citations sheet and a reference dialog over it: they lie over the finding
|
||||
* Closes the citations dialog and a reference dialog over it: they lie over the finding
|
||||
* dialog, so its question would be hidden under them.
|
||||
*/
|
||||
clearAbove: () => void
|
||||
@@ -73,8 +73,8 @@ function jumpTo({ api, key, watch }: Jump, keep: () => void): void {
|
||||
|
||||
/**
|
||||
* `layer` asks « Abandonner les modifications ? » and holds the jump. Its « Abandonner »
|
||||
* closes it, with the citations sheet it may have been opened from (so the next question
|
||||
* is not hidden under the sheet), and the next dirty layer under it asks in turn; the
|
||||
* closes it, with the citations dialog it may have been opened from (so the next question
|
||||
* is not hidden under the citations dialog), and the next dirty layer under it asks in turn; the
|
||||
* last one lets the jump go. Any « Continuer la saisie » drops the jump. The finding
|
||||
* dialog asks once the layers over it are closed (they are clean: it is the top dirty one).
|
||||
*/
|
||||
@@ -113,7 +113,7 @@ type LeaveNav = Pick<
|
||||
'guards' | 'state' | 'closeCitations' | 'references'
|
||||
>
|
||||
|
||||
/** Closes the sheet and the reference dialog of the navigation `latest` holds, if open. */
|
||||
/** Closes the citations dialog and the reference dialog of the navigation `latest` holds, if open. */
|
||||
function clearerOf(latest: { current: LeaveNav }): () => void {
|
||||
return () => {
|
||||
const { state, closeCitations, references } = latest.current
|
||||
|
||||
@@ -29,7 +29,7 @@ export interface FocusRequest {
|
||||
/**
|
||||
* What the browser history records of the editor (R2F-1): where the user is, never what
|
||||
* they typed. A layer (`finding`, `reference`) is a dialog over a place; `citations` is
|
||||
* the side sheet over the finding dialog; `reference` is the reference dialog above
|
||||
* the citations dialog over the finding dialog; `reference` is the reference dialog above
|
||||
* either; `referenceFilter` (only on the References tab) narrows the library to the
|
||||
* references a finding cites. The search text is a personal search: never part of a view.
|
||||
*/
|
||||
@@ -129,7 +129,7 @@ const DEFAULT_VIEW = {
|
||||
referenceFilter: null,
|
||||
} as const
|
||||
|
||||
/** The finding whose citations sheet the view shows, null when it shows none. */
|
||||
/** The finding whose citations dialog the view shows, null when it shows none. */
|
||||
export function citationsOfView(view: EditorView): ElementKey | null {
|
||||
const { finding } = view
|
||||
return finding && 'key' in finding && finding.citations ? finding.key : null
|
||||
@@ -191,20 +191,20 @@ function restoreView(
|
||||
}
|
||||
|
||||
/**
|
||||
* A finding node (kind `finding` below its family, path of two or more ids). A zone and a
|
||||
* family list their citations inline and have no panel.
|
||||
* An element that cites references: a family or a finding node (kind `finding`, a path of
|
||||
* one id or more). A zone cites none.
|
||||
*/
|
||||
export function isFindingNode(key: ElementKey): boolean {
|
||||
return key.kind === 'finding' && key.path.length > 1
|
||||
export function isCitable(key: ElementKey): boolean {
|
||||
return key.kind === 'finding' && key.path.length > 0
|
||||
}
|
||||
|
||||
/** Only a finding node has a citations sheet: any other key leaves the state as it is. */
|
||||
/** Only a citable element has a citations dialog: any other key leaves the state as it is. */
|
||||
function openCitations(state: NavigationState, citedBy: ElementKey) {
|
||||
const finding = { key: citedBy, citations: true }
|
||||
return isFindingNode(citedBy) ? shown({ ...state, finding }) : state
|
||||
return isCitable(citedBy) ? shown({ ...state, finding }) : state
|
||||
}
|
||||
|
||||
/** Closes the sheet only: the finding dialog under it stays. */
|
||||
/** Closes the citations dialog only: the finding dialog under it stays. */
|
||||
function closeCitations(state: NavigationState): NavigationState {
|
||||
const { finding } = state
|
||||
if (!finding || !('key' in finding)) return state
|
||||
@@ -217,7 +217,7 @@ function openFinding(state: NavigationState, key: ElementKey): NavigationState {
|
||||
return shown({ ...state, ...LEFT_REFERENCES, tab: 'findings', finding })
|
||||
}
|
||||
|
||||
/** The finding dialog closes with the reference dialog opened over its sheet. */
|
||||
/** The finding dialog closes with the citations and reference dialogs over it. */
|
||||
function closeFinding(state: NavigationState): NavigationState {
|
||||
const reference = state.finding ? null : state.reference
|
||||
return { ...state, finding: null, reference }
|
||||
@@ -262,7 +262,7 @@ function goTo(state: NavigationState, target: EditorTarget): NavigationState {
|
||||
|
||||
/**
|
||||
* « Tout afficher dans l'onglet Références »: the layers close, the library starts afresh
|
||||
* and lists what `filter` (the finding the sheet belongs to) cites.
|
||||
* and lists what `filter` (the finding the citations dialog belongs to) cites.
|
||||
*/
|
||||
function showAllReferences(
|
||||
state: NavigationState,
|
||||
@@ -286,7 +286,7 @@ function selectTab(state: NavigationState, tab: EditorTabId): NavigationState {
|
||||
return shown({ ...state, ...left, tab })
|
||||
}
|
||||
|
||||
/** The reference dialog of `id`, above the place (and the sheet) the view shows. */
|
||||
/** The reference dialog of `id`, above the place (and the citations dialog) the view shows. */
|
||||
function openReference(state: NavigationState, id: string): NavigationState {
|
||||
return shown({ ...state, reference: { edit: id } })
|
||||
}
|
||||
|
||||
@@ -83,9 +83,9 @@ export interface EditorPlaceProps {
|
||||
navigate: (target: EditorTarget) => void
|
||||
/** « Aller à … » with an element: the place seeds its own selection from it once. */
|
||||
focus?: FocusRequest
|
||||
/** The finding dialog and the citations sheet over it (only Constats has them). */
|
||||
/** The finding dialog and the citations dialog over it (only Constats has them). */
|
||||
layer?: FindingLayer
|
||||
/** The reference dialog and the filter (only the References tab and the sheet use them). */
|
||||
/** The reference dialog and the filter (only the References tab and the citations dialog use them). */
|
||||
references?: ReferenceLayer
|
||||
/** Bumped by « Tout afficher »: the references library resets its search once per bump. */
|
||||
libraryReset?: number
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
import {
|
||||
citationsOfView,
|
||||
initialNavigation,
|
||||
isFindingNode,
|
||||
isCitable,
|
||||
navigationReducer,
|
||||
type AnnotationSection,
|
||||
type EditorTarget,
|
||||
@@ -125,20 +125,20 @@ export interface EditorNavigation {
|
||||
closeFinding: (forced?: boolean) => boolean
|
||||
/**
|
||||
* The finding layer becomes another view of itself, by replace (no Back entry): the new
|
||||
* element's dialog, or `null` for none (the reference dialog over its sheet goes too).
|
||||
* element's dialog, or `null` for none (the dialogs over it go too).
|
||||
* With `text`, a close the user did not ask for (the element vanished): forced, said
|
||||
* once the dialogs are closed.
|
||||
*/
|
||||
replaceFinding: (key: ElementKey | null, text?: string) => void
|
||||
/** Opens the citations sheet of a finding node; any other key is ignored. */
|
||||
/** Opens the citations dialog of a family or a node; any other key is ignored. */
|
||||
openCitations: (citedBy: ElementKey, opener?: Opener) => void
|
||||
/** A user close of the sheet; false when a tile in edit refused it. */
|
||||
/** A user close of the citations dialog. */
|
||||
closeCitations: () => boolean
|
||||
/** « X références », where the focus returns once the sheet is closed. */
|
||||
/** « X références », where the focus returns once the citations dialog is closed. */
|
||||
citationsTrigger: () => HTMLElement | null
|
||||
/**
|
||||
* « Tout afficher dans l'onglet Références »: layers closed, tab shown, library reset
|
||||
* and filtered by the finding the sheet belongs to.
|
||||
* and filtered by the finding the citations dialog belongs to.
|
||||
*/
|
||||
showAllReferences: (filter: ElementKey) => void
|
||||
/** The reference dialog and the References tab's filter. */
|
||||
@@ -278,7 +278,7 @@ function useMoveTrace() {
|
||||
}
|
||||
|
||||
interface Openers {
|
||||
/** The trigger that opened the citations sheet, and the finding it belongs to. */
|
||||
/** The trigger that opened the citations dialog, and the finding it belongs to. */
|
||||
citations: RefObject<HTMLElement | null>
|
||||
citedBy: RefObject<ElementKey | null>
|
||||
section: RefObject<HTMLElement | null>
|
||||
@@ -384,12 +384,12 @@ function useFindingClosing({ dispatch, announce, guards, mark }: LayerContext) {
|
||||
return { closeFinding, replaceFinding }
|
||||
}
|
||||
|
||||
/** The citations sheet over the finding dialog: opened from a finding node only. */
|
||||
function useSheetLayer(ctx: LayerContext, openers: Openers) {
|
||||
/** The citations dialog over the finding dialog: opened for a family or a node only. */
|
||||
function useCitationsLayer(ctx: LayerContext, openers: Openers) {
|
||||
const { dispatch, mark } = ctx
|
||||
const openCitations = useCallback(
|
||||
(citedBy: ElementKey, opener?: Opener) => {
|
||||
if (!isFindingNode(citedBy)) return
|
||||
if (!isCitable(citedBy)) return
|
||||
openers.citations.current = opener ?? null
|
||||
openers.citedBy.current = citedBy
|
||||
mark()
|
||||
@@ -405,24 +405,47 @@ function useSheetLayer(ctx: LayerContext, openers: Openers) {
|
||||
return { openCitations, closeCitations }
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks every layer, top down, before a move that leaves them all; true when none refused.
|
||||
* When the finding dialog is the top one to refuse, the clean dialogs over it close first
|
||||
* so its question is the one in view (as a refused Back, `bareFinding`).
|
||||
*/
|
||||
function useAskLeaving(ctx: LayerContext, state: NavigationState) {
|
||||
const { guards, dispatch, mark } = ctx
|
||||
const cited = citationsOfView(state) !== null
|
||||
const reference = state.reference !== null
|
||||
return useCallback((): boolean => {
|
||||
const refused = [...LAYERS]
|
||||
.reverse()
|
||||
.filter((layer) => !guards.ask(layer, false).allowed)
|
||||
if (refused[0] !== 'finding' || !(cited || reference)) {
|
||||
return refused.length === 0
|
||||
}
|
||||
mark()
|
||||
if (reference) dispatch({ type: 'close_reference' })
|
||||
if (cited) dispatch({ type: 'close_citations' })
|
||||
return false
|
||||
}, [guards, dispatch, mark, cited, reference])
|
||||
}
|
||||
|
||||
/** « Aller à » and « Tout afficher » leave every layer: a layer in edit may refuse. */
|
||||
function useLeavingMoves(go: Go, guards: Guards) {
|
||||
function useLeavingMoves(go: Go, askLeaving: () => boolean) {
|
||||
const t = useT()
|
||||
const moveText = useMoveText()
|
||||
const navigate = useCallback(
|
||||
(target: EditorTarget) => {
|
||||
if (!guards.askAll(false).allowed) return
|
||||
if (!askLeaving()) return
|
||||
go({ type: 'go_to', target }, 'go_to', moveText(target))
|
||||
},
|
||||
[go, guards, moveText],
|
||||
[go, askLeaving, moveText],
|
||||
)
|
||||
const showAllReferences = useCallback(
|
||||
(filter: ElementKey) => {
|
||||
if (!guards.askAll(false).allowed) return
|
||||
if (!askLeaving()) return
|
||||
const text = t('editor.tab.references')
|
||||
go({ type: 'show_all_references', filter }, 'show_all', text)
|
||||
},
|
||||
[go, guards, t],
|
||||
[go, askLeaving, t],
|
||||
)
|
||||
return { navigate, showAllReferences }
|
||||
}
|
||||
@@ -574,8 +597,8 @@ export function useEditorNavigation(
|
||||
selectTab: useTabSelect(base.dispatch, base.mark),
|
||||
...useSectionMoves(base.go, openers),
|
||||
...useFindingLayer(ctx),
|
||||
...useSheetLayer(ctx, openers),
|
||||
...useLeavingMoves(base.go, guards),
|
||||
...useCitationsLayer(ctx, openers),
|
||||
...useLeavingMoves(base.go, useAskLeaving(ctx, base.state)),
|
||||
references: useReferenceMoves(ctx, base.trace),
|
||||
citationsTrigger: useCallback(() => triggerOf(openers), [openers]),
|
||||
guards,
|
||||
|
||||
@@ -1227,13 +1227,12 @@ export const en: Dict = {
|
||||
'editor.annotations.show_all': 'All annotations',
|
||||
'editor.annotations.deselect': 'Deselect',
|
||||
'editor.annotations.deselected': 'No annotation selected.',
|
||||
'editor.references.close': 'Close the references',
|
||||
'editor.references.search': 'Search a reference',
|
||||
'editor.references.panel_title': 'Cited references',
|
||||
'editor.references.dialog_title': 'References of the finding',
|
||||
'editor.references.panel_count_one': '{count} reference cited by this finding',
|
||||
'editor.references.panel_count_other': '{count} references cited by this finding',
|
||||
'editor.references.panel_show_all': 'Show all in the References tab',
|
||||
'editor.references.panel_empty': 'This finding no longer cites any reference.',
|
||||
'editor.references.panel_empty': 'This finding cites no reference.',
|
||||
'editor.references.this_finding': 'this finding',
|
||||
'editor.references.missing': 'Reference not found',
|
||||
'editor.references.cited_one': 'Cited {count} time',
|
||||
|
||||
@@ -1258,13 +1258,12 @@ export const fr: Dict = {
|
||||
'editor.annotations.show_all': 'Toutes les annotations',
|
||||
'editor.annotations.deselect': 'Désélectionner',
|
||||
'editor.annotations.deselected': 'Aucune annotation sélectionnée.',
|
||||
'editor.references.close': 'Fermer les références',
|
||||
'editor.references.search': 'Rechercher une référence',
|
||||
'editor.references.panel_title': 'Références citées',
|
||||
'editor.references.dialog_title': 'Références du constat',
|
||||
'editor.references.panel_count_one': '{count} référence citée par ce constat',
|
||||
'editor.references.panel_count_other': '{count} références citées par ce constat',
|
||||
'editor.references.panel_show_all': 'Tout afficher dans l\'onglet Références',
|
||||
'editor.references.panel_empty': 'Ce constat ne cite plus aucune référence.',
|
||||
'editor.references.panel_empty': 'Ce constat ne cite aucune référence.',
|
||||
'editor.references.this_finding': 'ce constat',
|
||||
'editor.references.missing': 'Référence introuvable',
|
||||
'editor.references.cited_one': 'Citée {count} fois',
|
||||
|
||||
@@ -6,7 +6,7 @@ type User = ReturnType<typeof userEvent.setup>
|
||||
|
||||
export const treeRow = (name: RegExp) => screen.getByRole('treeitem', { name })
|
||||
|
||||
/** The open finding dialog: the layer dialog that is not the citations sheet. */
|
||||
/** The open finding dialog: the layer dialog that is not the references dialog. */
|
||||
export const findingDialog = () =>
|
||||
[...document.querySelectorAll<HTMLElement>('dialog[open][data-layer]')].find(
|
||||
(dialog) => !dialog.querySelector('[data-testid="editor-citations-panel"]'),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { vi } from 'vitest'
|
||||
import type { FindingLayer } from '@/editor/tabs'
|
||||
import CitationsSheet from '@/components/editor/references/CitationsSheet'
|
||||
import CitationsDialog from '@/components/editor/references/CitationsDialog'
|
||||
import FindingsTab from '@/components/editor/tabs/FindingsTab'
|
||||
import { findingLayerOf } from '@/editor/findingLayer'
|
||||
import { citationsOfView } from '@/editor/navigation'
|
||||
@@ -8,7 +8,7 @@ import { useEditorNavigation } from '@/editor/useEditorNavigation'
|
||||
import { ReadOnlyContext } from '@/editor/editingContext'
|
||||
|
||||
/**
|
||||
* Constats with the navigation that drives its dialog and the sheet over it (what the
|
||||
* Constats with the navigation that drives its dialog and the references dialog over it (what the
|
||||
* workspace gives it), without the rest of the editor.
|
||||
*/
|
||||
export default function FindingsHost({
|
||||
@@ -25,13 +25,11 @@ export default function FindingsHost({
|
||||
reloadSheet={vi.fn()}
|
||||
layer={findingLayerOf(nav)}
|
||||
/>
|
||||
<CitationsSheet
|
||||
<CitationsDialog
|
||||
citedBy={citationsOfView(nav.state)}
|
||||
readOnly={readOnly}
|
||||
onClose={nav.closeCitations}
|
||||
onShowAll={() => undefined}
|
||||
navigate={nav.navigate}
|
||||
onEdit={nav.references.open}
|
||||
returnFocus={nav.citationsTrigger}
|
||||
/>
|
||||
</ReadOnlyContext>
|
||||
|
||||
@@ -9,13 +9,13 @@ import {
|
||||
within,
|
||||
} from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||
import type { Location, NavigateFunction } from 'react-router-dom'
|
||||
import { ENTRY_KEY, type HistoryEntry } from '@/editor/history/entry'
|
||||
import {
|
||||
forgetSessionTag,
|
||||
resolveSessionTag,
|
||||
} from '@/editor/history/sessionTag'
|
||||
import { useCitationDraft } from '@/editor/findings/citationDraft'
|
||||
import { useAuthStore } from '@/state/authStore'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { edit, insert } from '../helpers/editorFixtures'
|
||||
@@ -830,16 +830,33 @@ function citingText(ids = ['ref-a']): string {
|
||||
|
||||
const nodeIds = () =>
|
||||
doc().finding_zones[0].categories[0].children[0].reference_ids
|
||||
const cite = (user: User, label: string) =>
|
||||
user.selectOptions(inDialog().getByLabelText('Citer une référence'), label)
|
||||
const save = (user: User) =>
|
||||
user.click(inDialog().getByRole('button', { name: 'Enregistrer' }))
|
||||
const panelOpen = () => screen.queryByTestId('editor-citations-panel')
|
||||
const nodeKey: ElementKey = {
|
||||
kind: 'finding',
|
||||
zone_id: 'zone-a',
|
||||
path: ['fcat-a', 'fnode-a'],
|
||||
}
|
||||
|
||||
describe('citing references lives in the edit form (owner item 1)', () => {
|
||||
it('the view has no cite control and no remove; the trigger opens the sheet', async () => {
|
||||
/** Node A cites `ids` from now on: a change made outside the finding's edit form. */
|
||||
function citeElsewhere(ids: string[]) {
|
||||
act(() => {
|
||||
const node = doc().finding_zones[0].categories[0].children[0]
|
||||
store.getState().commit({
|
||||
op: 'update',
|
||||
key: nodeKey,
|
||||
element: { kind: 'finding_node', value: { ...node, reference_ids: ids } },
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
describe('the finding dialog holds no citation control (Rev 5, owner item 1)', () => {
|
||||
it('the view shows « Références citées » and « X références » only', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
expect(inDialog().getByText('Références citées')).toBeVisible()
|
||||
expect(inDialog().queryByText('Alpha')).toBeNull()
|
||||
expect(inDialog().queryByLabelText('Citer une référence')).toBeNull()
|
||||
expect(inDialog().queryByRole('button', { name: /^Retirer/ })).toBeNull()
|
||||
expect(
|
||||
@@ -847,7 +864,7 @@ describe('citing references lives in the edit form (owner item 1)', () => {
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
it('a family view lists its citations read-only', async () => {
|
||||
it('a family view lists nothing inline; its « X références » opens the dialog', async () => {
|
||||
let text = insert(sheetText(), reference('ref-a', 'Alpha'))
|
||||
const key = { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a'] }
|
||||
const cat = JSON.parse(text).finding_zones[0].categories[0]
|
||||
@@ -858,148 +875,48 @@ describe('citing references lives in the edit form (owner item 1)', () => {
|
||||
text = edit(text, { op: 'update', key, element } as never)
|
||||
const user = await mount(1280, text)
|
||||
await openFinding(user, /Cat A/)
|
||||
expect(inDialog().getByText('Alpha')).toBeVisible()
|
||||
expect(inDialog().queryByRole('button', { name: /^Retirer/ })).toBeNull()
|
||||
expect(inDialog().queryByLabelText('Citer une référence')).toBeNull()
|
||||
expect(inDialog().queryByText('Alpha')).toBeNull()
|
||||
await user.click(inDialog().getByRole('button', { name: '1 référence' }))
|
||||
await waitFor(() => expect(panelOpen()).not.toBeNull())
|
||||
expect(within(panelOpen()!).getByText('Alpha')).toBeVisible()
|
||||
})
|
||||
|
||||
it('the form stages a cite and a remove, written only by « Enregistrer »', async () => {
|
||||
it('a zone has no « Références citées »', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Zone A/)
|
||||
expect(inDialog().queryByText('Références citées')).toBeNull()
|
||||
})
|
||||
|
||||
it('the edit form shows the header and the button only, at zero too', async () => {
|
||||
const user = await mount(1280, citingText([]))
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
const before = entries()
|
||||
await cite(user, 'Beta')
|
||||
await user.click(inDialog().getByRole('button', { name: 'Retirer Alpha' }))
|
||||
expect(nodeIds()).toEqual(['ref-a'])
|
||||
expect(entries()).toBe(before)
|
||||
expect(inDialog().getByText('Références citées')).toBeVisible()
|
||||
expect(
|
||||
inDialog().getByRole('button', { name: '1 référence' }),
|
||||
inDialog().getByRole('button', { name: '0 référence' }),
|
||||
).toBeVisible()
|
||||
await save(user)
|
||||
expect(nodeIds()).toEqual(['ref-b'])
|
||||
expect(entries()).toBe(before + 1)
|
||||
expect(inDialog().queryByLabelText('Citer une référence')).toBeNull()
|
||||
expect(inDialog().queryByRole('button', { name: /^Retirer/ })).toBeNull()
|
||||
})
|
||||
|
||||
it('one undo restores the names and the citations together', async () => {
|
||||
it('a save keeps a citations change made elsewhere while the form was open', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
await user.clear(nameField())
|
||||
await user.type(nameField(), 'Renommé')
|
||||
await cite(user, 'Beta')
|
||||
await save(user)
|
||||
expect(doc().finding_zones[0].categories[0].children[0].name.fr).toBe(
|
||||
'Renommé',
|
||||
)
|
||||
expect(nodeIds()).toEqual(['ref-a', 'ref-b'])
|
||||
act(() => void store.getState().undoStep())
|
||||
expect(doc().finding_zones[0].categories[0].children[0].name.fr).toBe(
|
||||
'Node A',
|
||||
)
|
||||
expect(nodeIds()).toEqual(['ref-a'])
|
||||
})
|
||||
|
||||
it('a cite then its remove is pristine: « Enregistrer » writes nothing', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
citeElsewhere(['ref-a', 'ref-b'])
|
||||
const before = entries()
|
||||
await cite(user, 'Beta')
|
||||
await user.click(inDialog().getByRole('button', { name: 'Retirer Beta' }))
|
||||
await save(user)
|
||||
expect(entries()).toBe(before)
|
||||
})
|
||||
|
||||
it('« Annuler » with only a citation change asks, « Abandonner » writes nothing', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
const before = entries()
|
||||
await cite(user, 'Beta')
|
||||
await user.click(inDialog().getByRole('button', { name: 'Annuler' }))
|
||||
expect(inDialog().getByText('Abandonner les modifications ?')).toBeVisible()
|
||||
await user.click(inDialog().getByRole('button', { name: 'Abandonner' }))
|
||||
expect(entries()).toBe(before)
|
||||
expect(nodeIds()).toEqual(['ref-a'])
|
||||
})
|
||||
|
||||
it('the sheet opened from the form lists the draft and cannot remove', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
await cite(user, 'Beta')
|
||||
await user.click(inDialog().getByRole('button', { name: '2 références' }))
|
||||
await waitFor(() => expect(panelOpen()).not.toBeNull())
|
||||
const sheet = within(panelOpen()!)
|
||||
expect(sheet.getByText(/2 références citées/)).toBeVisible()
|
||||
expect(sheet.queryByRole('button', { name: /^Retirer/ })).toBeNull()
|
||||
expect(nodeIds()).toEqual(['ref-a'])
|
||||
})
|
||||
|
||||
it('the published draft returns to null on « Abandonner » and on save', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
await cite(user, 'Beta')
|
||||
expect(useCitationDraft.getState().draft?.ids).toEqual(['ref-a', 'ref-b'])
|
||||
await user.click(inDialog().getByRole('button', { name: 'Annuler' }))
|
||||
await user.click(inDialog().getByRole('button', { name: 'Abandonner' }))
|
||||
expect(useCitationDraft.getState().draft).toBeNull()
|
||||
await modify(user)
|
||||
await cite(user, 'Beta')
|
||||
await save(user)
|
||||
expect(useCitationDraft.getState().draft).toBeNull()
|
||||
})
|
||||
|
||||
it('a Retirer-only change counts and lists the draft, the document stays', async () => {
|
||||
const user = await mount(1280, citingText(['ref-a', 'ref-b']))
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
await user.click(inDialog().getByRole('button', { name: 'Retirer Alpha' }))
|
||||
await user.click(inDialog().getByRole('button', { name: '1 référence' }))
|
||||
await waitFor(() => expect(panelOpen()).not.toBeNull())
|
||||
const sheet = within(panelOpen()!)
|
||||
expect(sheet.getByText(/1 référence citée/)).toBeVisible()
|
||||
expect(sheet.getByText(/Beta/)).toBeVisible()
|
||||
expect(sheet.queryByText(/Alpha/)).toBeNull()
|
||||
const node = doc().finding_zones[0].categories[0].children[0]
|
||||
expect(node.name.fr).toBe('Renommé')
|
||||
expect(nodeIds()).toEqual(['ref-a', 'ref-b'])
|
||||
})
|
||||
|
||||
it('a read-only flip keeps a citation-only draft, never dropped silently', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
await cite(user, 'Beta')
|
||||
act(() => {
|
||||
setWidth(900)
|
||||
window.dispatchEvent(new Event('resize'))
|
||||
})
|
||||
expect(findingDialog()).not.toBeNull()
|
||||
expect(
|
||||
inDialog().getByRole('button', { name: '2 références' }),
|
||||
).toBeVisible()
|
||||
expect(inDialog().queryByLabelText('Citer une référence')).toBeNull()
|
||||
expect(
|
||||
inDialog().getByRole('button', { name: 'Enregistrer' }),
|
||||
).toBeDisabled()
|
||||
expect(nodeIds()).toEqual(['ref-a'])
|
||||
act(() => {
|
||||
setWidth(1280)
|
||||
window.dispatchEvent(new Event('resize'))
|
||||
})
|
||||
expect(
|
||||
inDialog().getByRole('button', { name: '2 références' }),
|
||||
).toBeVisible()
|
||||
expect(entries()).toBe(before + 1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('the citations sheet over a dirty edit form (final review rev 4, item 1)', () => {
|
||||
describe('the references dialog over a dirty edit form', () => {
|
||||
const question = 'Abandonner les modifications ?'
|
||||
const dialogs = () => [...document.querySelectorAll('dialog[open]')]
|
||||
const refForm = () =>
|
||||
dialogs().find((d) => d.querySelector('#reference-form-citation')) as
|
||||
| HTMLElement
|
||||
| undefined
|
||||
let api: NavigationStub
|
||||
beforeEach(() => {
|
||||
api = new NavigationStub()
|
||||
@@ -1012,13 +929,13 @@ describe('the citations sheet over a dirty edit form (final review rev 4, item 1
|
||||
Reflect.deleteProperty(window, 'navigation')
|
||||
})
|
||||
|
||||
/** Node A in edit with Beta cited in the draft, its sheet open over the form. */
|
||||
async function sheetOverDirtyForm() {
|
||||
/** Node A in edit with its name changed, its references dialog open over the form. */
|
||||
async function dialogOverDirtyForm() {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
await cite(user, 'Beta')
|
||||
await user.click(inDialog().getByRole('button', { name: '2 références' }))
|
||||
await user.type(nameField(), ' x')
|
||||
await user.click(inDialog().getByRole('button', { name: '1 référence' }))
|
||||
await waitFor(() => expect(panelOpen()).not.toBeNull())
|
||||
await waitFor(() =>
|
||||
expect(written()?.view.finding).toMatchObject({ citations: true }),
|
||||
@@ -1026,13 +943,10 @@ describe('the citations sheet over a dirty edit form (final review rev 4, item 1
|
||||
return user
|
||||
}
|
||||
|
||||
const draftKept = () =>
|
||||
expect(
|
||||
inDialog().getByRole('button', { name: '2 références' }),
|
||||
).toBeVisible()
|
||||
const draftKept = () => expect(nameField()).toHaveValue('Node A x')
|
||||
|
||||
it('a Back closes the clean sheet and asks nothing', async () => {
|
||||
await sheetOverDirtyForm()
|
||||
it('a Back closes the clean references dialog and asks nothing', async () => {
|
||||
await dialogOverDirtyForm()
|
||||
await back()
|
||||
await waitFor(() => expect(panelOpen()).toBeNull())
|
||||
expect(screen.queryByText(question)).toBeNull()
|
||||
@@ -1040,22 +954,8 @@ describe('the citations sheet over a dirty edit form (final review rev 4, item 1
|
||||
draftKept()
|
||||
})
|
||||
|
||||
it('a Back from a clean reference dialog over the sheet closes it only', async () => {
|
||||
const user = await sheetOverDirtyForm()
|
||||
const sheet = within(panelOpen()!)
|
||||
const head = sheet.getByRole('button', { name: /^Alpha/ })
|
||||
if (head.getAttribute('aria-expanded') === 'false') await user.click(head)
|
||||
const tile = within(head.closest('li')!)
|
||||
await user.click(tile.getByRole('button', { name: 'Modifier' }))
|
||||
await waitFor(() => expect(refForm()).toBeDefined())
|
||||
await back()
|
||||
await waitFor(() => expect(refForm()).toBeUndefined())
|
||||
expect(panelOpen()).not.toBeNull()
|
||||
expect(screen.queryByText(question)).toBeNull()
|
||||
})
|
||||
|
||||
it('a jump of two entries inside the editor closes the sheet, then the form asks', async () => {
|
||||
await sheetOverDirtyForm()
|
||||
it('a jump of two entries inside the editor closes the dialog, then the form asks', async () => {
|
||||
await dialogOverDirtyForm()
|
||||
await act(async () => navigate(-2))
|
||||
await waitFor(() => expect(panelOpen()).toBeNull())
|
||||
expect(inDialog().getByText(question)).toBeVisible()
|
||||
@@ -1066,103 +966,8 @@ describe('the citations sheet over a dirty edit form (final review rev 4, item 1
|
||||
draftKept()
|
||||
})
|
||||
|
||||
it('after the cascade keeps the form, one Back reopens the sheet (docs, limit 5)', async () => {
|
||||
const user = await sheetOverDirtyForm()
|
||||
const sheet = within(panelOpen()!)
|
||||
const head = sheet.getByRole('button', { name: /^Alpha/ })
|
||||
if (head.getAttribute('aria-expanded') === 'false') await user.click(head)
|
||||
const tile = within(head.closest('li')!)
|
||||
await user.click(tile.getByRole('button', { name: 'Modifier' }))
|
||||
await waitFor(() => expect(refForm()).toBeDefined())
|
||||
await user.type(within(refForm()!).getByLabelText('Citation'), ' x')
|
||||
const url = new URL('/app/admin/sheets', window.location.origin).href
|
||||
const event = Object.assign(new Event('navigate', { cancelable: true }), {
|
||||
navigationType: 'traverse',
|
||||
destination: { url, key: 'list', sameDocument: true },
|
||||
})
|
||||
act(() => {
|
||||
api.dispatchEvent(event)
|
||||
})
|
||||
await user.click(
|
||||
within(refForm()!).getByRole('button', { name: 'Abandonner' }),
|
||||
)
|
||||
await waitFor(() => expect(panelOpen()).toBeNull())
|
||||
// The reference dialog plays its exit, then leaves: only the finding dialog stays.
|
||||
await waitFor(() => expect(dialogs()).toHaveLength(1))
|
||||
await user.click(
|
||||
inDialog().getByRole('button', { name: 'Continuer la saisie' }),
|
||||
)
|
||||
await back()
|
||||
await waitFor(() => expect(panelOpen()).not.toBeNull())
|
||||
expect(screen.queryByText(question)).toBeNull()
|
||||
expect(api.traverseTo).not.toHaveBeenCalled()
|
||||
draftKept()
|
||||
})
|
||||
|
||||
/** The reference Alpha's edit dialog opened from the sheet; `dirty` types in it. */
|
||||
async function referenceOverSheet(user: User, dirty: boolean) {
|
||||
const sheet = within(panelOpen()!)
|
||||
const head = sheet.getByRole('button', { name: /^Alpha/ })
|
||||
if (head.getAttribute('aria-expanded') === 'false') await user.click(head)
|
||||
const tile = within(head.closest('li')!)
|
||||
await user.click(tile.getByRole('button', { name: 'Modifier' }))
|
||||
await waitFor(() => expect(refForm()).toBeDefined())
|
||||
if (dirty)
|
||||
await user.type(within(refForm()!).getByLabelText('Citation'), ' x')
|
||||
}
|
||||
|
||||
it('a jump of three entries asks the dirty reference only, nothing stays pending under it', async () => {
|
||||
const user = await sheetOverDirtyForm()
|
||||
await referenceOverSheet(user, true)
|
||||
await act(async () => navigate(-3))
|
||||
await waitFor(() => expect(screen.queryAllByText(question)).toHaveLength(1))
|
||||
expect(refForm()!.contains(screen.getByText(question))).toBe(true)
|
||||
await user.click(
|
||||
within(refForm()!).getByRole('button', { name: 'Abandonner' }),
|
||||
)
|
||||
await waitFor(() => expect(refForm()).toBeUndefined())
|
||||
// The refused jump is dropped: the sheet stays, and no question comes up unasked.
|
||||
expect(panelOpen()).not.toBeNull()
|
||||
expect(screen.queryByText(question)).toBeNull()
|
||||
draftKept()
|
||||
})
|
||||
|
||||
it('a clean reference over the sheet over a dirty form: a Back asks the form in view', async () => {
|
||||
const user = await sheetOverDirtyForm()
|
||||
await referenceOverSheet(user, false)
|
||||
await act(async () => navigate(-3))
|
||||
await waitFor(() => expect(panelOpen()).toBeNull())
|
||||
await waitFor(() => expect(refForm()).toBeUndefined())
|
||||
expect(inDialog().getByText(question)).toBeVisible()
|
||||
await waitFor(() =>
|
||||
expect(findingDialog()!.contains(document.activeElement)).toBe(true),
|
||||
)
|
||||
draftKept()
|
||||
})
|
||||
|
||||
it('a clean reference over the sheet over a dirty form: a leave out asks the form in view', async () => {
|
||||
const user = await sheetOverDirtyForm()
|
||||
await referenceOverSheet(user, false)
|
||||
const url = new URL('/app/admin/sheets', window.location.origin).href
|
||||
const event = Object.assign(new Event('navigate', { cancelable: true }), {
|
||||
navigationType: 'traverse',
|
||||
destination: { url, key: 'list', sameDocument: true },
|
||||
})
|
||||
act(() => {
|
||||
api.dispatchEvent(event)
|
||||
})
|
||||
expect(event.defaultPrevented).toBe(true)
|
||||
await waitFor(() => expect(panelOpen()).toBeNull())
|
||||
await waitFor(() => expect(refForm()).toBeUndefined())
|
||||
expect(inDialog().getByText(question)).toBeVisible()
|
||||
await waitFor(() =>
|
||||
expect(findingDialog()!.contains(document.activeElement)).toBe(true),
|
||||
)
|
||||
draftKept()
|
||||
})
|
||||
|
||||
it('a jump out of the editor closes the sheet, then the form asks in view', async () => {
|
||||
await sheetOverDirtyForm()
|
||||
it('a jump out of the editor closes the dialog, then the form asks in view', async () => {
|
||||
await dialogOverDirtyForm()
|
||||
const url = new URL('/app/admin/sheets', window.location.origin).href
|
||||
const event = Object.assign(new Event('navigate', { cancelable: true }), {
|
||||
navigationType: 'traverse',
|
||||
@@ -1179,4 +984,38 @@ describe('the citations sheet over a dirty edit form (final review rev 4, item 1
|
||||
)
|
||||
draftKept()
|
||||
})
|
||||
|
||||
it('« Tout afficher » refused by the form: the dialog closes first, the question in view', async () => {
|
||||
const user = await dialogOverDirtyForm()
|
||||
await user.click(
|
||||
within(panelOpen()!).getByRole('button', {
|
||||
name: "Tout afficher dans l'onglet Références",
|
||||
}),
|
||||
)
|
||||
await waitFor(() => expect(panelOpen()).toBeNull())
|
||||
expect(inDialog().getByText(question)).toBeVisible()
|
||||
await waitFor(() =>
|
||||
expect(document.activeElement).toBe(
|
||||
inDialog().getByRole('button', { name: 'Continuer la saisie' }),
|
||||
),
|
||||
)
|
||||
expect(written()?.view.tab).toBe('findings')
|
||||
expect(written()?.view.finding).toMatchObject({ citations: false })
|
||||
draftKept()
|
||||
})
|
||||
|
||||
it('« Aller à » refused by the form: the dialog closes first, the question in view', async () => {
|
||||
const user = await dialogOverDirtyForm()
|
||||
const sheet = within(panelOpen()!)
|
||||
await user.click(sheet.getByRole('button', { name: /^Alpha/ }))
|
||||
await user.click(sheet.getAllByRole('button', { name: /^Aller à / })[0])
|
||||
await waitFor(() => expect(panelOpen()).toBeNull())
|
||||
expect(inDialog().getByText(question)).toBeVisible()
|
||||
await waitFor(() =>
|
||||
expect(document.activeElement).toBe(
|
||||
inDialog().getByRole('button', { name: 'Continuer la saisie' }),
|
||||
),
|
||||
)
|
||||
draftKept()
|
||||
})
|
||||
})
|
||||
@@ -1,6 +1,7 @@
|
||||
/** Lot I: the Constats tree. */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
act,
|
||||
cleanup,
|
||||
render,
|
||||
screen,
|
||||
@@ -590,7 +591,7 @@ describe('Constats tab', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('edits descriptions (blank side omitted), the vet flag and the citations in one save', async () => {
|
||||
it('edits descriptions (blank side omitted) and the vet flag in one save, citations kept', async () => {
|
||||
let text = treeText()
|
||||
text = insert(text, {
|
||||
kind: 'reference',
|
||||
@@ -628,66 +629,29 @@ describe('Constats tab', () => {
|
||||
await user.clear(inFindingDialog().getByLabelText('Description (FR)'))
|
||||
await save()
|
||||
expect(node().description).toEqual({})
|
||||
// the view cites nothing: « Citer une référence » is the edit form's
|
||||
// Neither mode cites: the references dialog holds the citations (Rev 5).
|
||||
expect(inFindingDialog().queryByLabelText('Citer une référence')).toBeNull()
|
||||
await startEdit(user)
|
||||
await user.selectOptions(
|
||||
inFindingDialog().getByLabelText('Citer une référence'),
|
||||
'ref-a',
|
||||
)
|
||||
expect(node().reference_ids).toEqual([])
|
||||
expect(inFindingDialog().queryByLabelText('Citer une référence')).toBeNull()
|
||||
act(() => {
|
||||
store.getState().commit({
|
||||
op: 'update',
|
||||
key: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a', 'node-a'] },
|
||||
element: {
|
||||
kind: 'finding_node',
|
||||
value: { ...node(), reference_ids: ['ref-a'] },
|
||||
},
|
||||
})
|
||||
})
|
||||
await user.type(inFindingDialog().getByLabelText('Description (FR)'), 'B')
|
||||
await save()
|
||||
expect(node().description).toEqual({ fr: 'B' })
|
||||
expect(node().reference_ids).toEqual(['ref-a'])
|
||||
expect(
|
||||
inFindingDialog().getByRole('button', { name: '1 référence' }),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('a family cites and removes in its edit form, one save writes both', async () => {
|
||||
let text = treeText()
|
||||
text = insert(text, {
|
||||
kind: 'reference',
|
||||
value: {
|
||||
id: 'ref-a',
|
||||
type: 'book',
|
||||
citation: 'Alpha',
|
||||
url: null,
|
||||
doi: null,
|
||||
},
|
||||
})
|
||||
await openReady({ text })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsHost />)
|
||||
await user.click(items()[1])
|
||||
const family = () => doc().finding_zones[0].categories[0]
|
||||
await startEdit(user)
|
||||
await user.selectOptions(
|
||||
inFindingDialog().getByLabelText('Citer une référence'),
|
||||
'ref-a',
|
||||
)
|
||||
expect(
|
||||
inFindingDialog().getByRole('button', { name: /Retirer Alpha/ }),
|
||||
).toBeInTheDocument()
|
||||
await user.click(
|
||||
inFindingDialog().getByRole('button', { name: /Retirer Alpha/ }),
|
||||
)
|
||||
expect(
|
||||
inFindingDialog().getByText('Aucune référence citée.'),
|
||||
).toBeInTheDocument()
|
||||
await user.selectOptions(
|
||||
inFindingDialog().getByLabelText('Citer une référence'),
|
||||
'ref-a',
|
||||
)
|
||||
expect(family().reference_ids).toEqual([])
|
||||
await user.click(
|
||||
inFindingDialog().getByRole('button', { name: 'Enregistrer' }),
|
||||
)
|
||||
expect(family().reference_ids).toEqual(['ref-a'])
|
||||
expect(
|
||||
inFindingDialog().queryByRole('button', { name: /Retirer/ }),
|
||||
).toBeNull()
|
||||
})
|
||||
|
||||
it('the trigger shows exactly for the keys open_citations accepts', async () => {
|
||||
let text = insert(treeText(), {
|
||||
kind: 'reference',
|
||||
@@ -733,7 +697,7 @@ describe('Constats tab', () => {
|
||||
}
|
||||
expect(truth).toEqual([
|
||||
['zone', false],
|
||||
['category', false],
|
||||
['category', true],
|
||||
['node', true],
|
||||
['node', true],
|
||||
['zone', false],
|
||||
@@ -742,7 +706,7 @@ describe('Constats tab', () => {
|
||||
expect(all.filter((item) => item.kind === 'node')).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('the trigger reads « expanded » while the sheet of its finding is open', async () => {
|
||||
it('the trigger reads « expanded » while the references dialog of its finding is open', async () => {
|
||||
let text = insert(treeText(), {
|
||||
kind: 'reference',
|
||||
value: { id: 'ref-a', type: 'book', citation: 'A', url: null, doi: null },
|
||||
@@ -771,9 +735,10 @@ describe('Constats tab', () => {
|
||||
expect(trigger()).toHaveAttribute('aria-controls', 'editor-citations-panel')
|
||||
await user.click(trigger())
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'true')
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Fermer les références' }),
|
||||
)
|
||||
const citations = screen
|
||||
.getByTestId('editor-citations-panel')
|
||||
.closest('dialog')!
|
||||
await user.click(within(citations).getByRole('button', { name: 'Fermer' }))
|
||||
await waitFor(() =>
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'false'),
|
||||
)
|
||||
|
||||
@@ -57,12 +57,18 @@ describe('sanitizeView', () => {
|
||||
expect(layerCount(sanitizeView(sheet)!)).toBe(2)
|
||||
})
|
||||
|
||||
it('a sheet needs a finding node, a layer needs the Constats tab', () => {
|
||||
it('citations need a family or a node, a layer needs the Constats tab', () => {
|
||||
const family = { kind: 'finding', zone_id: 'z', path: ['f'] }
|
||||
const zone = { kind: 'zone', id: 'z' }
|
||||
const raw = { tab: 'findings', section: 'drawing' }
|
||||
const asked = { ...raw, finding: { key: family, citations: true } }
|
||||
expect(sanitizeView(asked)?.finding).toEqual({
|
||||
key: family,
|
||||
citations: true,
|
||||
})
|
||||
const ofZone = { ...raw, finding: { key: zone, citations: true } }
|
||||
expect(sanitizeView(ofZone)?.finding).toEqual({
|
||||
key: zone,
|
||||
citations: false,
|
||||
})
|
||||
const elsewhere = {
|
||||
@@ -108,9 +114,12 @@ describe('sanitizeView', () => {
|
||||
).toBeNull()
|
||||
})
|
||||
|
||||
it('the finding filter names a finding node and lives on the References tab only', () => {
|
||||
it('the finding filter names a family or a node and lives on the References tab only', () => {
|
||||
const filtered = view('references', { referenceFilter: node })
|
||||
expect(sanitizeView(filtered)?.referenceFilter).toEqual(node)
|
||||
const family = { kind: 'finding' as const, zone_id: 'z', path: ['f'] }
|
||||
const byFamily = view('references', { referenceFilter: family })
|
||||
expect(sanitizeView(byFamily)?.referenceFilter).toEqual(family)
|
||||
expect(sanitizeView(filtered, false)?.referenceFilter).toEqual(node)
|
||||
expect(
|
||||
sanitizeView({ ...view('general'), referenceFilter: node })
|
||||
|
||||
@@ -128,16 +128,14 @@ describe('navigationReducer', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('open_citations opens for a finding node only', () => {
|
||||
it('open_citations opens for a family or a finding node only', () => {
|
||||
const base = initialNavigation('findings')
|
||||
const opened = run(base, { type: 'open_citations', citedBy: node })
|
||||
expect(citationsOfView(opened)).toBe(node)
|
||||
expect(opened.finding).toEqual({ key: node, citations: true })
|
||||
for (const refused of [
|
||||
finding,
|
||||
view,
|
||||
{ kind: 'zone', id: 'z1' } as const,
|
||||
]) {
|
||||
for (const citable of [node, finding]) {
|
||||
const opened = run(base, { type: 'open_citations', citedBy: citable })
|
||||
expect(citationsOfView(opened)).toBe(citable)
|
||||
expect(opened.finding).toEqual({ key: citable, citations: true })
|
||||
}
|
||||
for (const refused of [view, { kind: 'zone', id: 'z1' } as const]) {
|
||||
const state = run(base, { type: 'open_citations', citedBy: refused })
|
||||
expect(state).toBe(base)
|
||||
}
|
||||
|
||||
@@ -559,96 +559,3 @@ describe('final review: the creation dialog fades out as a creation (M-9)', () =
|
||||
expect(titles).not.toContain('Modifier la référence')
|
||||
})
|
||||
})
|
||||
|
||||
/** The Navigation API as the leave guard reads it: `navigate` events and `traverseTo`. */
|
||||
class NavigationStub extends EventTarget {
|
||||
traverseTo = vi.fn((key: string) => {
|
||||
void key
|
||||
return { committed: Promise.resolve(), finished: Promise.resolve() }
|
||||
})
|
||||
}
|
||||
|
||||
describe('a jump with the reference over the sheet of a dirty finding (criterion 23)', () => {
|
||||
let api: NavigationStub
|
||||
beforeEach(() => {
|
||||
api = new NavigationStub()
|
||||
Object.defineProperty(window, 'navigation', {
|
||||
value: api,
|
||||
configurable: true,
|
||||
})
|
||||
})
|
||||
afterEach(() => {
|
||||
Reflect.deleteProperty(window, 'navigation')
|
||||
})
|
||||
|
||||
const sheet = () =>
|
||||
[...dialogs()].find((d) => d.querySelector('[data-place="citations"]'))
|
||||
const question = 'Abandonner les modifications ?'
|
||||
/** The reference dialog: the finding's edit form is a draft form too. */
|
||||
const refForm = () =>
|
||||
[...dialogs()].find((d) => d.querySelector('#reference-form-citation')) as
|
||||
| HTMLElement
|
||||
| undefined
|
||||
const inForm = () => within(refForm()!)
|
||||
|
||||
function jump() {
|
||||
const url = new URL('/app/admin/sheets', window.location.origin).href
|
||||
const event = Object.assign(new Event('navigate', { cancelable: true }), {
|
||||
navigationType: 'traverse',
|
||||
destination: { url, key: 'list', sameDocument: true },
|
||||
})
|
||||
act(() => {
|
||||
api.dispatchEvent(event)
|
||||
})
|
||||
return event
|
||||
}
|
||||
|
||||
/** Node A in edit with a typed name, its sheet open, Barone in edit with a typed citation. */
|
||||
async function stacked(user: User) {
|
||||
await user.click(screen.getByRole('tab', { name: 'Constats' }))
|
||||
await openFinding(user, /Node A/)
|
||||
const finding = within(findingDialog()!)
|
||||
await user.click(finding.getByRole('button', { name: 'Modifier' }))
|
||||
await user.type(finding.getByLabelText('Nom (FR)'), ' bis')
|
||||
await user.click(finding.getByRole('button', { name: '2 références' }))
|
||||
await waitFor(() => expect(sheet()).toBeDefined())
|
||||
const inSheet = within(sheet() as HTMLElement)
|
||||
const head = inSheet.getByRole('button', { name: /^Barone/ })
|
||||
if (head.getAttribute('aria-expanded') === 'false') await user.click(head)
|
||||
const tile = head.closest('li')!
|
||||
await user.click(within(tile).getByRole('button', { name: 'Modifier' }))
|
||||
await waitFor(() => expect(refForm()).toBeDefined())
|
||||
await user.type(inForm().getByLabelText('Citation'), ' x')
|
||||
}
|
||||
|
||||
it('the finding asks next with the sheet closed, focused; the jump goes after it', async () => {
|
||||
const user = await mount()
|
||||
await stacked(user)
|
||||
expect(jump().defaultPrevented).toBe(true)
|
||||
expect(inForm().getByText(question)).toBeVisible()
|
||||
await user.click(inForm().getByRole('button', { name: 'Abandonner' }))
|
||||
await waitFor(() => expect(refForm()).toBeUndefined())
|
||||
await waitFor(() => expect(sheet()).toBeUndefined())
|
||||
const finding = within(findingDialog()!)
|
||||
expect(finding.getByText(question)).toBeVisible()
|
||||
const keep = finding.getByRole('button', { name: 'Continuer la saisie' })
|
||||
await waitFor(() => expect(keep).toHaveFocus())
|
||||
expect(api.traverseTo).not.toHaveBeenCalled()
|
||||
await user.click(finding.getByRole('button', { name: 'Abandonner' }))
|
||||
expect(api.traverseTo).toHaveBeenCalledWith('list')
|
||||
})
|
||||
|
||||
it('« Continuer la saisie » there keeps the finding draft and drops the jump', async () => {
|
||||
const user = await mount()
|
||||
await stacked(user)
|
||||
jump()
|
||||
await user.click(inForm().getByRole('button', { name: 'Abandonner' }))
|
||||
await waitFor(() => expect(sheet()).toBeUndefined())
|
||||
const finding = within(findingDialog()!)
|
||||
await user.click(
|
||||
finding.getByRole('button', { name: 'Continuer la saisie' }),
|
||||
)
|
||||
expect(finding.getByLabelText('Nom (FR)')).toHaveValue('Node A bis')
|
||||
expect(api.traverseTo).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
/** R2.4: the citations panel of one finding (board 25): contents, « Retirer », motion, closes, focus. */
|
||||
/** R2.4, Rev 5: the references dialog of one finding: contents, view mode, closes, focus. */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
act,
|
||||
@@ -109,12 +109,15 @@ const ready = () =>
|
||||
screen.findByRole('heading', { level: 1, name: 'Brouillon, version 4' })
|
||||
const panel = () => screen.getByTestId('editor-citations-panel')
|
||||
const hasPanel = () => screen.queryByTestId('editor-citations-panel') !== null
|
||||
const layer = () => panel().closest('[data-place="citations"]')!
|
||||
const citationsDialog = () => panel().closest('dialog')!
|
||||
const tiles = () => [...panel().querySelectorAll('ul > li')]
|
||||
const trigger = (name = '2 références') =>
|
||||
inFindingDialog().getByRole('button', { name })
|
||||
const heading = () =>
|
||||
within(panel()).getByRole('heading', { name: 'Références citées' })
|
||||
within(citationsDialog()).getByRole('heading', {
|
||||
name: 'Références du constat',
|
||||
})
|
||||
const backdrop = () => within(citationsDialog()).getByTestId('dialog-backdrop')
|
||||
const doc = () => JSON.parse(store.getState().documentText)
|
||||
const nodeA = () =>
|
||||
doc().finding_zones[0].categories[0].children[0] as {
|
||||
@@ -148,7 +151,7 @@ async function select(user: User, label: RegExp) {
|
||||
await openFinding(user, label)
|
||||
}
|
||||
|
||||
/** The sheet of Node A, open over its dialog: its first control (✕) holds the focus. */
|
||||
/** The references dialog of Node A, over its dialog: its first control (✕) holds the focus. */
|
||||
async function openFromFinding(user: User, name = '2 références') {
|
||||
await select(user, /Node A/)
|
||||
await user.click(trigger(name))
|
||||
@@ -161,10 +164,10 @@ const link = () =>
|
||||
})
|
||||
|
||||
const closeButton = () =>
|
||||
within(panel()).getByRole('button', { name: 'Fermer les références' })
|
||||
within(citationsDialog()).getByRole('button', { name: 'Fermer' })
|
||||
|
||||
describe('opening', () => {
|
||||
it('has no header button; only a finding opens it, its heading takes the focus after the slide', async () => {
|
||||
it('has no header button; « X références » opens a modal dialog over the finding, ✕ focused', async () => {
|
||||
const user = await mount()
|
||||
expect(screen.queryByRole('button', { name: 'Références' })).toBeNull()
|
||||
expect(hasPanel()).toBe(false)
|
||||
@@ -173,23 +176,37 @@ describe('opening', () => {
|
||||
expect(trigger()).toHaveAttribute('aria-controls', 'editor-citations-panel')
|
||||
await user.click(trigger())
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'true')
|
||||
expect(document.activeElement).not.toBe(heading())
|
||||
await focusIs(closeButton)
|
||||
expect(panel()).toHaveAttribute('aria-labelledby', 'editor-citations-title')
|
||||
expect(heading()).toHaveAttribute('id', 'editor-citations-title')
|
||||
expect(citationsDialog()).toHaveAttribute(
|
||||
'aria-labelledby',
|
||||
'editor-citations-title',
|
||||
)
|
||||
expect(citationsDialog()).toHaveAttribute('data-layer')
|
||||
expect(panel()).toHaveAttribute('data-place', 'citations')
|
||||
expect(document.querySelectorAll('dialog[open]')).toHaveLength(2)
|
||||
expect(findingDialog()).not.toBe(citationsDialog())
|
||||
})
|
||||
|
||||
it('a family lists its citations read-only: no trigger, no Retirer, no panel', async () => {
|
||||
it('a family opens the same dialog with its citations', async () => {
|
||||
const user = await mount()
|
||||
await select(user, /Cat A/)
|
||||
const detail = screen.getByRole('tabpanel', { name: 'Constats' })
|
||||
expect(
|
||||
within(detail).queryByRole('button', { name: /références?$/ }),
|
||||
).toBeNull()
|
||||
expect(within(detail).getByText('Barone, Ostéologie')).toBeVisible()
|
||||
expect(
|
||||
within(detail).queryByRole('button', { name: /^Retirer/ }),
|
||||
).toBeNull()
|
||||
expect(hasPanel()).toBe(false)
|
||||
expect(inFindingDialog().queryByText('Barone, Ostéologie')).toBeNull()
|
||||
await user.click(trigger())
|
||||
await focusIs(closeButton)
|
||||
expect(panel()).toHaveTextContent('Zone A › Cat A')
|
||||
expect(tiles()).toHaveLength(2)
|
||||
expect(tiles()[0].textContent).toContain('Barone')
|
||||
expect(tiles()[1].textContent).toContain('Denoix')
|
||||
})
|
||||
|
||||
it('« 0 référence » is offered at zero and opens the empty dialog', async () => {
|
||||
const user = await mount(1280, nodeText([]))
|
||||
await select(user, /Node A/)
|
||||
await user.click(trigger('0 référence'))
|
||||
await focusIs(closeButton)
|
||||
expect(tiles()).toHaveLength(0)
|
||||
expect(panel()).toHaveTextContent('Ce constat ne cite aucune référence.')
|
||||
})
|
||||
|
||||
it('shows the path, the count, and only the references of the finding as tiles', async () => {
|
||||
@@ -205,7 +222,7 @@ describe('opening', () => {
|
||||
expect(panel()).not.toHaveTextContent('Denoix')
|
||||
})
|
||||
|
||||
it('an open tile marks the current finding and offers Modifier only', async () => {
|
||||
it('view mode: an open tile marks the current finding, « Aller à » only, no edit control', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
@@ -214,34 +231,23 @@ describe('opening', () => {
|
||||
expect(
|
||||
within(tile).getAllByRole('button', { name: /^Aller à / }),
|
||||
).toHaveLength(2)
|
||||
expect(within(tile).getByRole('button', { name: 'Modifier' })).toBeVisible()
|
||||
for (const absent of [
|
||||
'Modifier',
|
||||
'Retirer de ce constat',
|
||||
'Supprimer',
|
||||
'Monter',
|
||||
'Descendre',
|
||||
]) {
|
||||
expect(within(panel()).queryByRole('button', { name: absent })).toBeNull()
|
||||
expect(
|
||||
within(citationsDialog()).queryByRole('button', { name: absent }),
|
||||
).toBeNull()
|
||||
}
|
||||
expect(within(citationsDialog()).queryByRole('searchbox')).toBeNull()
|
||||
expect(within(citationsDialog()).queryByRole('textbox')).toBeNull()
|
||||
expect(within(citationsDialog()).queryByRole('combobox')).toBeNull()
|
||||
})
|
||||
|
||||
it('has no search, no add control; « Modifier » opens the reference dialog over the sheet', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
expect(within(panel()).queryByRole('searchbox')).toBeNull()
|
||||
expect(
|
||||
within(panel()).queryByRole('button', { name: /Ajouter/ }),
|
||||
).toBeNull()
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
await user.click(within(panel()).getByRole('button', { name: 'Modifier' }))
|
||||
expect(document.querySelectorAll('dialog[open]')).toHaveLength(3)
|
||||
expect(
|
||||
screen.getByRole('dialog', { name: 'Modifier la référence' }),
|
||||
).toBeVisible()
|
||||
expect(panel().querySelector('[id$="-citation"]')).toBeNull()
|
||||
})
|
||||
|
||||
it('ids stay unique with the Références tab mounted and the panel open (P14)', async () => {
|
||||
it('ids stay unique with the Références tab mounted and the dialog open (P14)', async () => {
|
||||
const user = await mount()
|
||||
await user.click(screen.getByRole('tab', { name: 'Références' }))
|
||||
await user.click(screen.getByRole('button', { name: /^Barone/ }))
|
||||
@@ -267,26 +273,12 @@ describe('opening', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('motion', () => {
|
||||
const slid = () => (layer() as HTMLElement).style.transform
|
||||
|
||||
it('slides in from the right and fades the scrim, the page behind inert', async () => {
|
||||
const user = await mount()
|
||||
await select(user, /Node A/)
|
||||
await user.click(trigger())
|
||||
expect(slid()).toMatch(/translateX\(/)
|
||||
expect(screen.getByTestId('references-scrim')).toBeInTheDocument()
|
||||
expect(panel().closest('header')).toBeNull()
|
||||
await focusIs(closeButton)
|
||||
await waitFor(() => expect(slid()).not.toMatch(/translateX\([1-9]/))
|
||||
})
|
||||
|
||||
it('reduced motion: no slide, the same lifecycle', async () => {
|
||||
describe('reduced motion', () => {
|
||||
it('the same lifecycle: open, close, the trigger takes the focus back', async () => {
|
||||
setReducedMotion(true)
|
||||
const user = await mount()
|
||||
await select(user, /Node A/)
|
||||
await user.click(trigger())
|
||||
expect(slid()).not.toMatch(/translateX\(/)
|
||||
await focusIs(closeButton)
|
||||
await user.click(closeButton())
|
||||
await closed()
|
||||
@@ -302,7 +294,7 @@ const MODES = [
|
||||
describe.each(MODES)('closing, %s', (_label, reduced) => {
|
||||
beforeEach(() => setReducedMotion(reduced))
|
||||
|
||||
it('✕, Escape and the scrim each close it after the exit: the trigger holds the focus', async () => {
|
||||
it('✕, Escape and the backdrop each close it after the exit: the trigger holds the focus', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(closeButton())
|
||||
@@ -315,7 +307,7 @@ describe.each(MODES)('closing, %s', (_label, reduced) => {
|
||||
await focusIs(() => trigger())
|
||||
await user.click(trigger())
|
||||
await focusIs(closeButton)
|
||||
fireEvent.click(screen.getByTestId('references-scrim'))
|
||||
fireEvent.click(backdrop())
|
||||
await closed()
|
||||
await focusIs(() => trigger())
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'false')
|
||||
@@ -350,14 +342,14 @@ describe.each(MODES)('closing, %s', (_label, reduced) => {
|
||||
await focusIs(() =>
|
||||
within(tabPanel).getByRole('heading', { name: 'Références' }),
|
||||
)
|
||||
// Filtered by the finding the sheet belonged to: its two citations (R2F-6).
|
||||
// Filtered by the finding the dialog belonged to: its two citations (R2F-6).
|
||||
expect(within(tabPanel).getAllByRole('listitem')).toHaveLength(2)
|
||||
expect(
|
||||
within(tabPanel).getByText('Références du constat : Node A'),
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
it('« Aller à » a citer from a panel tile closes the sheet and opens that finding in its dialog', async () => {
|
||||
it('« Aller à » a citer from a tile closes the dialog and opens that finding in its dialog', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
@@ -387,7 +379,7 @@ describe.each(MODES)('closing, %s', (_label, reduced) => {
|
||||
expect(document.activeElement).not.toBe(document.body)
|
||||
})
|
||||
|
||||
it('below 640 px the sheet opens from « Plus » > Constats and closes on its own', async () => {
|
||||
it('below 640 px the dialog opens from « Plus » > Constats and closes on its own', async () => {
|
||||
const user = await mount(375)
|
||||
await user.click(screen.getByRole('button', { name: 'Plus' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Constats' }))
|
||||
@@ -401,7 +393,7 @@ describe.each(MODES)('closing, %s', (_label, reduced) => {
|
||||
})
|
||||
|
||||
describe('the exit', () => {
|
||||
it('a sheet playing its exit is inert, its trigger reads « expanded » until it is gone', async () => {
|
||||
it('a dialog playing its exit is inert, its trigger reads « expanded » until it is gone', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'true')
|
||||
@@ -416,14 +408,14 @@ describe('the exit', () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(closeButton())
|
||||
fireEvent.keyDown(layer(), { key: 'Escape' })
|
||||
fireEvent.click(screen.getByTestId('references-scrim'))
|
||||
fireEvent.keyDown(citationsDialog(), { key: 'Escape' })
|
||||
fireEvent.click(backdrop())
|
||||
await closed()
|
||||
expect(findingDialog()).not.toBeNull()
|
||||
await focusIs(() => trigger())
|
||||
})
|
||||
|
||||
it('Ctrl+Z is ignored while the sheet is open: Défaire is unreachable under a dialog', async () => {
|
||||
it('Ctrl+Z is ignored while the dialog is open: Défaire is unreachable under a dialog', async () => {
|
||||
const user = await mount()
|
||||
act(() => void commitMove(40))
|
||||
await openFromFinding(user)
|
||||
@@ -434,7 +426,7 @@ describe('the exit', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('the library and the history around the panel', () => {
|
||||
describe('the library and the history around the dialog', () => {
|
||||
it('« Tout afficher » clears the search of the tab and keeps its sort, open tiles kept (P4)', async () => {
|
||||
const user = await mount()
|
||||
await user.click(screen.getByRole('tab', { name: 'Références' }))
|
||||
@@ -489,7 +481,7 @@ describe('the library and the history around the panel', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('the sheet cannot remove a citation (the edit form does)', () => {
|
||||
describe('the view mode cannot remove a citation', () => {
|
||||
it('no tile offers « Retirer de ce constat »', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
@@ -538,7 +530,7 @@ function cite(ids: string[]) {
|
||||
}
|
||||
|
||||
describe('the panel review fixes', () => {
|
||||
it('the sheet is a modal dialog named by its title (M4: no announcement needed)', async () => {
|
||||
it('the dialog is modal and named by its title (M4: no announcement needed)', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
const dialog = panel().closest('dialog')!
|
||||
|
||||
Reference in new issue
Block a user