Skip to content

Commit

Permalink
Add error handler to the base feature detail preparation
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Apr 13, 2023
1 parent 0e8bff2 commit cdf350f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
5 changes: 4 additions & 1 deletion packages/core/BaseFeatureWidget/BaseFeatureDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,11 @@ export function FeatureDetails(props: {
}

export default observer(function ({ model }: BaseInputProps) {
const { featureData } = model
const { error, featureData } = model

if (error) {
return <ErrorMessage error={error} />
}
if (!featureData) {
return null
}
Expand Down
53 changes: 32 additions & 21 deletions packages/core/BaseFeatureWidget/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export default function stateModelFactory(pluginManager: PluginManager) {
trackId: types.maybe(types.string),
trackType: types.maybe(types.string),
})
.volatile(() => ({
error: undefined as unknown,
}))
.actions(self => ({
setFeatureData(featureData: Record<string, unknown>) {
self.unformattedFeatureData = featureData
Expand All @@ -62,37 +65,45 @@ export default function stateModelFactory(pluginManager: PluginManager) {
self.trackId = trackId
self.trackType = type
},
setError(e: unknown) {
self.error = e
},
}))
.actions(self => ({
afterCreate() {
addDisposer(
self,
autorun(() => {
self.setExtra(self.track?.type, self.track?.configuration.trackId)
const { unformattedFeatureData, track } = self
const session = getSession(self)
if (unformattedFeatureData) {
const feature = clone(unformattedFeatureData)
try {
self.setExtra(self.track?.type, self.track?.configuration.trackId)
const { unformattedFeatureData, track } = self
const session = getSession(self)
if (unformattedFeatureData) {
const feature = clone(unformattedFeatureData)

const combine = (
arg2: string,
feature: Record<string, unknown>,
) => ({
...getConf(session, ['formatDetails', arg2], { feature }),
...getConf(track, ['formatDetails', arg2], { feature }),
})
const combine = (
arg2: string,
feature: Record<string, unknown>,
) => ({
...getConf(session, ['formatDetails', arg2], { feature }),
...getConf(track, ['formatDetails', arg2], { feature }),
})

if (track) {
// eslint-disable-next-line no-underscore-dangle
feature.__jbrowsefmt = combine('feature', feature)
const depth = getConf(track, ['formatDetails', 'depth'])
formatSubfeatures(feature, depth, sub => {
if (track) {
// eslint-disable-next-line no-underscore-dangle
sub.__jbrowsefmt = combine('subfeatures', sub)
})
}
feature.__jbrowsefmt = combine('feature', feature)
const depth = getConf(track, ['formatDetails', 'depth'])
formatSubfeatures(feature, depth, sub => {
// eslint-disable-next-line no-underscore-dangle
sub.__jbrowsefmt = combine('subfeatures', sub)
})
}

self.setFormattedData(feature)
self.setFormattedData(feature)
}
} catch (e) {
console.error(e)
self.setError(e)
}
}),
)
Expand Down
2 changes: 2 additions & 0 deletions products/jbrowse-web/src/tests/util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ export async function doSetupForImportForm(val?: unknown) {
)
const input = (await findByPlaceholderText(
'Search for location',
{},
{ timeout: 10000 },
)) as HTMLInputElement

// this will be the input that is obtained after opening the LGV from the import form
Expand Down

0 comments on commit cdf350f

Please sign in to comment.