22
33import React , { useState , useEffect , useMemo } from "react" ;
44import { TbVariable } from "react-icons/tb" ;
5- import { useGlobalStore } from "@/utils/GlobalStates" ;
5+ import { useGlobalStore , useZarrStore } from "@/utils/GlobalStates" ;
66import { useShallow } from "zustand/shallow" ;
77import { Separator } from "@/components/ui/separator" ;
88import MetaDataInfo from "./MetaDataInfo" ;
@@ -20,6 +20,7 @@ import {
2020 DialogContent ,
2121 DialogTitle ,
2222} from "@/components/ui/dialog" ;
23+ import { ZarrDataset } from "@/components/zarr/ZarrLoaderLRU" ;
2324
2425const Variables = ( {
2526 openVariables,
@@ -32,13 +33,20 @@ const Variables = ({
3233 const [ openMetaPopover , setOpenMetaPopover ] = useState ( false ) ;
3334
3435 const [ showMeta , setShowMeta ] = useState ( false ) ;
35- const { variables, zMeta, initStore } = useGlobalStore (
36+ const { variables, zMeta, metadata , setMetadata , initStore } = useGlobalStore (
3637 useShallow ( ( state ) => ( {
3738 variables : state . variables ,
3839 zMeta : state . zMeta ,
40+ metadata : state . metadata ,
41+ setMetadata : state . setMetadata ,
3942 initStore : state . initStore
4043 } ) )
4144 ) ;
45+ const { currentStore } = useZarrStore ( useShallow ( state => ( {
46+ currentStore : state . currentStore ,
47+ } ) ) )
48+ const ZarrDS = useMemo ( ( ) => new ZarrDataset ( currentStore ) , [ currentStore ] )
49+
4250 const [ dimArrays , setDimArrays ] = useState ( [ [ 0 ] , [ 0 ] , [ 0 ] ] )
4351 const [ dimUnits , setDimUnits ] = useState ( [ null , null , null ] )
4452 const [ dimNames , setDimNames ] = useState < string [ ] > ( [ "Default" ] )
@@ -61,6 +69,7 @@ const Variables = ({
6169 const relevant = zMeta . find ( ( e : any ) => e . name === selectedVar ) ;
6270 if ( relevant ) {
6371 setMeta ( { ...relevant , dimInfo : { dimArrays, dimNames, dimUnits} } ) ;
72+ ZarrDS . GetAttributes ( selectedVar ) . then ( e => setMetadata ( e ) )
6473 }
6574 }
6675 } , [ selectedVar , variables , zMeta , dimArrays , dimNames , dimUnits ] ) ;
@@ -69,6 +78,7 @@ const Variables = ({
6978 setSelectedIndex ( null )
7079 setSelectedVar ( null )
7180 setMeta ( null )
81+ setMetadata ( null )
7282 } , [ initStore ] )
7383
7484 useEffect ( ( ) => {
@@ -191,9 +201,11 @@ const Variables = ({
191201 >
192202 { meta && (
193203 < MetaDataInfo
194- meta = { meta }
204+ meta = { meta }
205+ metadata = { metadata ?? { } }
195206 setShowMeta = { setOpenMetaPopover }
196207 setOpenVariables = { setOpenVariables }
208+ popoverSide = { "left" }
197209 />
198210 ) }
199211 </ PopoverContent >
@@ -202,12 +214,16 @@ const Variables = ({
202214 { popoverSide === "top" && (
203215 < Dialog open = { showMeta } onOpenChange = { setShowMeta } >
204216 < DialogContent className = "max-w-[85%] md:max-w-2xl max-h-[80vh] overflow-y-auto" >
205- < DialogTitle className = "text-center text-lg font-semibold" >
206- { selectedVar }
207- </ DialogTitle >
208- < div className = "mt-4" >
217+ < DialogTitle > { } </ DialogTitle >
218+ < div className = "-mt-4" >
209219 { meta && (
210- < MetaDataInfo meta = { meta } setShowMeta = { setShowMeta } setOpenVariables = { setOpenVariables } />
220+ < MetaDataInfo
221+ meta = { meta }
222+ metadata = { metadata ?? { } }
223+ setShowMeta = { setShowMeta }
224+ setOpenVariables = { setOpenVariables }
225+ popoverSide = { "top" }
226+ />
211227 ) }
212228 </ div >
213229 </ DialogContent >
0 commit comments