-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crash in "Open session" widget for sessions that have 'track-less…
… views' (#4043)
- Loading branch information
Showing
10 changed files
with
252 additions
and
200 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
plugins/menus/src/SessionManager/components/AutosavedSessionsList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react' | ||
import { List, ListSubheader, Paper } from '@mui/material' | ||
import { makeStyles } from 'tss-react/mui' | ||
|
||
import { observer } from 'mobx-react' | ||
|
||
// icons | ||
import { SessionModel, SessionSnap } from './util' | ||
import SessionListItem from './SessionListItem' | ||
|
||
const useStyles = makeStyles()(theme => ({ | ||
root: { | ||
margin: theme.spacing(1), | ||
}, | ||
})) | ||
|
||
const AutosaveSessionsList = observer(function ({ | ||
session, | ||
}: { | ||
session: SessionModel | ||
}) { | ||
const { classes } = useStyles() | ||
const autosavedSession = JSON.parse( | ||
localStorage.getItem(session.previousAutosaveId) || '{}', | ||
).session as SessionSnap | ||
|
||
return autosavedSession ? ( | ||
<Paper className={classes.root}> | ||
<List subheader={<ListSubheader>Previous autosaved entry</ListSubheader>}> | ||
<SessionListItem | ||
session={session} | ||
sessionSnapshot={autosavedSession} | ||
onClick={() => session.loadAutosaveSession()} | ||
/> | ||
</List> | ||
</Paper> | ||
) : null | ||
}) | ||
|
||
export default AutosaveSessionsList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
plugins/menus/src/SessionManager/components/RegularSavedSessionsList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import React, { useState } from 'react' | ||
import { | ||
IconButton, | ||
List, | ||
ListSubheader, | ||
Paper, | ||
Typography, | ||
} from '@mui/material' | ||
import { makeStyles } from 'tss-react/mui' | ||
|
||
import { observer } from 'mobx-react' | ||
|
||
// icons | ||
import DeleteIcon from '@mui/icons-material/Delete' | ||
|
||
// locals | ||
import { SessionModel } from './util' | ||
import DeleteSavedSessionDialog from './DeleteSavedSessionDialog' | ||
import SessionListItem from './SessionListItem' | ||
|
||
const useStyles = makeStyles()(theme => ({ | ||
root: { | ||
margin: theme.spacing(1), | ||
}, | ||
message: { | ||
padding: theme.spacing(3), | ||
}, | ||
})) | ||
|
||
const RegularSavedSessionsList = observer(function ({ | ||
session, | ||
}: { | ||
session: SessionModel | ||
}) { | ||
const { classes } = useStyles() | ||
const [sessionIndexToDelete, setSessionIndexToDelete] = useState<number>() | ||
|
||
function handleDialogClose(deleteSession = false) { | ||
if (deleteSession && sessionIndexToDelete !== undefined) { | ||
session.removeSavedSession(session.savedSessions[sessionIndexToDelete]) | ||
} | ||
setSessionIndexToDelete(undefined) | ||
} | ||
|
||
const sessionNameToDelete = | ||
sessionIndexToDelete !== undefined | ||
? session.savedSessions[sessionIndexToDelete].name | ||
: '' | ||
return ( | ||
<Paper className={classes.root}> | ||
<List subheader={<ListSubheader>Saved sessions</ListSubheader>}> | ||
{session.savedSessions.length ? ( | ||
session.savedSessions.map((sessionSnapshot, idx) => ( | ||
<SessionListItem | ||
onClick={() => session.activateSession(sessionSnapshot.name)} | ||
sessionSnapshot={sessionSnapshot} | ||
session={session} | ||
key={sessionSnapshot.name} | ||
secondaryAction={ | ||
<IconButton | ||
edge="end" | ||
disabled={session.name === sessionSnapshot.name} | ||
onClick={() => setSessionIndexToDelete(idx)} | ||
> | ||
<DeleteIcon /> | ||
</IconButton> | ||
} | ||
/> | ||
)) | ||
) : ( | ||
<Typography className={classes.message}> | ||
No saved sessions found | ||
</Typography> | ||
)} | ||
</List> | ||
{sessionNameToDelete ? ( | ||
<React.Suspense fallback={null}> | ||
<DeleteSavedSessionDialog | ||
open | ||
sessionNameToDelete={sessionNameToDelete} | ||
handleClose={handleDialogClose} | ||
/> | ||
</React.Suspense> | ||
) : null} | ||
</Paper> | ||
) | ||
}) | ||
|
||
export default RegularSavedSessionsList |
56 changes: 56 additions & 0 deletions
56
plugins/menus/src/SessionManager/components/SessionListItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from 'react' | ||
import { | ||
ListItem, | ||
ListItemButton, | ||
ListItemIcon, | ||
ListItemText, | ||
} from '@mui/material' | ||
|
||
import { observer } from 'mobx-react' | ||
import pluralize from 'pluralize' | ||
|
||
// icons | ||
import ViewListIcon from '@mui/icons-material/ViewList' | ||
import { AbstractSessionModel, sum } from '@jbrowse/core/util' | ||
|
||
// locals | ||
import { SessionSnap } from './util' | ||
|
||
const SessionListItem = observer(function ({ | ||
session, | ||
sessionSnapshot, | ||
onClick, | ||
secondaryAction, | ||
}: { | ||
sessionSnapshot: SessionSnap | ||
session: AbstractSessionModel | ||
onClick: () => void | ||
secondaryAction?: React.ReactNode | ||
}) { | ||
const { views = [] } = sessionSnapshot || {} | ||
const totalTracks = sum(views.map(view => view.tracks?.length ?? 0)) | ||
const n = views.length | ||
|
||
return ( | ||
<ListItem secondaryAction={secondaryAction}> | ||
<ListItemButton onClick={onClick}> | ||
<ListItemIcon> | ||
<ViewListIcon /> | ||
</ListItemIcon> | ||
<ListItemText | ||
primary={sessionSnapshot.name} | ||
secondary={ | ||
session.name === sessionSnapshot.name | ||
? 'Currently open' | ||
: `${n} ${pluralize('view', n)}; ${totalTracks} open ${pluralize( | ||
'track', | ||
totalTracks, | ||
)}` | ||
} | ||
/> | ||
</ListItemButton> | ||
</ListItem> | ||
) | ||
}) | ||
|
||
export default SessionListItem |
168 changes: 12 additions & 156 deletions
168
plugins/menus/src/SessionManager/components/SessionManager.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.