fix(editor): Task 2 round 3, lint, locals, stale comment
This commit is contained in:
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')
|
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) =>
|
const heads = (page: Page) =>
|
||||||
panel(page).locator('button[aria-controls][id$="-header"]')
|
panel(page).locator('button[aria-controls][id$="-header"]')
|
||||||
const trigger = (page: Page) => page.locator('[data-citations-trigger]')
|
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. */
|
/** 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 t = useT()
|
||||||
const text = (l: Locale2) => (l === 'fr' ? 'descriptionFr' : 'descriptionEn')
|
|
||||||
return (
|
return (
|
||||||
<div className="grid gap-3 md:grid-cols-2">
|
<div className="grid gap-3 md:grid-cols-2">
|
||||||
{LOCALES.map((l) => (
|
{LOCALES.map((l) => (
|
||||||
@@ -121,19 +123,21 @@ function EditFields({ draft, set, readOnly, described, blank }: FieldsProps) {
|
|||||||
label={t(`editor.general.name_${l}`)}
|
label={t(`editor.general.name_${l}`)}
|
||||||
value={draft[l]}
|
value={draft[l]}
|
||||||
onChange={(value) => set({ [l]: value })}
|
onChange={(value) => set({ [l]: value })}
|
||||||
readOnly={readOnly}
|
readOnly={props.readOnly}
|
||||||
error={blank.includes(l) ? t('editor.field.required') : undefined}
|
error={
|
||||||
|
props.blank.includes(l) ? t('editor.field.required') : undefined
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
{described &&
|
{props.described &&
|
||||||
LOCALES.map((l) => (
|
LOCALES.map((l) => (
|
||||||
<DraftField
|
<DraftField
|
||||||
key={`d-${l}`}
|
key={`d-${l}`}
|
||||||
id={`finding-edit-description-${l}`}
|
id={`finding-edit-description-${l}`}
|
||||||
label={t(`editor.findings.description_${l}`)}
|
label={t(`editor.findings.description_${l}`)}
|
||||||
value={draft[text(l)]}
|
value={draft[textKey(l)]}
|
||||||
onChange={(value) => set({ [text(l)]: value })}
|
onChange={(value) => set({ [textKey(l)]: value })}
|
||||||
readOnly={readOnly}
|
readOnly={props.readOnly}
|
||||||
multiline
|
multiline
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -187,10 +187,9 @@ function useTreeSelection(
|
|||||||
if (!open && selectedId && isUnder(items, selectedId, id)) select(id)
|
if (!open && selectedId && isUnder(items, selectedId, id)) select(id)
|
||||||
exp.set(id, open)
|
exp.set(id, open)
|
||||||
}
|
}
|
||||||
const selected = items.find((item) => item.id === selectedId)
|
|
||||||
return {
|
return {
|
||||||
selectedId,
|
selectedId,
|
||||||
selected,
|
selected: items.find((item) => item.id === selectedId),
|
||||||
expanded: exp.expanded,
|
expanded: exp.expanded,
|
||||||
select,
|
select,
|
||||||
toggle,
|
toggle,
|
||||||
@@ -271,13 +270,10 @@ function useFindingsTab(focus: EditorPlaceProps['focus'], layer: FindingLayer) {
|
|||||||
useLayerFollow(focus, ctx)
|
useLayerFollow(focus, ctx)
|
||||||
useGoneRule(layer, data.doc !== null)
|
useGoneRule(layer, data.doc !== null)
|
||||||
const actions = useFindingActions(ctx)
|
const actions = useFindingActions(ctx)
|
||||||
return {
|
const returnFocus = useReturnTarget(layer.view)
|
||||||
...data,
|
const { view } = layer
|
||||||
sel,
|
const shown = view && 'key' in view ? itemForKey(data.items, view.key) : null
|
||||||
landing,
|
return { ...data, sel, landing, actions, returnFocus, shown }
|
||||||
actions,
|
|
||||||
returnFocus: useReturnTarget(layer.view),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Constats: the tree zones → categories → nodes; each element opens in a dialog. */
|
/** 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} />
|
return <FindingsBody {...props} layer={layer} />
|
||||||
}
|
}
|
||||||
|
|
||||||
function FindingsBody({
|
function FindingsBody(props: EditorPlaceProps & { layer: FindingLayer }) {
|
||||||
readOnly,
|
const { layer } = props
|
||||||
focus,
|
|
||||||
layer,
|
|
||||||
}: EditorPlaceProps & { layer: FindingLayer }) {
|
|
||||||
const t = useT()
|
const t = useT()
|
||||||
const tab = useFindingsTab(focus, layer)
|
const tab = useFindingsTab(props.focus, layer)
|
||||||
const { items, sel, landing, actions } = tab
|
|
||||||
const { view } = layer
|
|
||||||
const shown = view && 'key' in view ? itemForKey(items, view.key) : null
|
|
||||||
return (
|
return (
|
||||||
<section
|
<section
|
||||||
data-testid="editor-tab-findings"
|
data-testid="editor-tab-findings"
|
||||||
@@ -305,36 +295,39 @@ function FindingsBody({
|
|||||||
className="min-h-24 space-y-3"
|
className="min-h-24 space-y-3"
|
||||||
>
|
>
|
||||||
<AddBar
|
<AddBar
|
||||||
selected={sel.selected}
|
selected={tab.sel.selected}
|
||||||
hasZone={items.some((item) => item.kind === 'zone')}
|
hasZone={tab.items.some((item) => item.kind === 'zone')}
|
||||||
readOnly={readOnly}
|
readOnly={props.readOnly}
|
||||||
onStart={(p) => layer.start(p.kind, p.parent?.key ?? null)}
|
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)]">
|
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||||
{t('editor.findings.empty')}
|
{t('editor.findings.empty')}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
<FindingTree
|
<FindingTree
|
||||||
visible={visibleItems(items, sel.expanded)}
|
visible={visibleItems(tab.items, tab.sel.expanded)}
|
||||||
selectedId={sel.selected?.id ?? null}
|
selectedId={tab.sel.selected?.id ?? null}
|
||||||
expanded={sel.expanded}
|
expanded={tab.sel.expanded}
|
||||||
onSelect={sel.select}
|
onSelect={tab.sel.select}
|
||||||
onActivate={actions.activate}
|
onActivate={tab.actions.activate}
|
||||||
onToggle={sel.toggle}
|
onToggle={tab.sel.toggle}
|
||||||
focusId={landing.focusId}
|
focusId={tab.landing.focusId}
|
||||||
onFocused={landing.clear}
|
onFocused={tab.landing.clear}
|
||||||
/>
|
/>
|
||||||
<FindingDialog
|
<FindingDialog
|
||||||
layer={layer}
|
layer={layer}
|
||||||
item={shown?.item ?? null}
|
item={tab.shown?.item ?? null}
|
||||||
pending={pendingOf(view, items)}
|
pending={pendingOf(layer.view, tab.items)}
|
||||||
readOnly={readOnly}
|
readOnly={props.readOnly}
|
||||||
returnFocus={tab.returnFocus}
|
returnFocus={tab.returnFocus}
|
||||||
onDelete={actions.askDelete}
|
onDelete={tab.actions.askDelete}
|
||||||
onCreated={actions.created}
|
onCreated={tab.actions.created}
|
||||||
|
/>
|
||||||
|
<DeleteDialog
|
||||||
|
target={tab.actions.deleting}
|
||||||
|
onClose={tab.actions.closeDelete}
|
||||||
/>
|
/>
|
||||||
<DeleteDialog target={actions.deleting} onClose={actions.closeDelete} />
|
|
||||||
</section>
|
</section>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -449,7 +449,6 @@ function useCitedBy(state: NavigationState, openers: Openers) {
|
|||||||
}, [citedBy, 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. */
|
/** The reducer and the move machinery every other part of the hook builds on. */
|
||||||
function useNavBase(initialTab: EditorTabId, initialView?: EditorView | null) {
|
function useNavBase(initialTab: EditorTabId, initialView?: EditorView | null) {
|
||||||
const [state, dispatch] = useReducer(navigationReducer, 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) }
|
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). */
|
/** Navigation of the draft editor: the reducer plus the DOM side (focus, live region). */
|
||||||
export function useEditorNavigation(
|
export function useEditorNavigation(
|
||||||
initialTab: EditorTabId,
|
initialTab: EditorTabId,
|
||||||
@@ -493,9 +500,6 @@ export function useEditorNavigation(
|
|||||||
citationsTrigger: useCallback(() => triggerOf(openers), [openers]),
|
citationsTrigger: useCallback(() => triggerOf(openers), [openers]),
|
||||||
guards,
|
guards,
|
||||||
trace: base.trace,
|
trace: base.trace,
|
||||||
restoreView: useCallback(
|
restoreView: useRestoreView(base.dispatch),
|
||||||
(view: EditorView) => base.dispatch({ type: 'restore_view', view }),
|
|
||||||
[],
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user