All files / src/pages/flowsheet-page/flowsheet/Summary Summary.tsx

85.71% Statements 6/7
66.66% Branches 2/3
100% Functions 3/3
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69                    5x 5x     1x     5x                                         8x 8x                                                          
import CompoundSummary from './CompoundSummary'
import UnitopsSummary from './UnitopsSummary'
import StreamsSummary from './StreamsSummary'
import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/ahuora-design-system/ui/tabs'
import { Select, SelectTrigger, SelectValue, SelectContent, SelectGroup, SelectLabel, SelectItem } from '@/ahuora-design-system/ui/select'
import { GroupWithObject, useFlowsheetGroupsWithSimulationObjects } from '@/hooks/flowsheetObjects'
import { useSearchParam } from '@/hooks/searchParams'
import ExportExcel from './ExportExcel'
 
export default function Summary() {
    const groups: GroupWithObject[] | undefined = useFlowsheetGroupsWithSimulationObjects()
    const [param, setParam] = useSearchParam("parentGroup", groups?.[0]?.id)
 
    function handleChange(value) {
        setParam(value)
    }
 
    return (
        <Tabs defaultValue="streams" className='w-full flex flex-col'>
            <div className='flex justify-between p-4'>
                <TabsList className='p-0 w-fit bg-transparent rounded'>
                    <TabsTrigger value="streams">Streams</TabsTrigger>
                    <TabsTrigger value="compounds">Compounds</TabsTrigger>
                    <TabsTrigger value="objects">Objects</TabsTrigger>
                </TabsList>
                <div className='flex gap-2'>
                    <ExportExcel groups={groups} />
                    <Select onValueChange={handleChange} value={+param!}>
                        {groups && (
                            <>
                                <SelectTrigger className="w-[180px] border rounded" aria-label="group-layer-select">
                                    <SelectValue placeholder="Select a layer" />
                                </SelectTrigger>
                                <SelectContent>
                                    <SelectGroup>
                                        <SelectLabel>Layers</SelectLabel>
                                        {
                                            groups?.map((group: GroupWithObject) => {
                                                Iif (!group.simulationObjectRead) return null;
                                                return (
                                                    <SelectItem 
                                                        key={group.id} 
                                                        value={group.id} 
                                                    >
                                                        {group.simulationObjectRead?.componentName}
                                                    </SelectItem>
                                                )
                                            })
                                        }
                                    </SelectGroup>
                                </SelectContent>
                            </>
                        )}
                    </Select>
                </div>
            </div>
            <TabsContent value="streams" asChild>
                <StreamsSummary />
            </TabsContent>
            <TabsContent value="compounds" asChild>
                <CompoundSummary />
            </TabsContent>
            <TabsContent value="objects" asChild>
                <UnitopsSummary />
            </TabsContent>
        </Tabs>
    )
}