1
- import { createContext , useEffect , useMemo , useState } from 'react' ;
1
+ import {
2
+ createContext , useEffect , useMemo , useState ,
3
+ } from 'react' ;
2
4
3
- import { UpsetProvenance , UpsetActions , getActions , initializeProvenanceTracking } from '@visdesignlab/upset2-react' ;
5
+ import {
6
+ UpsetProvenance , UpsetActions , getActions , initializeProvenanceTracking ,
7
+ } from '@visdesignlab/upset2-react' ;
4
8
import { useRecoilValue , useSetRecoilState } from 'recoil' ;
9
+ import { BrowserRouter , Route , Routes } from 'react-router-dom' ;
10
+ import { convertConfig , DefaultConfig , UpsetConfig } from '@visdesignlab/upset2-core' ;
11
+ import { CircularProgress } from '@mui/material' ;
12
+ import { ProvenanceGraph } from '@trrack/core/graph/graph-slice' ;
5
13
import { dataSelector , encodedDataAtom } from './atoms/dataAtom' ;
6
14
import { Root } from './components/Root' ;
7
- import { BrowserRouter , Route , Routes } from 'react-router-dom' ;
8
15
import { DataTable } from './components/DataTable' ;
9
- import { convertConfig , DefaultConfig , UpsetConfig } from '@visdesignlab/upset2-core' ;
10
16
import { configAtom } from './atoms/configAtoms' ;
11
17
import { queryParamAtom } from './atoms/queryParamAtom' ;
12
18
import { getMultinetSession } from './api/session' ;
13
- import { CircularProgress } from '@mui/material' ;
14
- import { ProvenanceGraph } from '@trrack/core/graph/graph-slice' ;
15
19
16
20
/** @jsxImportSource @emotion /react */
17
21
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -29,60 +33,60 @@ function App() {
29
33
const multinetData = useRecoilValue ( dataSelector ) ;
30
34
const encodedData = useRecoilValue ( encodedDataAtom ) ;
31
35
const setState = useSetRecoilState ( configAtom ) ;
32
- const data = ( encodedData === null ) ? multinetData : encodedData
36
+ const data = ( encodedData === null ) ? multinetData : encodedData ;
33
37
const { workspace, sessionId } = useRecoilValue ( queryParamAtom ) ;
34
38
const [ sessionState , setSessionState ] = useState < SessionState > ( null ) ; // null is not tried to load, undefined is tried and no state to load, and value is loaded value
35
39
36
40
const conf = useMemo ( ( ) => {
37
- const config : UpsetConfig = { ...DefaultConfig }
41
+ const config : UpsetConfig = { ...DefaultConfig } ;
38
42
if ( data !== null ) {
39
- const conf : UpsetConfig = JSON . parse ( JSON . stringify ( config ) )
43
+ const newConf : UpsetConfig = JSON . parse ( JSON . stringify ( config ) ) ;
40
44
if ( config . visibleSets . length === 0 ) {
41
45
const setList = Object . entries ( data . sets ) ;
42
- conf . visibleSets = setList . slice ( 0 , defaultVisibleSets ) . map ( ( set ) => set [ 0 ] ) // get first 6 set names
43
- conf . allSets = setList . map ( ( set ) => { return { name : set [ 0 ] , size : set [ 1 ] . size } } )
46
+ newConf . visibleSets = setList . slice ( 0 , defaultVisibleSets ) . map ( ( set ) => set [ 0 ] ) ; // get first 6 set names
47
+ newConf . allSets = setList . map ( ( set ) => ( { name : set [ 0 ] , size : set [ 1 ] . size } ) ) ;
44
48
}
45
49
46
50
// Add first 4 attribute columns (deviation + 3 attrs) to visibleAttributes
47
- conf . visibleAttributes = [ ...DefaultConfig . visibleAttributes , ...data . attributeColumns . slice ( 0 , 4 ) ] ;
51
+ newConf . visibleAttributes = [ ...DefaultConfig . visibleAttributes , ...data . attributeColumns . slice ( 0 , 4 ) ] ;
48
52
49
53
// Default: a histogram for each attribute if no plots exist
50
- if ( conf . plots . histograms . length + conf . plots . scatterplots . length === 0 ) {
51
- conf . plots . histograms = data . attributeColumns . map ( ( attr ) => {
52
- return {
53
- attribute : attr ,
54
- bins : 20 , // 20 bins is the default used in upset/.../AddPlot.tsx
55
- type : 'Histogram' ,
56
- frequency : false ,
57
- id : Date . now ( ) . toString ( ) // Same calculation as in upset/.../AddPlot.tsx
58
- }
59
- } )
54
+ if ( newConf . plots . histograms . length + newConf . plots . scatterplots . length === 0 ) {
55
+ newConf . plots . histograms = data . attributeColumns . map ( ( attr ) => ( {
56
+ attribute : attr ,
57
+ bins : 20 , // 20 bins is the default used in upset/.../AddPlot.tsx
58
+ type : 'Histogram' ,
59
+ frequency : false ,
60
+ id : Date . now ( ) . toString ( ) , // Same calculation as in upset/.../AddPlot.tsx
61
+ } ) ) ;
60
62
}
61
63
62
- return conf ;
64
+ return newConf ;
63
65
}
66
+
67
+ return config ;
64
68
} , [ data ] ) ;
65
69
66
70
// Initialize Provenance and pass it setter to connect
67
71
const { provenance, actions } = useMemo ( ( ) => {
68
72
if ( sessionState ) {
69
- const provenance : UpsetProvenance = initializeProvenanceTracking ( conf ) ;
70
- const actions : UpsetActions = getActions ( provenance ) ;
73
+ const prov : UpsetProvenance = initializeProvenanceTracking ( conf ?? undefined ) ;
74
+ const act : UpsetActions = getActions ( prov ) ;
71
75
72
76
// Make sure the provenance state gets converted every time this is called
73
- ( provenance as UpsetProvenance & { _getState : typeof provenance . getState } ) . _getState = provenance . getState ;
74
- provenance . getState = ( ) => convertConfig (
75
- ( provenance as UpsetProvenance & { _getState : typeof provenance . getState } ) . _getState ( )
77
+ ( prov as UpsetProvenance & { _getState : typeof prov . getState } ) . _getState = prov . getState ;
78
+ prov . getState = ( ) => convertConfig (
79
+ ( prov as UpsetProvenance & { _getState : typeof prov . getState } ) . _getState ( ) ,
76
80
) ;
77
81
78
82
if ( sessionState && sessionState !== 'not found' ) {
79
- provenance . importObject ( structuredClone ( sessionState ) ) ;
83
+ prov . importObject ( structuredClone ( sessionState ) ) ;
80
84
}
81
85
82
86
// Make sure the config atom stays up-to-date with the provenance
83
- provenance . currentChange ( ( ) => setState ( provenance . getState ( ) ) ) ;
87
+ prov . currentChange ( ( ) => setState ( prov . getState ( ) ) ) ;
84
88
85
- return { provenance : provenance , actions : actions } ;
89
+ return { provenance : prov , actions : act } ;
86
90
}
87
91
return { provenance : null , actions : null } ;
88
92
} , [ conf , setState , sessionState ] ) ;
@@ -108,31 +112,29 @@ function App() {
108
112
update ( ) ;
109
113
} , [ sessionId , workspace ] ) ;
110
114
115
+ const provContext = useMemo ( ( ) => ( provenance && actions ? { provenance, actions } : null ) , [ provenance , actions ] ) ;
116
+
111
117
// Update the state on first render and if the provenance object changes
112
- useEffect ( ( ) => { if ( provenance ?. getState ( ) ) setState ( provenance ?. getState ( ) ) } , [ provenance , setState ] ) ;
118
+ useEffect ( ( ) => { if ( provenance ?. getState ( ) ) setState ( provenance ?. getState ( ) ) ; } , [ provenance , setState ] ) ;
113
119
114
120
return (
115
121
< BrowserRouter >
116
- { provenance ?
122
+ { ( provenance && provContext ) ?
117
123
< ProvenanceContext . Provider
118
- value = { {
119
- provenance,
120
- actions,
121
- } }
124
+ value = { provContext }
122
125
>
123
126
< Routes >
124
127
< Route path = "*" element = { < Root provenance = { provenance } actions = { actions } data = { null } config = { conf } /> } />
125
128
< Route path = "/" element = { < Root provenance = { provenance } actions = { actions } data = { data } config = { conf } /> } />
126
129
< Route path = "/datatable" element = { < DataTable /> } />
127
130
</ Routes >
128
131
</ ProvenanceContext . Provider >
129
- :
132
+ :
130
133
< Routes >
131
134
< Route path = "*" element = { < CircularProgress /> } />
132
135
< Route path = "/" element = { < CircularProgress /> } />
133
136
< Route path = "/datatable" element = { < DataTable /> } />
134
- </ Routes >
135
- }
137
+ </ Routes > }
136
138
</ BrowserRouter >
137
139
) ;
138
140
}
0 commit comments