Skip to content

Commit

Permalink
[ImageViewer] fixed restore state for rerocessed datasets (#1473)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmacielvieira authored Feb 6, 2024
1 parent 6cd8b4e commit a3babad
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions metaspace/webapp/src/modules/ImageViewer/useRestoredState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { restoreIonImageState } from './ionImageState'
import store from '../../store'
import { annotationDetailItemFragment } from '../../api/annotation'
import router from '../../router'
import { isEqual } from 'lodash-es'
import Vue from 'vue'

export default async($apollo: any, id: string, datasetId: string) => {
try {
Expand Down Expand Up @@ -47,7 +49,8 @@ export default async($apollo: any, id: string, datasetId: string) => {
})
}

store.commit('setSnapshotAnnotationIds', annotations.map((annotation: any) => annotation.id))
const annotationIds = annotations.map((annotation: any) => annotation.id).sort()
store.commit('setSnapshotAnnotationIds', annotationIds)

// set snapshot filters
if (parsed.filter) {
Expand Down Expand Up @@ -82,13 +85,24 @@ export default async($apollo: any, id: string, datasetId: string) => {
window.location.reload()
}

if (annotations.length > 0) {
store.commit('setAnnotation', annotations[0])
} else {
store.commit('setAnnotation', {
status: 'reprocessed_snapshot',
annotationIons: parsed.annotationIons,
const restoreState = isEqual(annotationIds,
(parsed.ionImage?.layers || []).map((layer: any) => layer.id).sort())

// multiple annotations reprocessed, so saved layers based on id do not match
if (!restoreState || annotations.length === 0) {
Vue.nextTick(async() => { // wait for rendering and time before update viewer
const MILISECONDS = 1000
await new Promise(resolve => setTimeout(resolve, MILISECONDS))
store.commit('setAnnotation', {
status: 'reprocessed_snapshot',
annotationIons: parsed.annotationIons,
})
})
return
}

if (Array.isArray(annotations)) {
store.commit('setAnnotation', annotations[0])
}

restoreImageViewerState({
Expand Down

0 comments on commit a3babad

Please sign in to comment.