11import React , { useMemo , useState } from "react" ;
2- import { Accordion , Autocomplete , Banner , Table , Typography } from "@equinor/eds-core-react" ;
2+ import { Autocomplete , Banner , Table , Typography } from "@equinor/eds-core-react" ;
33import { GridSimulationResult } from "@/dto/GridSimulation" ;
44import { formatConcentration } from "@/functions/Formatting" ;
55import {
@@ -13,7 +13,8 @@ import { optionName } from "@/functions/Substance";
1313import LineChart , { LineSeries } from "@/components/LineChart" ;
1414import DownloadButton from "@/components/DownloadButton" ;
1515import { useAvailableModels } from "@/contexts/ModelContext" ;
16- import { buildModelSections , ModelSection } from "@/utils/modelUtils" ;
16+ import { buildModelSections , phaseLabel } from "@/utils/modelUtils" ;
17+ import ModelAccordionLayout , { AccordionItem } from "@/components/ModelAccordionLayout" ;
1718
1819interface GridResultsProps {
1920 result : GridSimulationResult ;
@@ -25,10 +26,6 @@ interface GridPhaseChartProps {
2526 phaseKind : string ;
2627}
2728
28- function phaseLabel ( kind : string ) : string {
29- return kind === "aqueous" ? "Aqueous" : "CO2-rich" ;
30- }
31-
3229const GridPhaseChart : React . FC < GridPhaseChartProps > = ( { result, modelIndex, phaseKind } ) => {
3330 const { simulations, axes } = result ;
3431
@@ -146,13 +143,21 @@ const GridResults: React.FC<GridResultsProps> = ({ result }) => {
146143 const firstSim = simulations [ 0 ] ;
147144 const inputModels = firstSim ?. input . models ?? [ ] ;
148145
149- const sections : ModelSection [ ] = buildModelSections ( inputModels , models ) ;
146+ const sections = buildModelSections ( inputModels , models ) ;
150147
151148 const erroredSimulations = simulations . filter ( ( sim ) => sim . status === "error" ) ;
152149
153150 const xAxisSubstance = axes [ 0 ] ?. substance ?? "Unknown" ;
154151 const modelLabel = inputModels . map ( ( model ) => model . modelId ) . join ( " → " ) || "Unknown model" ;
155152
153+ const items : AccordionItem [ ] = sections . flatMap ( ( section ) =>
154+ section . indices . map ( ( modelIndex ) => ( {
155+ key : `${ section . category } -${ modelIndex } ` ,
156+ header : `${ section . category } : ${ models . find ( ( m ) => m . modelId === inputModels [ modelIndex ] ?. modelId ) ?. displayName ?? inputModels [ modelIndex ] ?. modelId } ` ,
157+ content : < GridSection result = { result } modelIndex = { modelIndex } /> ,
158+ } ) )
159+ ) ;
160+
156161 return (
157162 < >
158163 < Typography variant = "body_short" style = { { marginBottom : "1rem" } } >
@@ -169,22 +174,7 @@ const GridResults: React.FC<GridResultsProps> = ({ result }) => {
169174 </ Banner >
170175 ) }
171176
172- < div style = { { display : "flex" , flexDirection : "column" , gap : "1rem" } } >
173- { sections . map ( ( section , sectionIndex ) =>
174- section . indices . map ( ( modelIndex ) => (
175- < Accordion key = { `${ section . category } -${ modelIndex } ` } >
176- < Accordion . Item isExpanded = { sectionIndex === sections . length - 1 } >
177- < Accordion . Header >
178- { `${ section . category } : ${ models . find ( ( m ) => m . modelId === inputModels [ modelIndex ] ?. modelId ) ?. displayName ?? inputModels [ modelIndex ] ?. modelId } ` }
179- </ Accordion . Header >
180- < Accordion . Panel >
181- < GridSection result = { result } modelIndex = { modelIndex } />
182- </ Accordion . Panel >
183- </ Accordion . Item >
184- </ Accordion >
185- ) )
186- ) }
187- </ div >
177+ < ModelAccordionLayout items = { items } />
188178
189179 < div style = { { display : "flex" , justifyContent : "flex-end" , marginTop : "1rem" , marginBottom : "2rem" } } >
190180 < DownloadButton
0 commit comments