Plan a delivery without moving its dependencies silently
Civil-date task rows, progress and a milestone share reviewed dependency-safe moves and a recoverable host save.
Keyboard
- Horizontal arrows propose a one-day move; Shift resizes the end, Control or Command resizes the start.
- Enter opens the review dialog for date, progress and predecessor changes.
- Pointer movement previews a whole-day move or resize. Escape and pointer cancellation restore the previous proposal.
- A conflict requires explicit revision rebase; an unknown result retries the unchanged request ID.
States covered
- day and week scales
- finish-to-start links
- cycle validation
- milestone
- progress
- pointer preview
- keyboard resize
- exact table
- mobile list
- uncertain save
- conflict
Install this complete example and its component dependencies.
npx shadcn@latest add https://ui.bld8.dev/r/example-gantt-reviewed-delivery.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 { useCallback, useRef, useState } from 'react';
import { Button, Gantt, Select, createMemoryGantt, type GanttChange, type GanttSaveContext, type GanttSaveResult, type GanttSnapshot } from '@bld8/ui';
const initial:GanttSnapshot={revision:1,tasks:[{id:'plan',title:'Interface plan',startDay:'2026-11-16',endDay:'2026-11-18',progress:75,revision:1},{id:'build',title:'Build controls',startDay:'2026-11-20',endDay:'2026-11-23',progress:30,revision:1},{id:'release',title:'Release milestone',startDay:'2026-11-27',endDay:'2026-11-27',milestone:true,progress:0,revision:1}],dependencies:[{from:'plan',to:'build',lagDays:1},{from:'build',to:'release',lagDays:2}]};
const range={startDay:'2026-11-16',endDayExclusive:'2026-11-30'};
function wait(signal:AbortSignal,delay:number){return new Promise<void>((resolve,reject)=>{const timer=setTimeout(done,delay);function stop(){clearTimeout(timer);reject(new DOMException('Aborted','AbortError'));}function done(){signal.removeEventListener('abort',stop);resolve();}if(signal.aborted){stop();return;}signal.addEventListener('abort',stop,{once:true});});}
export default function ReviewedDeliveryExample(){
const service=useRef(createMemoryGantt(initial)),mode=useRef('normal'),lost=useRef(false),conflicted=useRef(false);
const [snapshot,setSnapshot]=useState(initial),[preview,setPreview]=useState('normal'),[key,setKey]=useState(0),[ids,setIds]=useState<string[]>([]);
const save=useCallback(async(change:GanttChange,context:GanttSaveContext):Promise<GanttSaveResult>=>{
const active=service.current,scenario=mode.current;setIds(current=>[...current,context.requestId]);
if(scenario==='late'){await new Promise(resolve=>setTimeout(resolve,600));return active.save(change,{...context,signal:new AbortController().signal});}
await wait(context.signal,120);
if(scenario==='reject')return {ok:false,code:'validation',message:'Example service rejected this task change. The proposal is kept.'};
if(scenario==='conflict'&&!conflicted.current){conflicted.current=true;const current=active.read(),task=current.tasks.find(task=>task.id===change.taskId)!;await active.save({...change,startDay:task.startDay,endDay:task.endDay,progress:Math.min(100,task.progress+5),expectedRevision:task.revision,expectedSnapshotRevision:current.revision,predecessors:current.dependencies.filter(link=>link.to===task.id).map(link=>({taskId:link.from,lagDays:link.lagDays}))},{signal:new AbortController().signal,requestId:crypto.randomUUID()});}
const result=await active.save(change,context);if(scenario==='lost'&&!lost.current){lost.current=true;throw new Error('The example write succeeded but its acknowledgement was lost.');}return result;
},[]);
return <div style={{display:'grid',gap:16,minWidth:0}}><div style={{display:'flex',alignItems:'end',gap:12,flexWrap:'wrap'}}><Select label="Gantt service preview" value={preview} options={[{value:'normal',label:'Successful save'},{value:'lost',label:'Lost acknowledgement'},{value:'conflict',label:'Newer revision'},{value:'reject',label:'Rejected save'},{value:'late',label:'Late service response'},{value:'readonly',label:'Read only'}]} onValueChange={value=>{if(value){mode.current=value;setPreview(value);}}}/><Button size="sm" variant="secondary" onClick={()=>{service.current=createMemoryGantt(initial);lost.current=false;conflicted.current=false;setSnapshot(initial);setIds([]);setKey(value=>value+1);}}>Reset task source</Button><Button size="sm" variant="secondary" onClick={async()=>{const current=service.current.read(),task=current.tasks.find(task=>task.id==='build')!;const result=await service.current.save({taskId:task.id,expectedRevision:task.revision,expectedSnapshotRevision:current.revision,startDay:task.startDay,endDay:task.endDay,progress:Math.min(100,task.progress+5),predecessors:current.dependencies.filter(link=>link.to===task.id).map(link=>({taskId:link.from,lagDays:link.lagDays}))},{signal:new AbortController().signal,requestId:crypto.randomUUID()});if(result.ok)setSnapshot(result.snapshot);}}>Publish newer supplied plan</Button></div><Gantt label="Delivery plan" snapshot={snapshot} range={range} onSave={save} onSnapshotChange={setSnapshot} sourceKey={key} readOnly={preview==='readonly'}/><output aria-label="Gantt save request IDs" style={{fontSize:11,overflowWrap:'anywhere'}}>{JSON.stringify(ids)}</output><p className="bui-hint">Authored civil dates and finish-to-start links. End dates are exclusive; a milestone uses one equal start/end date. The single-process example retains 100 receipts and resets on reload. Supply an authorised durable atomic service for an application; a stopped client wait cannot undo a committed task change.</p></div>;
}