What a view shows while loading, when empty, after a failure, or when access is refused.
↻
No runs yet
Runs show here once Invoice sync is triggered. Run it now to see one.
import{Command,UiSchema}from"@effect/ui"import{Html}from"@effect/ui/html"import*as stylex from"@stylexjs/stylex"import{Effect,Schema}from"effect"import{Button}from"./ui/uicontext/components/Button.ts"import{Empty,ErrorBanner,Skeleton}from"./ui/uicontext/components/kit/States.ts"import{SegmentedControl}from"./ui/uicontext/components/SegmentedControl.ts"import{ sx }from"./ui/uicontext/components/Sx.ts"import{ color, font, radius, space }from"./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({stack:{display:"grid",gap: space.lg,inlineSize:"min(100%, 34rem)"},note:{margin:0,minBlockSize:"1.4em",fontSize: font.sm,color: color.muted},panel:{minBlockSize:200,padding: space.lg,borderRadius: radius.lg,backgroundColor: color.panel,boxShadow:`inset 0 0 0 1px ${color.line}`,},})constShown=Schema.Literals(["loading","empty","failed","refused"])constMessage=UiSchema.TaggedEnum({PickedState:{state:Shown},ClickedRetry:{},CompletedRetry:{},ClickedCreate:{},ClickedRequestAccess:{},})// stands in for the app's request: it fails again, so the banner stays to showconstRetry=Command.make("Example.RetryRuns",{},()=>Effect.sleep("900 millis").pipe(Effect.as(Message.CompletedRetry())))// the app's words for each rejection its services can returnconst copy ={Unreachable:{sentence:"Couldn't load this workflow's runs.",nextStep:"Check your connection, then try again.",action:"Try again"},NotAMember:{sentence:"You don't have access to Invoice sync.",nextStep:"Ask Maya Chen, its owner, to add you.",action:"Request access",tone:"neutral"asconst,},}exportconstRunStates=Html.component({name:"RunStates",model:Schema.Struct({state:Shown,retrying:Schema.Boolean,note:Schema.String}),message:Message,}).make({init:()=>({state:"empty",retrying:false,note:""}),update:{PickedState:($,{ state })=> $.evolve({ state,retrying:false,note:""}),ClickedRetry:($)=>($.model.retrying? $.model: $.evolve({state:"loading",retrying:true}).run(Retry.make())),CompletedRetry:($)=>($.model.retrying? $.evolve({state:"failed",retrying:false}): $.model),ClickedCreate:($)=> $.evolve({note:"The app would start a run."}),ClickedRequestAccess:($)=> $.evolve({note:"Request sent. Maya Chen will get an email."}),},view:(h,{ state, note })=> h.div.attrs(sx(styles.stack)).children(SegmentedControl(h,{label:"State",size:"sm",value: state,options:[{value:"loading",label:"Loading"},{value:"empty",label:"Empty"},{value:"failed",label:"Failed"},{value:"refused",label:"No access"},],onPick:(value)=>Message.PickedState({state: value ==="loading"|| value ==="failed"|| value ==="refused"? value :"empty"}),}), h.div.attrs({"aria-live":"polite",...sx(styles.panel)}).children( state ==="loading"?Skeleton(h,{label:"Loading runs",shape:"rows",count:4}): state ==="empty"?Empty(h,{icon:"↻",title:"No runs yet",hint:"Runs show here once Invoice sync is triggered. Run it now to see one.",actions:[Button(h,{tone:"primary"}).on("click",Message.ClickedCreate()).children("Run now")],}):ErrorBanner(h,{props:{agentId:"runs-error",rejection: state ==="failed"?"Unreachable":"NotAMember", copy,urgent: state ==="failed"},onEmit:{RequestedAction:({ rejection })=>(rejection ==="Unreachable"?Message.ClickedRetry():Message.ClickedRequestAccess()),RequestedDismiss:()=>undefined,},}),), h.p.attrs({role:"status",...sx(styles.note)}).children(note),),})