Save, reject and retry an intended move
An optimistic board move stays pending until the local adapter accepts, rejects or cancels it. A rejected save restores the original order and retains the intended move for retry.
Keyboard
- Use a card Move button to choose a column and exact position.
- Move item applies the optimistic change; other move buttons stay disabled during the save.
- Accept, Reject or Cancel the pending move using outside controls. Retry intended move repeats the rejected move.
States covered
- Optimistic reorder
- Pending move lock
- Rejected save rollback
- Exact intended move retry
- Abortable cancellation
- Unmount protection
- Host-owned persistence
Install this complete example and its component dependencies.
npx shadcn@latest add https://ui.bld8.dev/r/example-workflow-kanban-recovery.jsonComplete source
/*!
MIT License
Copyright (c) 2026 Jaison
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import '@bld8/ui/styles.css';
import { useEffect, useRef, useState } from 'react';
import { Kanban } from '@bld8/ui/kanban';
import { applyKanbanMove, type KanbanColumn, type KanbanItem, type KanbanMove } from '@bld8/ui/kanban-state';
import { Button, Checkbox } from '@bld8/ui/core';
import { UIProvider, Select } from '@bld8/ui';
const columns: KanbanColumn[] = [{ id: 'planned', title: 'Planned' }, { id: 'review', title: 'In review', limit: 2 }, { id: 'done', title: 'Done' }];
const initial: KanbanItem[] = [{ id: 'labels', columnId: 'planned', title: 'Review field labels' }, { id: 'focus', columnId: 'planned', title: 'Check focus return' }, { id: 'spacing', columnId: 'review', title: 'Verify spacing' }];
type SaveRequest = { controller: AbortController; accept: () => void; reject: () => void };
export function RecoverableKanbanExample() {
const [items, setItems] = useState<KanbanItem[]>(initial);
const [saving, setSaving] = useState(false);
const [failed, setFailed] = useState<KanbanMove | null>(null);
const [message, setMessage] = useState('No move is pending.');
const current = useRef(items), active = useRef<SaveRequest | null>(null), alive = useRef(true);
useEffect(() => { alive.current = true; return () => { alive.current = false; active.current?.controller.abort(); }; }, []);
function moveItem(move: KanbanMove) {
if (active.current) return;
const before = current.current;
let next: KanbanItem[];
try { next = applyKanbanMove(before, move, columns); } catch { setMessage('The board changed. Choose the move again.'); setFailed(null); return; }
const controller = new AbortController();
let accept!: () => void, reject!: () => void;
const response = new Promise<void>((resolve, fail) => {
accept = resolve; reject = () => fail(new Error('Save rejected'));
controller.signal.addEventListener('abort', () => fail(new DOMException('Cancelled', 'AbortError')), { once: true });
});
const request = { controller, accept, reject };
active.current = request; current.current = next; setItems(next); setSaving(true); setFailed(null); setMessage('Saving the intended move…');
response.then(() => {
if (!alive.current || active.current !== request || controller.signal.aborted) return;
setMessage('Move saved by the local adapter.');
}).catch(() => {
if (!alive.current || active.current !== request) return;
current.current = before; setItems(before);
if (controller.signal.aborted) { setFailed(null); setMessage('Save cancelled. Original order restored.'); }
else { setFailed(move); setMessage('Save rejected. Original order restored; the intended move is ready to retry.'); }
}).finally(() => { if (alive.current && active.current === request) { active.current = null; setSaving(false); } });
}
return <UIProvider><div style={{ width: '100%', display: 'grid', gap: 20 }}>
<p className="bui-hint">This local adapter holds its save promise for review. Replace it with an authorised, revision-checked service. No tasks are persisted.</p>
<Kanban label="Recoverable review board" columns={columns} items={items} onMove={moveItem} pending={saving} layout="backlog" />
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 12 }}>
<Button disabled={!saving} onClick={() => active.current?.accept()}>Accept pending move</Button>
<Button variant="secondary" disabled={!saving} onClick={() => active.current?.reject()}>Reject pending move</Button>
<Button variant="secondary" disabled={!saving} onClick={() => active.current?.controller.abort()}>Cancel pending move</Button>
{failed && <Button variant="secondary" onClick={() => moveItem(failed)}>Retry intended move</Button>}
</div>
<p role={failed ? 'alert' : 'status'}>{message}</p>
<output aria-label="Board order" className="bui-hint">{items.map(item => item.id + ':' + item.columnId).join(' | ')}</output>
</div></UIProvider>;
}