Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

5.0 KB
Raw Blame
<script>
import {tick} from 'svelte';import Icon from './Icon.svelte';
import {flowCatalog,flowLabel,newFlow,balanceWeights,flowAvailable} from './flow-catalog.mjs';
export let flows;export let disabled=false;
let expanded=null,picker,search='',searchInput,undo=null;
$: allocated=flows.reduce((sum,flow)=>sum+Number(flow.weight||0),0);
$: choices=flowCatalog.filter(([,label])=>label.toLowerCase().includes(search.trim().toLowerCase()));
async function openPicker(){search='';picker.showModal();await tick();searchInput.focus();}
function add(type){flows=[...flows,newFlow(type,flows)];picker.close();expanded=flows.length-1;}
function remove(index){undo=structuredClone(flows);flows=flows.filter((_,i)=>i!==index);expanded=null;}
</script>
<section class="mix" aria-labelledby="mix-title">
<div class="section-head"><div><h2 id="mix-title">Flow mix</h2><p class:invalid={allocated!==100}>{allocated===100?'100% allocated':allocated<100?`${100-allocated}% remaining`:`${allocated-100}% over allocated`}</p></div><button type="button" class="secondary" disabled={disabled} onclick={openPicker}><Icon name="plus"/> Add flow</button></div>
<div class="mix-tools">{#if allocated<100&&flows.length}<button type="button" class="quiet" disabled={disabled} onclick={()=>{undo=structuredClone(flows);flows=balanceWeights(flows);}}>Distribute remaining {100-allocated}%</button>{/if}{#if allocated!==100&&flows.length}<button type="button" class="quiet" disabled={disabled} onclick={()=>{undo=structuredClone(flows);flows=balanceWeights(flows,true);}}>Normalize to 100%</button>{/if}{#if undo}<button type="button" class="quiet" onclick={()=>{flows=undo;undo=null;}}>Undo</button>{/if}</div><div class="flow-list">
{#each flows as flow,index}
<div class="flow-row">
<button type="button" class="quiet flow-name" disabled={disabled} aria-expanded={expanded===index} aria-controls={`flow-options-${index}`} onclick={()=>expanded=expanded===index?null:index}>{flowLabel(flow.scenario)}<span aria-hidden="true" class="chevron">{expanded===index?'⌃':'⌄'}</span></button>
<label class="flow-weight"><input aria-label={`${flowLabel(flow.scenario)} weight`} type="number" min="0" max="100" required disabled={disabled} bind:value={flow.weight}/><span>%</span></label>
<button type="button" class="icon-button danger" disabled={disabled} aria-label={`Remove ${flowLabel(flow.scenario)}`} onclick={()=>remove(index)}><Icon name="close"/></button>
</div>
{#if expanded===index}
<div class="flow-options fields" id={`flow-options-${index}`}>
<label>Flow<select disabled={disabled} bind:value={flow.scenario}>{#each flowCatalog as [type,label]}<option value={type} disabled={!flowAvailable(type)}>{label}{flowAvailable(type)?'':' · Not yet supported'}</option>{/each}</select></label>

<label class="internal-name">Internal name <span>Used in run metrics</span><input disabled={disabled} required bind:value={flow.name}/></label>
</div>
{/if}
{/each}
{#if !flows.length}<p class="muted">Add a flow to configure the traffic mix.</p>{/if}
</div>
</section>
<dialog bind:this={picker} aria-labelledby="picker-title"><div class="section-head"><h2 id="picker-title">Add flow</h2><button type="button" class="icon-button" aria-label="Close flow picker" onclick={()=>picker.close()}><Icon name="close"/></button></div><input type="search" aria-label="Search flows" placeholder="Search flows" bind:this={searchInput} bind:value={search}/><div class="choices">{#each choices as [type,label]}<button type="button" class="quiet choice" disabled={!flowAvailable(type)} onclick={()=>add(type)}>{label}{flowAvailable(type)?'':' · Not yet supported'}<span aria-hidden="true">+</span></button>{/each}{#if !choices.length}<p>No flows found.</p>{/if}</div></dialog>
<style>
.mix-tools{display:flex;gap:8px;font-size:12px;margin-bottom:8px;flex-wrap:wrap}.mix{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:20px;margin:20px 0}.mix .section-head{margin-bottom:14px}.mix h2{font-size:15px}.mix p{font-size:12px}.flow-row{display:grid;grid-template-columns:minmax(0,1fr) 90px 32px;gap:14px;align-items:center;border-top:1px solid var(--border);padding:8px 0}.flow-name{justify-content:flex-start;text-align:left;padding:8px;gap:14px;font-size:13px;white-space:normal}.chevron{margin-left:auto;color:var(--subtle)}.flow-weight{display:flex;align-items:center;gap:7px}.flow-weight input{margin:0;text-align:center;width:68px;min-height:34px}.flow-weight span{font-size:12px}.flow-options{padding:16px;background:var(--surface-muted);border-radius:7px;margin-bottom:8px}.internal-name span{font-weight:400;color:var(--muted)}.internal-name{grid-column:1/-1}.internal-name input{max-width:420px}.choices{margin-top:14px;max-height:340px;overflow:auto;display:grid;gap:4px}.choice{justify-content:space-between;width:100%;padding:12px;text-align:left;font-weight:400}.mix-tools:empty{display:none}@media(max-width:600px){.flow-row{gap:6px;grid-template-columns:minmax(0,1fr) 76px 32px}.flow-name{flex-wrap:wrap;gap:3px}.chevron{display:none}.flow-weight input{width:55px}}
</style>