diff --git a/apps/app/e2e/shell/editor-citations.spec.ts b/apps/app/e2e/shell/editor-citations.spec.ts index 5851fbcc..d0764e15 100644 --- a/apps/app/e2e/shell/editor-citations.spec.ts +++ b/apps/app/e2e/shell/editor-citations.spec.ts @@ -90,9 +90,6 @@ async function open(page: Page, seedShape = shape) { } const panel = (page: Page) => page.getByTestId('editor-citations-panel') -/** The sheet's own dialog (the finding dialog under it is the other one). */ -const sheet = (page: Page) => - page.locator('dialog[open]').filter({ has: panel(page) }) const heads = (page: Page) => panel(page).locator('button[aria-controls][id$="-header"]') const trigger = (page: Page) => page.locator('[data-citations-trigger]') diff --git a/apps/app/src/components/editor/findings/FindingEditForm.tsx b/apps/app/src/components/editor/findings/FindingEditForm.tsx index 05d2da80..c283d2e2 100644 --- a/apps/app/src/components/editor/findings/FindingEditForm.tsx +++ b/apps/app/src/components/editor/findings/FindingEditForm.tsx @@ -109,9 +109,11 @@ interface FieldsProps { } /** The names, then the descriptions of a family or a node, as draft fields. */ -function EditFields({ draft, set, readOnly, described, blank }: FieldsProps) { +const textKey = (l: Locale2) => (l === 'fr' ? 'descriptionFr' : 'descriptionEn') + +function EditFields(props: FieldsProps) { + const { draft, set } = props const t = useT() - const text = (l: Locale2) => (l === 'fr' ? 'descriptionFr' : 'descriptionEn') return (
{LOCALES.map((l) => ( @@ -121,19 +123,21 @@ function EditFields({ draft, set, readOnly, described, blank }: FieldsProps) { label={t(`editor.general.name_${l}`)} value={draft[l]} onChange={(value) => set({ [l]: value })} - readOnly={readOnly} - error={blank.includes(l) ? t('editor.field.required') : undefined} + readOnly={props.readOnly} + error={ + props.blank.includes(l) ? t('editor.field.required') : undefined + } /> ))} - {described && + {props.described && LOCALES.map((l) => ( set({ [text(l)]: value })} - readOnly={readOnly} + value={draft[textKey(l)]} + onChange={(value) => set({ [textKey(l)]: value })} + readOnly={props.readOnly} multiline /> ))} diff --git a/apps/app/src/components/editor/tabs/FindingsTab.tsx b/apps/app/src/components/editor/tabs/FindingsTab.tsx index 1a6f5868..c4f778d8 100644 --- a/apps/app/src/components/editor/tabs/FindingsTab.tsx +++ b/apps/app/src/components/editor/tabs/FindingsTab.tsx @@ -187,10 +187,9 @@ function useTreeSelection( if (!open && selectedId && isUnder(items, selectedId, id)) select(id) exp.set(id, open) } - const selected = items.find((item) => item.id === selectedId) return { selectedId, - selected, + selected: items.find((item) => item.id === selectedId), expanded: exp.expanded, select, toggle, @@ -271,13 +270,10 @@ function useFindingsTab(focus: EditorPlaceProps['focus'], layer: FindingLayer) { useLayerFollow(focus, ctx) useGoneRule(layer, data.doc !== null) const actions = useFindingActions(ctx) - return { - ...data, - sel, - landing, - actions, - returnFocus: useReturnTarget(layer.view), - } + const returnFocus = useReturnTarget(layer.view) + const { view } = layer + const shown = view && 'key' in view ? itemForKey(data.items, view.key) : null + return { ...data, sel, landing, actions, returnFocus, shown } } /** Constats: the tree zones → categories → nodes; each element opens in a dialog. */ @@ -288,16 +284,10 @@ export default function FindingsTab(props: EditorPlaceProps) { return } -function FindingsBody({ - readOnly, - focus, - layer, -}: EditorPlaceProps & { layer: FindingLayer }) { +function FindingsBody(props: EditorPlaceProps & { layer: FindingLayer }) { + const { layer } = props const t = useT() - const tab = useFindingsTab(focus, layer) - const { items, sel, landing, actions } = tab - const { view } = layer - const shown = view && 'key' in view ? itemForKey(items, view.key) : null + const tab = useFindingsTab(props.focus, layer) return (
item.kind === 'zone')} - readOnly={readOnly} + selected={tab.sel.selected} + hasZone={tab.items.some((item) => item.kind === 'zone')} + readOnly={props.readOnly} onStart={(p) => layer.start(p.kind, p.parent?.key ?? null)} /> - {tab.doc && items.length === 0 && ( + {tab.doc && tab.items.length === 0 && (

{t('editor.findings.empty')}

)} + -
) } diff --git a/apps/app/src/editor/useEditorNavigation.ts b/apps/app/src/editor/useEditorNavigation.ts index e546bc2e..c11457a7 100644 --- a/apps/app/src/editor/useEditorNavigation.ts +++ b/apps/app/src/editor/useEditorNavigation.ts @@ -449,7 +449,6 @@ function useCitedBy(state: NavigationState, openers: Openers) { }, [citedBy, openers]) } -/** Navigation of the draft editor: the reducer plus the DOM side (focus, live region). */ /** The reducer and the move machinery every other part of the hook builds on. */ function useNavBase(initialTab: EditorTabId, initialView?: EditorView | null) { const [state, dispatch] = useReducer(navigationReducer, null, () => @@ -459,6 +458,14 @@ function useNavBase(initialTab: EditorTabId, initialView?: EditorView | null) { return { state, dispatch, trace, mark, ...useGo(dispatch, trace) } } +/** A Back or Forward landed on a view: restored, no move, no request. */ +function useRestoreView(dispatch: Dispatch) { + return useCallback( + (view: EditorView) => dispatch({ type: 'restore_view', view }), + [dispatch], + ) +} + /** Navigation of the draft editor: the reducer plus the DOM side (focus, live region). */ export function useEditorNavigation( initialTab: EditorTabId, @@ -493,9 +500,6 @@ export function useEditorNavigation( citationsTrigger: useCallback(() => triggerOf(openers), [openers]), guards, trace: base.trace, - restoreView: useCallback( - (view: EditorView) => base.dispatch({ type: 'restore_view', view }), - [], - ), + restoreView: useRestoreView(base.dispatch), } }