Skip to content

Commit 98cfa80

Browse files
bbimberSebastian Benjamin
andauthored
Fix loading lifecycle flow when getting session (#259)
Co-authored-by: Sebastian Benjamin <sebastiancbenjamin@gmail.com>
1 parent 002550f commit 98cfa80

File tree

2 files changed

+23
-43
lines changed

2 files changed

+23
-43
lines changed

jbrowse/src/client/JBrowse/VariantSearch/VariantTable.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function VariantTable() {
4545

4646
const [session, setSession] = useState(null)
4747
const [state, setState] = useState(null)
48-
const [theme, setTheme] = useState(null)
48+
const [theme, setTheme] = useState(createTheme())
4949
const [view, setView] = useState(null)
5050
const [parsedLocString, setParsedLocString] = useState(null)
5151
const [assemblyNames, setAssemblyNames] = useState(null)
@@ -86,24 +86,11 @@ function VariantTable() {
8686
fetchSession(queryParam, sessionId, nativePlugins, refTheme, setState, true, [trackId], undefined, successCallback, trackId)
8787
}, []);
8888

89-
// Error handle and then render the component
90-
if (view === null || theme == null) {
91-
return (<LoadingIndicator isOpen={true}/>)
92-
}
93-
else if (view === "invalid" || state == "invalid") {
94-
return (<p>Error fetching config. See console for more details</p>)
95-
}
96-
97-
if (!assemblyNames.length) {
98-
return (<p>No configured assemblies</p>)
99-
}
100-
10189
return (
10290
<ThemeProvider theme={theme}>
10391
<div style={{height: "80vh", display:"block"}}>
10492
<ErrorBoundary>
105-
<VariantTableWidget assemblyName={assemblyNames[0]} assembly={assembly} trackId={trackId} locString={locString}
106-
parsedLocString={parsedLocString} sessionId={sessionId} session={session} pluginManager={pluginManager}/>
93+
<VariantTableWidget assembly={assembly} trackId={trackId} parsedLocString={parsedLocString} sessionId={sessionId} session={session} pluginManager={pluginManager}/>
10794
</ErrorBoundary>
10895
</div>
10996
</ThemeProvider>

jbrowse/src/client/JBrowse/VariantSearch/components/VariantTableWidget.tsx

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,20 @@ import { BaseFeatureDataAdapter } from '@jbrowse/core/data_adapters/BaseAdapter'
3636
import { lastValueFrom } from 'rxjs';
3737

3838
const VariantTableWidget = observer(props => {
39-
const { assembly, trackId, parsedLocString, sessionId, session, pluginManager } = props
40-
const { assemblyNames, assemblyManager } = session
41-
const { view } = session
42-
43-
// The code expects a proper GUID, yet the trackId is a string containing the GUID + filename
44-
const trackGUID = truncateToValidGUID(props.trackId)
45-
46-
// NOTE: since the trackId is GUID+filename, allow exact string matching, or a match on the GUID portion alone.
47-
// Upstream code might only have access to the GUID and translating to the trackId isnt always easy
48-
const track = view.tracks.find(
49-
t => t.configuration.trackId === trackId || truncateToValidGUID(t.configuration.trackId).toUpperCase() === trackGUID.toUpperCase()
50-
)
51-
52-
if (!track) {
53-
return (<p>Unknown track: {trackId}</p>)
39+
const { assembly, trackId, parsedLocString, sessionId, session, pluginManager } = props;
40+
const { assemblyNames = [], assemblyManager } = session ?? {};
41+
const { view } = session ?? {};
42+
43+
var track = undefined;
44+
var trackGUID = undefined;
45+
if(view && trackId) {
46+
// The code expects a proper GUID, yet the trackId is a string containing the GUID + filename
47+
// NOTE: since the trackId is GUID+filename, allow exact string matching, or a match on the GUID portion alone.
48+
// Upstream code might only have access to the GUID and translating to the trackId isnt always easy
49+
trackGUID = truncateToValidGUID(props.trackId)
50+
track = view.tracks.find(
51+
t => t.configuration.trackId === trackId || truncateToValidGUID(t.configuration.trackId).toUpperCase() === trackGUID.toUpperCase()
52+
)
5453
}
5554

5655
function handleSearch(data) {
@@ -150,7 +149,6 @@ const VariantTableWidget = observer(props => {
150149
<span className='table-cell-truncate'>{displayValue}</span>
151150
</Typography>
152151
{renderPopover &&
153-
// TODO
154152
<Popover
155153
id="mouse-over-popover"
156154
open={open}
@@ -236,7 +234,7 @@ const VariantTableWidget = observer(props => {
236234
const [activeWidgetList, setActiveWidgetList] = useState<string[]>([])
237235

238236
// False until initial data load or an error:
239-
const [dataLoaded, setDataLoaded] = useState(!parsedLocString)
237+
const [dataLoaded, setDataLoaded] = useState(false)
240238

241239
const urlParams = new URLSearchParams(window.location.search);
242240
const page = parseInt(urlParams.get('page') || '0');
@@ -278,20 +276,15 @@ const VariantTableWidget = observer(props => {
278276
})
279277
}
280278

281-
fetch()
279+
if(sessionId && trackGUID) {
280+
fetch()
281+
}
282+
282283
return () => {
283284
window.removeEventListener('popstate', handlePopState);
284285
};
285286

286-
}, [pluginManager, parsedLocString, session.visibleWidget])
287-
288-
if (!view) {
289-
return
290-
}
291-
292-
if (!track) {
293-
return(<p>Unable to find track: {trackId}</p>)
294-
}
287+
}, [pluginManager, parsedLocString, session?.visibleWidget, sessionId, trackGUID])
295288

296289
if (error) {
297290
throw new Error(error)
@@ -435,7 +428,7 @@ const VariantTableWidget = observer(props => {
435428
<LoadingIndicator isOpen={!dataLoaded}/>
436429

437430
{
438-
[...session.activeWidgets].map((elem) => {
431+
[...(session?.activeWidgets ?? [])].map((elem) => {
439432
const widget = elem[1]
440433
const widgetType = pluginManager.getWidgetType(widget.type)
441434
const { ReactComponent } = widgetType

0 commit comments

Comments
 (0)