fix(editor): Task 2 round 3, lint, locals, stale comment

This commit is contained in:
bchanot committed 2026-11-13 19:51:03 +01:00
1 parent 20905adf72
commit af300de04c
4 files changed
+50 -52

No files matched your search

@@ -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]')
@@ -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 (
<div className="grid gap-3 md:grid-cols-2">
{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) => (
<DraftField
key={`d-${l}`}
id={`finding-edit-description-${l}`}
label={t(`editor.findings.description_${l}`)}
value={draft[text(l)]}
onChange={(value) => set({ [text(l)]: value })}
readOnly={readOnly}
value={draft[textKey(l)]}
onChange={(value) => set({ [textKey(l)]: value })}
readOnly={props.readOnly}
multiline
/>
))}
@@ -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 <FindingsBody {...props} layer={layer} />
}
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 (
<section
data-testid="editor-tab-findings"
@@ -305,36 +295,39 @@ function FindingsBody({
className="min-h-24 space-y-3"
>
<AddBar
selected={sel.selected}
hasZone={items.some((item) => 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 && (
<p className="text-sm text-[var(--color-ink-muted)]">
{t('editor.findings.empty')}
</p>
)}
<FindingTree
visible={visibleItems(items, sel.expanded)}
selectedId={sel.selected?.id ?? null}
expanded={sel.expanded}
onSelect={sel.select}
onActivate={actions.activate}
onToggle={sel.toggle}
focusId={landing.focusId}
onFocused={landing.clear}
visible={visibleItems(tab.items, tab.sel.expanded)}
selectedId={tab.sel.selected?.id ?? null}
expanded={tab.sel.expanded}
onSelect={tab.sel.select}
onActivate={tab.actions.activate}
onToggle={tab.sel.toggle}
focusId={tab.landing.focusId}
onFocused={tab.landing.clear}
/>
<FindingDialog
layer={layer}
item={shown?.item ?? null}
pending={pendingOf(view, items)}
readOnly={readOnly}
item={tab.shown?.item ?? null}
pending={pendingOf(layer.view, tab.items)}
readOnly={props.readOnly}
returnFocus={tab.returnFocus}
onDelete={actions.askDelete}
onCreated={actions.created}
onDelete={tab.actions.askDelete}
onCreated={tab.actions.created}
/>
<DeleteDialog
target={tab.actions.deleting}
onClose={tab.actions.closeDelete}
/>
<DeleteDialog target={actions.deleting} onClose={actions.closeDelete} />
</section>
)
}
+9 -5
View File
@@ -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<NavigationAction>) {
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),
}
}