Skip to content

Commit

Permalink
Global notifyError
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Mar 12, 2024
1 parent 965de76 commit 28c3efd
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 26 deletions.
6 changes: 3 additions & 3 deletions packages/core/ui/ErrorMessageStackTraceDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ function stripMessage(trace: string, error: unknown) {
}
}

function Contents({ text, extra }: { text: string; extra: unknown }) {
function Contents({ text, extra }: { text: string; extra?: unknown }) {
const err = encodeURIComponent(
[
'I got this error from JBrowse, here is the stack trace:\n',
'```',
text,
'```',
`supporting data: ${extra}`,
extra ? `supporting data: ${extra}` : '',
].join('\n') + '\n',
)
const githubLink = `https://github.com/GMOD/jbrowse-components/issues/new?labels=bug&title=JBrowse+issue&body=${err}`
Expand Down Expand Up @@ -160,7 +160,7 @@ export default function ErrorMessageStackTraceDialog({
}: {
onClose: () => void
error: unknown
extra: unknown
extra?: unknown
}) {
const [mappedStackTrace, setMappedStackTrace] = useState<string>()
const [secondaryError, setSecondaryError] = useState<unknown>()
Expand Down
12 changes: 8 additions & 4 deletions packages/core/ui/SnackbarModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IObservableArray, observable } from 'mobx'
import { NotificationLevel, SnackAction } from '../util/types'
// icons
import Report from '@mui/icons-material/Report'
import { getSession } from '../util'

Check warning on line 8 in packages/core/ui/SnackbarModel.tsx

View workflow job for this annotation

GitHub Actions / Lint on node 20 and ubuntu-latest

'getSession' is defined but never used

// lazies
const ErrorMessageStackTraceDialog = lazy(

Check warning on line 11 in packages/core/ui/SnackbarModel.tsx

View workflow job for this annotation

GitHub Actions / Lint on node 20 and ubuntu-latest

Fast refresh only works when a file only exports components. Move your component(s) to a separate file
Expand All @@ -21,7 +22,11 @@ export interface SnackbarMessage {
* #stateModel SnackbarModel
* #category session
*/
function makeExtension(snackbarMessages: IObservableArray<SnackbarMessage>) {
function makeExtension(
snackbarMessages: IObservableArray<SnackbarMessage>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
self: any,
) {
return {
views: {
/**
Expand All @@ -47,7 +52,6 @@ function makeExtension(snackbarMessages: IObservableArray<SnackbarMessage>) {
this.notify(errorMessage, 'error', {
name: <Report />,
onClick: () => {
// @ts-expect-error
self.queueDialog((onClose: () => void) => [
ErrorMessageStackTraceDialog,
{
Expand Down Expand Up @@ -99,9 +103,9 @@ export default function addSnackbarToModel<
ReturnType<typeof makeExtension>['actions'] &
ReturnType<typeof makeExtension>['views']
> {
return tree.extend(() => {
return tree.extend(self => {
const snackbarMessages = observable.array<SnackbarMessage>()

return makeExtension(snackbarMessages)
return makeExtension(snackbarMessages, self)
})
}
1 change: 1 addition & 0 deletions packages/core/util/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export interface AbstractSessionModel extends AbstractViewContainer {
level?: NotificationLevel,
action?: SnackAction,
) => void
notifyError: (message: string, error?: unknown, extra?: unknown) => void
assemblyManager: AssemblyManager
version: string
getTrackActionMenuItems?: Function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,6 @@ export function onClick(feature: Feature, self: LinearPileupDisplayModel) {
})
} catch (e) {
console.error(e)
session.notify(`${e}`, 'error')
session.notifyError(`${e}`, e)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const BookmarkGrid = observer(function ({
model.updateBookmarkLabel(target, row.label)
return row
}}
onProcessRowUpdateError={e => session.notify(e.message, 'error')}
onProcessRowUpdateError={e => session.notifyError(`${e}`, e)}
checkboxSelection
onRowSelectionModelChange={newRowSelectionModel => {
if (bookmarksWithValidAssemblies.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/grid-bookmark/src/GridBookmarkWidget/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function navToBookmark(
await view.navToLocString(locString, assembly)
} catch (e) {
console.error(e)
session.notify(`${e}`, 'error')
session.notifyError(`${e}`, e)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default (pluginManager: PluginManager) => {
)
}
} catch (e) {
session.notify(`${e}`, 'error')
session.notifyError(`${e}`, e)
throw e
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ const RefNameAutocomplete = observer(function ({
const { coarseVisibleLocStrings, hasDisplayedRegions } = model

useEffect(() => {
let active = true

// eslint-disable-next-line @typescript-eslint/no-floating-promises
;(async () => {
try {
Expand All @@ -59,21 +57,13 @@ const RefNameAutocomplete = observer(function ({

setLoaded(false)
const results = await fetchResults(debouncedSearch)
if (active) {
setLoaded(true)
setSearchOptions(getDeduplicatedResult(results))
}
setLoaded(true)
setSearchOptions(getDeduplicatedResult(results))
} catch (e) {
console.error(e)
if (active) {
session.notify(`${e}`, 'error')
}
session.notifyError(`${e}`, e)
}
})()

return () => {
active = false
}
}, [assemblyName, fetchResults, debouncedSearch, session, model])

const inputBoxVal = coarseVisibleLocStrings || value || ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default function SearchResultsTable({
}
} catch (e) {
console.error(e)
session.notify(`${e}`, 'error')
session.notifyError(`${e}`, e)
}
handleClose()
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default function createViewState(opts: ViewStateOptions) {
assembly.name,
)
} catch (e) {
session.notify(`${e}`, 'error')
session.notifyError(`${e}`, e)
}
})()
}
Expand Down

0 comments on commit 28c3efd

Please sign in to comment.