fix(editor): C1 review round 1, note endings tested, tile hook, pin guard
Tests: note ends on another tile's Modifier, on Ajouter une reference, and is replaced (announced again) by a newer drop; long titles shortened. Read-only toggle deletes the key from openKeys explicitly. Drop slot and tile wrappers moved to useTileActions. pinEdited pins nothing for an absent key.
This commit is contained in:
1 parent
3303530717
commit
1e19479853
4 files changed
+80
-13
No files matched your search
@@ -243,6 +243,26 @@ function useDroppedDrafts(editing: boolean, readOnly: boolean) {
|
||||
return [dropped, setDropped] as const
|
||||
}
|
||||
|
||||
/** The tile's own actions: « Terminer » refocuses the header, a toggle ends the note. */
|
||||
function useTileActions(
|
||||
props: TileProps,
|
||||
headerRef: RefObject<HTMLButtonElement | null>,
|
||||
) {
|
||||
const { on, editing, readOnly } = props
|
||||
const [dropped, setDropped] = useDroppedDrafts(editing, readOnly)
|
||||
return {
|
||||
dropped,
|
||||
setDropped,
|
||||
done: () => {
|
||||
if (on.done()) headerRef.current?.focus()
|
||||
},
|
||||
toggle: () => {
|
||||
setDropped(null)
|
||||
on.toggle()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/** « Saisie non appliquée : … »: plain text, the live region says it once elsewhere. */
|
||||
function DroppedNote({ fields }: { fields: readonly Field[] }) {
|
||||
const droppedText = useDroppedText()
|
||||
@@ -264,14 +284,7 @@ export default function ReferenceTile(props: TileProps) {
|
||||
const t = useT()
|
||||
const base = tileBase(host, position, reference)
|
||||
const headerRef = useRef<HTMLButtonElement>(null)
|
||||
const [dropped, setDropped] = useDroppedDrafts(editing, props.readOnly)
|
||||
const done = () => {
|
||||
if (on.done()) headerRef.current?.focus()
|
||||
}
|
||||
const toggle = () => {
|
||||
setDropped(null)
|
||||
on.toggle()
|
||||
}
|
||||
const { dropped, setDropped, done, toggle } = useTileActions(props, headerRef)
|
||||
return (
|
||||
<li
|
||||
data-reference-tile
|
||||
|
||||
@@ -45,9 +45,9 @@ export function useReferenceView(
|
||||
const [pinned, setPinned] = useState<Pinned | null>(null)
|
||||
// The reset view is the sheet order: the tile in edit sits at its own position.
|
||||
const pinEdited = (): Pinned | null =>
|
||||
editingKey === null
|
||||
editingKey === null || !keys.includes(editingKey)
|
||||
? null
|
||||
: { key: editingKey, index: Math.max(0, keys.indexOf(editingKey)) }
|
||||
: { key: editingKey, index: keys.indexOf(editingKey) }
|
||||
if (seen !== resetSignal) {
|
||||
setSeen(resetSignal)
|
||||
setView(INITIAL)
|
||||
|
||||
@@ -48,6 +48,11 @@ export function useTileState(keys: readonly string[] | null) {
|
||||
if (editingKey === key) {
|
||||
if (!readOnly) return void finish()
|
||||
setEditingKey(null)
|
||||
return setOpenKeys((prev) => {
|
||||
const next = new Set(prev)
|
||||
next.delete(key)
|
||||
return next
|
||||
})
|
||||
}
|
||||
setOpenKeys((prev) => {
|
||||
const next = new Set(prev)
|
||||
|
||||
@@ -145,7 +145,7 @@ async function typeBadUrl(user: User, id: string) {
|
||||
}
|
||||
|
||||
describe('a read-only flip with a refused draft (tab tile)', () => {
|
||||
it('shows the note in the tile, says it once, writes nothing, keeps the focus on the tile', async () => {
|
||||
it('shows the note, says it once, writes nothing, focuses the tile', async () => {
|
||||
const user = await mount()
|
||||
await editTile(user, 'ref-b', /^Denoix/)
|
||||
await typeBadUrl(user, 'ref-b')
|
||||
@@ -167,7 +167,7 @@ describe('a read-only flip with a refused draft (tab tile)', () => {
|
||||
watch.stop()
|
||||
})
|
||||
|
||||
it('keeps the note across the flip back, URL field on the document value; Terminer removes it', async () => {
|
||||
it('keeps the note across the flip back; Terminer removes it', async () => {
|
||||
const user = await mount()
|
||||
await editTile(user, 'ref-b', /^Denoix/)
|
||||
await typeBadUrl(user, 'ref-b')
|
||||
@@ -225,8 +225,57 @@ describe('a read-only flip with a refused draft (tab tile)', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('the note ends on the next action', () => {
|
||||
/** ref-b flipped with a refused URL and back: in edit again, note shown. */
|
||||
async function flippedBack() {
|
||||
const user = await mount()
|
||||
await editTile(user, 'ref-b', /^Denoix/)
|
||||
await typeBadUrl(user, 'ref-b')
|
||||
cross(800)
|
||||
cross(1280)
|
||||
expect(
|
||||
within(tile('ref-b')).getByText(/Saisie non appliquée/),
|
||||
).toBeVisible()
|
||||
return user
|
||||
}
|
||||
const noted = () => within(tabPanel()).queryAllByText(/Saisie non appliquée/)
|
||||
|
||||
it("ends on another tile's « Modifier » (this tile leaves edit)", async () => {
|
||||
const user = await flippedBack()
|
||||
await user.click(
|
||||
within(tabPanel()).getByRole('button', { name: /^Barone/ }),
|
||||
)
|
||||
await user.click(
|
||||
within(tile('ref-a')).getByRole('button', { name: 'Modifier' }),
|
||||
)
|
||||
expect(noted()).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('ends on « Ajouter une référence »', async () => {
|
||||
const user = await flippedBack()
|
||||
await user.click(
|
||||
within(tabPanel()).getByRole('button', { name: 'Ajouter une référence' }),
|
||||
)
|
||||
expect(noted()).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('is replaced by a newer drop of the same tile, announced again', async () => {
|
||||
const user = await flippedBack()
|
||||
const watch = watchNotes()
|
||||
await user.clear(field('ref-b', 'citation'))
|
||||
await typeBadUrl(user, 'ref-b')
|
||||
cross(800)
|
||||
await flush()
|
||||
const items = noted()
|
||||
expect(items).toHaveLength(1)
|
||||
expect(items[0]).toHaveTextContent(`${NOTE} : Citation, Adresse web (URL)`)
|
||||
expect(watch.seen).toHaveLength(1)
|
||||
watch.stop()
|
||||
})
|
||||
})
|
||||
|
||||
describe('a read-only flip without a refused draft', () => {
|
||||
it('adds exactly the typed change when a valid draft has the focus, nothing on the way back', async () => {
|
||||
it('adds only the typed change when a valid draft has the focus', async () => {
|
||||
const user = await mount()
|
||||
await editTile(user, 'ref-a', /^Barone/)
|
||||
const citation = field('ref-a', 'citation')
|
||||
|
||||
Reference in new issue
Block a user