GMOD / Apollo3

JBrowse 2 plugin for editing annotations on an Apollo server
Apache License 2.0
7 stars 4 forks source link

Provide feedback that an ontology is being loaded #457

Open garrettjstevens opened 2 months ago

garrettjstevens commented 2 months ago

Use the jobsManager in the (Apollo) session to update that an ontology is loading.

We'll have to pass something into the OntologyManager to call updates with, like an update callback. We can then use that callback to adapt to the jobsManager. e.g. something like this:

--- a/packages/jbrowse-plugin-apollo/src/OntologyManager/OntologyStore/index.ts
+++ b/packages/jbrowse-plugin-apollo/src/OntologyManager/OntologyStore/index.ts
@@ -71,6 +71,7 @@ export interface OntologyStoreOptions {
     indexFields?: { displayName: string; jsonPath: string }[]
   }
   maxSearchResults?: number
+  update?(message: string, progress: number): void
 }

 export interface PropertiesOptions {
@@ -110,8 +111,8 @@ export default class OntologyStore {
     this.ontologyName = name
     this.ontologyVersion = version
     this.sourceLocation = source
-    this.db = this.prepareDatabase()
     this.options = options ?? {}
+    this.db = this.prepareDatabase()
   }

   /**
@@ -176,8 +177,12 @@ export default class OntologyStore {
       return db
     }

-    const { sourceLocation, sourceType } = this
+    const { options, sourceLocation, sourceType } = this
     if (sourceType === 'obo-graph-json') {
+      if (options.update) {
+        options.update('Importing', 0)
+      }
+      // add more updates inside `loadOboGraphJson`
       await this.loadOboGraphJson(db)
     } else {
       throw new Error(
--- a/packages/jbrowse-plugin-apollo/src/session/ClientDataStore.ts
+++ b/packages/jbrowse-plugin-apollo/src/session/ClientDataStore.ts
@@ -42,6 +42,7 @@ import {
 } from '../OntologyManager'
 import { ApolloRootModel } from '../types'
 import { autorun } from 'mobx'
+import { ApolloSessionModel } from './session'

 export function clientDataStoreFactory(
   AnnotationFeatureExtended: typeof AnnotationFeatureModel,
@@ -164,8 +165,15 @@ export function clientDataStoreFactory(
                 ) as TextIndexFieldDefinition[],
               ]
               if (!ontologyManager.findOntology(name)) {
+                const session = getSession(
+                  self,
+                ) as unknown as ApolloSessionModel
+                const { jobsManager } = session
+                function update(message: string, progress: Number) {
+                  // adapt `update` to what `jobsManager` expets
+                }
                 ontologyManager.addOntology(name, version, source, {
-                  textIndexing: { indexFields },
+                  textIndexing: { indexFields }, update,
                 })
               }
             }

You can see an example of how jobsManager is used in packages/jbrowse-plugin-apollo/src/components/ImportFeatures.tsx.

dariober commented 5 days ago

See PR here.