@@ -6,8 +6,10 @@ import {
66 Card as MUICard ,
77 CircularProgress ,
88 Theme ,
9+ lighten ,
910} from "@mui/material" ;
1011import { makeStyles , styled } from "@mui/styles" ;
12+ import clsx from "clsx" ;
1113import groupBy from "lodash/groupBy" ;
1214import mapValues from "lodash/mapValues" ;
1315import React , { ChangeEvent , useMemo , useState } from "react" ;
@@ -56,7 +58,7 @@ const datasets = mapValues(
5658type Observation = Record < string , any > ;
5759type PivottedObservation = Record < string , any > ;
5860
59- const useStyles = makeStyles ( ( ) => ( {
61+ const useStyles = makeStyles ( ( theme : Theme ) => ( {
6062 table : {
6163 fontSize : "12px" ,
6264 borderCollapse : "collapse" ,
@@ -71,6 +73,22 @@ const useStyles = makeStyles(() => ({
7173 marginTop : "0.5rem" ,
7274 } ,
7375 } ,
76+ expanded : { } ,
77+ depth_0 : {
78+ "&$expanded" : {
79+ background : lighten ( theme . palette . primary . light , 0.75 ) ,
80+ } ,
81+ } ,
82+ depth_1 : {
83+ "&$expanded" : {
84+ background : lighten ( theme . palette . primary . light , 0.5 ) ,
85+ } ,
86+ } ,
87+ depth_2 : {
88+ "&$expanded" : {
89+ background : lighten ( theme . palette . primary . light , 0.15 ) ,
90+ } ,
91+ } ,
7492} ) ) ;
7593
7694const indexHierarchy = ( hierarchy : HierarchyValue [ ] ) => {
@@ -312,25 +330,26 @@ const Page = () => {
312330 Header : uv ,
313331 columns : measures
314332 . filter ( ( m ) => activeMeasures ?. [ m . iri ] !== false )
315- . map ( ( m ) => ( {
316- Header : m . label ,
317- Cell : m . label . includes ( "%" )
318- ? ( { cell } ) => {
319- return (
320- < div >
321- { cell . value }
333+ . map ( ( m ) => {
334+ const showBars = m . label . includes ( "%" ) ;
335+ return {
336+ Header : m . label ,
337+ Cell : ( { cell, row } ) => {
338+ return (
339+ < >
340+ { cell . value }
341+ { showBars ? (
322342 < Bar percent = { parseFloat ( cell . value ) } />
323- </ div >
324- ) ;
325- }
326- : ( { cell } ) => {
327- return < div > { cell . value } </ div > ;
328- } ,
329- id : `${ pivotDimension . iri } /${ uv } /${ m . iri } ` ,
330- accessor : ( x ) => {
331- return x [ `${ pivotDimension . iri } /${ uv } ` ] ?. [ m . iri ] || "" ;
332- } ,
333- } ) ) ,
343+ ) : null }
344+ </ >
345+ ) ;
346+ } ,
347+ id : `${ pivotDimension . iri } /${ uv } /${ m . iri } ` ,
348+ accessor : ( x ) => {
349+ return x [ `${ pivotDimension . iri } /${ uv } ` ] ?. [ m . iri ] || "" ;
350+ } ,
351+ } ;
352+ } ) ,
334353 } )
335354 ) ;
336355
@@ -357,7 +376,7 @@ const Page = () => {
357376 style,
358377 } ) }
359378 >
360- { row . canExpand ? ( row . isExpanded ? "▼ " : "▶ " ) : null }
379+ { row . canExpand ? ( row . isExpanded ? "▼ " : "▶ " ) : null }
361380 { cell . value }
362381 </ span >
363382 ) ;
@@ -388,17 +407,22 @@ const Page = () => {
388407 activeMeasures ,
389408 ] ) ;
390409
391- const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } =
392- useTable (
393- {
394- columns : columns ,
395- data : pivotDimension && tree ? tree : observations ,
396- } ,
397- useSortBy ,
398- useExpanded
399- // useExpanded // Use the useExpanded plugin hook
400- ) ;
401-
410+ const {
411+ getTableProps,
412+ getTableBodyProps,
413+ headerGroups,
414+ rows,
415+ prepareRow,
416+ expandedDepth,
417+ } = useTable (
418+ {
419+ columns : columns ,
420+ data : pivotDimension && tree ? tree : observations ,
421+ } ,
422+ useSortBy ,
423+ useExpanded
424+ ) ;
425+ console . log ( expandedDepth ) ;
402426 useEffect ( ( ) => {
403427 if ( ! Object . keys ( activeMeasures ) . length && measures ) {
404428 setActiveMeasures ( Object . fromEntries ( measures . map ( ( m ) => [ m . iri , true ] ) ) ) ;
@@ -576,7 +600,15 @@ const Page = () => {
576600 prepareRow ( row ) ;
577601 return (
578602 // eslint-disable-next-line react/jsx-key
579- < tr { ...row . getRowProps ( ) } >
603+ < tr
604+ { ...row . getRowProps ( ) }
605+ className = { clsx (
606+ classes [
607+ `depth_${ expandedDepth - row . depth } ` as keyof typeof classes
608+ ] ,
609+ row . isExpanded ? classes . expanded : null
610+ ) }
611+ >
580612 { row . cells . map ( ( cell ) => {
581613 return (
582614 // eslint-disable-next-line react/jsx-key
0 commit comments