diff --git a/resources/js/pages/Scenarios/Show.tsx b/resources/js/pages/Scenarios/Show.tsx index c347013..cdbebde 100644 --- a/resources/js/pages/Scenarios/Show.tsx +++ b/resources/js/pages/Scenarios/Show.tsx @@ -18,7 +18,8 @@ interface Bucket { allocation_type: string; allocation_value: number | null; allocation_type_label: string; - formatted_allocation_value: string; + buffer_multiplier: number; + effective_capacity: number; current_balance: number; has_available_space: boolean; available_space: number; @@ -64,11 +65,22 @@ const bucketTypeBorderColor = { overflow: 'border-amber-500', } as const; +const BUFFER_PRESETS = ['0', '0.5', '1', '1.5', '2'] as const; + +const formatAllocationValue = (bucket: Bucket): string => { + if (bucket.allocation_type === 'unlimited') return 'All remaining'; + if (bucket.allocation_value === null) return '--'; + if (bucket.allocation_type === 'percentage') return `${Number(bucket.allocation_value).toFixed(2)}%`; + return `$${Number(bucket.allocation_value).toFixed(2)}`; +}; + const defaultFormData = { name: '', type: 'need' as Bucket['type'], allocation_type: 'fixed_limit', - allocation_value: '' + allocation_value: '', + buffer_multiplier: '0', + buffer_mode: 'preset' as 'preset' | 'custom', }; export default function Show({ scenario, buckets, streams = { data: [] }, streamStats }: Props) { @@ -79,11 +91,15 @@ export default function Show({ scenario, buckets, streams = { data: [] }, stream const handleEdit = (bucket: Bucket) => { setEditingBucket(bucket); + const bufferStr = bucket.buffer_multiplier.toString(); + const isPreset = (BUFFER_PRESETS as readonly string[]).includes(bufferStr); setFormData({ name: bucket.name, type: bucket.type, allocation_type: bucket.allocation_type, - allocation_value: bucket.allocation_value ? bucket.allocation_value.toString() : '' + allocation_value: bucket.allocation_value ? bucket.allocation_value.toString() : '', + buffer_multiplier: bufferStr, + buffer_mode: isPreset ? 'preset' : 'custom', }); setIsModalOpen(true); }; @@ -133,6 +149,7 @@ export default function Show({ scenario, buckets, streams = { data: [] }, stream type: formData.type, allocation_type: formData.allocation_type, allocation_value: formData.allocation_value ? parseFloat(formData.allocation_value) : null, + buffer_multiplier: formData.allocation_type === 'fixed_limit' ? parseFloat(formData.buffer_multiplier) || 0 : 0, priority: editingBucket ? editingBucket.priority : undefined }), }); @@ -174,6 +191,7 @@ export default function Show({ scenario, buckets, streams = { data: [] }, stream type: bucket.type, allocation_type: bucket.allocation_type, allocation_value: bucket.allocation_value, + buffer_multiplier: bucket.buffer_multiplier, priority: newPriority }), }); @@ -283,23 +301,28 @@ export default function Show({ scenario, buckets, streams = { data: [] }, stream