@@ -72,6 +72,25 @@ type TimelineEvent = {
7272 carbonChange : number
7373
7474 explanation ?: string
75+
76+ rateEventType ?: NonNullable < PlanRow [ 'rate_event_type' ] >
77+ }
78+
79+ const RATE_EVENT_DETAILS : Record < NonNullable < PlanRow [ 'rate_event_type' ] > , { label : string ; colour : string } > = {
80+ octopus_power_down : { label : 'Power Down' , colour : 'power-down' } ,
81+ octopus_power_up : { label : 'Power Up' , colour : 'power-up' } ,
82+ octopus_happy_hour : { label : 'Happy Hour' , colour : 'power-up' } ,
83+ axle_import : { label : 'Axle import' , colour : 'axle-import' } ,
84+ axle_export : { label : 'Axle export' , colour : 'axle-export' } ,
85+ axle_event : { label : 'Axle event' , colour : 'axle-event' } ,
86+ energy_event : { label : 'Energy event' , colour : 'generic' }
87+ }
88+
89+ function getRateEventType ( row : PlanRow ) {
90+ const isEnergyEvent =
91+ row . import_rate_adjust_type === 'saving' || row . export_rate_adjust_type === 'saving'
92+
93+ return isEnergyEvent ? ( row . rate_event_type ?? 'energy_event' ) : undefined
7594}
7695
7796type TimelineTick = {
@@ -409,6 +428,8 @@ function buildTimelineEvents(
409428
410429 let currentAction = getTimelineAction ( rows [ 0 ] . state )
411430
431+ let currentRateEventType = getRateEventType ( rows [ 0 ] )
432+
412433 function addEvent ( endIndex : number ) {
413434 const eventRows = rows . slice ( startIndex , endIndex + 1 )
414435
@@ -533,19 +554,25 @@ function buildTimelineEvents(
533554
534555 carCharging,
535556
536- explanation
557+ explanation,
558+
559+ rateEventType : currentRateEventType
537560 } )
538561 }
539562
540563 for ( let index = 1 ; index < rows . length ; index += 1 ) {
541564 const action = getTimelineAction ( rows [ index ] . state )
542565
543- if ( action !== currentAction ) {
566+ const rateEventType = getRateEventType ( rows [ index ] )
567+
568+ if ( action !== currentAction || rateEventType !== currentRateEventType ) {
544569 addEvent ( index - 1 )
545570
546571 startIndex = index
547572
548573 currentAction = action
574+
575+ currentRateEventType = rateEventType
549576 }
550577 }
551578
@@ -897,6 +924,10 @@ export default function PlanVisual({ plan }: PlanVisualProps) {
897924 ? formatTargetSoc ( activeEvent . targetSocStart , activeEvent . targetSocEnd )
898925 : null
899926
927+ const activeRateEvent = activeEvent ?. rateEventType
928+ ? RATE_EVENT_DETAILS [ activeEvent . rateEventType ]
929+ : null
930+
900931 const ticks = buildTimeTicks ( timelineStart , timelineEnd )
901932
902933 /*
@@ -1025,6 +1056,14 @@ export default function PlanVisual({ plan }: PlanVisualProps) {
10251056
10261057 < span > { formatEventRange ( activeEvent . start , activeEvent . end ) } </ span >
10271058 </ div >
1059+
1060+ { activeRateEvent && (
1061+ < span className = { `plan-timeline-rate-event is-${ activeRateEvent . colour } ` } >
1062+ < FontAwesomeIcon icon = { faBolt } aria-hidden = "true" />
1063+
1064+ { activeRateEvent . label }
1065+ </ span >
1066+ ) }
10281067 </ div >
10291068
10301069 < div className = "plan-timeline-detail-values" >
@@ -1156,18 +1195,23 @@ export default function PlanVisual({ plan }: PlanVisualProps) {
11561195
11571196 const isActive = activeEvent ?. id === event . id
11581197
1198+ const rateEvent = event . rateEventType
1199+ ? RATE_EVENT_DETAILS [ event . rateEventType ]
1200+ : null
1201+
11591202 return (
11601203 < button
11611204 key = { event . id }
11621205 type = "button"
1163- className = { `plan-timeline-event timeline-action-${ event . action } ${ isCurrent ? 'is-current' : '' } ${ isActive ? 'is-active' : '' } ` }
1206+ className = { `plan-timeline-event timeline-action-${ event . action } ${ rateEvent ? `timeline-rate-event- ${ rateEvent . colour } ` : '' } ${ isCurrent ? 'is-current' : '' } ${ isActive ? 'is-active' : '' } ` }
11641207 style = { {
11651208 left : `${ startX } px` ,
11661209
11671210 width : `${ eventWidth } px`
11681211 } }
11691212 aria-label = {
1170- `${ getEventTitle ( event ) } , ` + `${ formatEventRange ( event . start , event . end ) } `
1213+ `${ rateEvent ? `${ rateEvent . label } , ` : '' } ${ getEventTitle ( event ) } , ` +
1214+ `${ formatEventRange ( event . start , event . end ) } `
11711215 }
11721216 aria-pressed = { selectedEventId === event . id }
11731217 onMouseEnter = { ( ) => {
0 commit comments