Skip to content

Commit

Permalink
Avoid rendering undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed May 20, 2024
1 parent 1a44d00 commit c98e002
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ const Highlight = observer(function Highlight({ model }: { model: LGV }) {

const set = new Set(model.assemblyNames)

return showBookmarkHighlights
? bookmarkWidget?.bookmarks
?.filter(value => set.has(value.assemblyName))
return showBookmarkHighlights && bookmarkWidget?.bookmarks
? bookmarkWidget.bookmarks
.filter(value => set.has(value.assemblyName))
.map(r => {
const asm = assemblyManager.get(r.assemblyName)
const refName = asm?.getCanonicalRefName(r.refName) ?? r.refName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const OverviewHighlight = observer(function OverviewHighlight({
}, [session, bookmarkWidget])

const assemblyNames = new Set(model.assemblyNames)
return showBookmarkHighlights
? bookmarkWidget?.bookmarks
return showBookmarkHighlights && bookmarkWidget?.bookmarks
? bookmarkWidget.bookmarks
.filter(r => assemblyNames.has(r.assemblyName))
.map(r => {
const asm = assemblyManager.get(r.assemblyName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,13 @@ const Highlight = observer(function Highlight({
const [open, setOpen] = useState(false)
const anchorEl = useRef(null)
const color = useTheme().palette.highlight?.main ?? 'goldenrod'

const session = getSession(model) as SessionWithWidgets
const { assemblyManager } = session

const dismissHighlight = () => {
model.removeHighlight(highlight)
}

const menuItems = [
{
label: 'Dismiss highlight',
icon: CloseIcon,
onClick: () => dismissHighlight(),
},
{
label: 'Bookmark highlighted region',
icon: BookmarkIcon,
onClick: () => {
let bookmarkWidget = session.widgets.get('GridBookmark')
if (!bookmarkWidget) {
bookmarkWidget = session.addWidget(
'GridBookmarkWidget',
'GridBookmark',
)
}
// @ts-ignore
bookmarkWidget.addBookmark(highlight as Region)
dismissHighlight()
},
},
]

function handleClose() {
setOpen(false)
}
Expand Down Expand Up @@ -134,7 +109,29 @@ const Highlight = observer(function Highlight({
}}
open={open}
onClose={handleClose}
menuItems={menuItems}
menuItems={[
{
label: 'Dismiss highlight',
icon: CloseIcon,
onClick: () => dismissHighlight(),
},
{
label: 'Bookmark highlighted region',
icon: BookmarkIcon,
onClick: () => {
let bookmarkWidget = session.widgets.get('GridBookmark')
if (!bookmarkWidget) {
bookmarkWidget = session.addWidget(
'GridBookmarkWidget',
'GridBookmark',
)
}
// @ts-ignore
bookmarkWidget.addBookmark(highlight as Region)
dismissHighlight()
},
},
]}
/>
</div>
) : null
Expand Down

0 comments on commit c98e002

Please sign in to comment.