-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Back with main
- Loading branch information
Showing
19 changed files
with
3,717 additions
and
2,755 deletions.
There are no files selected for viewing
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
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,63 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import { ResizableBox } from 'react-resizable' | ||
import { observer } from 'mobx-react' | ||
import { AbstractViewModel, SessionWithDrawerWidgets } from '@jbrowse/core/util' | ||
import { SnackbarMessage } from '@jbrowse/core/ui/SnackbarModel' | ||
import { MenuItem as JBMenuItem } from '@jbrowse/core/ui/Menu' | ||
import DraggableDialog from '@jbrowse/core/ui/DraggableDialog' | ||
|
||
// locals | ||
import StaticViewPanel from './StaticViewPanel' | ||
import './test.css' | ||
import useMeasure from '@jbrowse/core/util/useMeasure' | ||
|
||
type AppSession = SessionWithDrawerWidgets & { | ||
savedSessionNames: string[] | ||
menus: { | ||
label: string | ||
menuItems: JBMenuItem[] | ||
}[] | ||
snackbarMessages: SnackbarMessage[] | ||
renameCurrentSession: (arg: string) => void | ||
popSnackbarMessage: () => unknown | ||
} | ||
|
||
const FloatingViewPanel = observer(function ({ | ||
view, | ||
session, | ||
}: { | ||
view: AbstractViewModel | ||
session: AppSession | ||
}) { | ||
const zIndex = session.focusedViewId === view.id ? 101 : 100 | ||
const [ref, { height }] = useMeasure() | ||
const [mode, setMode] = useState<'se' | 'e'>('se') | ||
const [size, setSize] = useState<{ width: number; height: number }>() | ||
const h = size !== undefined ? size.height : undefined | ||
|
||
useEffect(() => { | ||
if (h !== undefined && height !== undefined && height - h > 50) { | ||
setMode('e') | ||
} | ||
}, [h, height]) | ||
|
||
return ( | ||
<DraggableDialog zIndex={zIndex}> | ||
<ResizableBox | ||
className="box" | ||
height={(height || 100) + 20} | ||
resizeHandles={[mode]} | ||
onResize={(_event, { size }) => { | ||
setSize(size) | ||
}} | ||
width={1000} | ||
> | ||
<div ref={ref}> | ||
<StaticViewPanel view={view} session={session} /> | ||
</div> | ||
</ResizableBox> | ||
</DraggableDialog> | ||
) | ||
}) | ||
|
||
export default FloatingViewPanel |
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,65 @@ | ||
import React, { Suspense } from 'react' | ||
import { ErrorBoundary } from '@jbrowse/core/ui/ErrorBoundary' | ||
import { observer } from 'mobx-react' | ||
|
||
// locals | ||
import { | ||
getEnv, | ||
AbstractViewModel, | ||
SessionWithDrawerWidgets, | ||
} from '@jbrowse/core/util' | ||
import { SnackbarMessage } from '@jbrowse/core/ui/SnackbarModel' | ||
|
||
// ui elements | ||
import ErrorMessage from '@jbrowse/core/ui/ErrorMessage' | ||
import LoadingEllipses from '@jbrowse/core/ui/LoadingEllipses' | ||
import { MenuItem as JBMenuItem } from '@jbrowse/core/ui/Menu' | ||
|
||
// locals | ||
import ViewContainer from './ViewContainer' | ||
|
||
type AppSession = SessionWithDrawerWidgets & { | ||
savedSessionNames: string[] | ||
menus: { label: string; menuItems: JBMenuItem[] }[] | ||
snackbarMessages: SnackbarMessage[] | ||
renameCurrentSession: (arg: string) => void | ||
popSnackbarMessage: () => unknown | ||
} | ||
|
||
const StaticViewPanel = observer(function StaticViewPanel2({ | ||
view, | ||
session, | ||
}: { | ||
view: AbstractViewModel | ||
session: AppSession | ||
}) { | ||
const { pluginManager } = getEnv(session) | ||
const viewType = pluginManager.getViewType(view.type) | ||
if (!viewType) { | ||
throw new Error(`unknown view type ${view.type}`) | ||
} | ||
const { ReactComponent } = viewType | ||
return ( | ||
<ViewContainer | ||
view={view} | ||
onClose={() => { | ||
session.removeView(view) | ||
}} | ||
onMinimize={() => { | ||
view.setMinimized(!view.minimized) | ||
}} | ||
> | ||
{!view.minimized ? ( | ||
<ErrorBoundary | ||
FallbackComponent={({ error }) => <ErrorMessage error={error} />} | ||
> | ||
<Suspense fallback={<LoadingEllipses variant="h6" />}> | ||
<ReactComponent model={view} session={session} /> | ||
</Suspense> | ||
</ErrorBoundary> | ||
) : null} | ||
</ViewContainer> | ||
) | ||
}) | ||
|
||
export default StaticViewPanel |
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,19 @@ | ||
import React, { useEffect, useRef } from 'react' | ||
import { observer } from 'mobx-react' | ||
|
||
const StaticViewWrapper = observer(function ({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
const scrollRef = useRef<HTMLDivElement>(null) | ||
|
||
// scroll the view into view when first mounted. note: this effect will run | ||
// only once, because of the empty array second param | ||
useEffect(() => { | ||
scrollRef.current?.scrollIntoView({ block: 'center' }) | ||
}, []) | ||
return <div>{children}</div> | ||
}) | ||
|
||
export default StaticViewWrapper |
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
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
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
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,53 @@ | ||
import React from 'react' | ||
import { IconButton } from '@mui/material' | ||
import { makeStyles } from 'tss-react/mui' | ||
import { observer } from 'mobx-react' | ||
import { IBaseViewModel } from '@jbrowse/core/pluggableElementTypes/models' | ||
|
||
// icons | ||
import CloseIcon from '@mui/icons-material/Close' | ||
import MinimizeIcon from '@mui/icons-material/Minimize' | ||
import AddIcon from '@mui/icons-material/Add' | ||
import OpenInNew from '@mui/icons-material/OpenInNew' | ||
|
||
const useStyles = makeStyles()(theme => ({ | ||
icon: { | ||
color: theme.palette.secondary.contrastText, | ||
}, | ||
})) | ||
|
||
const ViewHeaderButtons = observer(function ({ | ||
view, | ||
onClose, | ||
onMinimize, | ||
}: { | ||
view: IBaseViewModel | ||
onClose: () => void | ||
onMinimize: () => void | ||
}) { | ||
const { classes } = useStyles() | ||
return ( | ||
<> | ||
<IconButton | ||
data-testid="open_in_new" | ||
onClick={() => { | ||
view.setIsFloating(!view.isFloating) | ||
}} | ||
> | ||
<OpenInNew className={classes.icon} fontSize="small" /> | ||
</IconButton> | ||
<IconButton data-testid="minimize_view" onClick={onMinimize}> | ||
{view.minimized ? ( | ||
<AddIcon className={classes.icon} fontSize="small" /> | ||
) : ( | ||
<MinimizeIcon className={classes.icon} fontSize="small" /> | ||
)} | ||
</IconButton> | ||
<IconButton data-testid="close_view" onClick={onClose}> | ||
<CloseIcon className={classes.icon} fontSize="small" /> | ||
</IconButton> | ||
</> | ||
) | ||
}) | ||
|
||
export default ViewHeaderButtons |
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.