@@ -20,6 +20,7 @@ const MAX_FIXED_SYNONYMS = 5;
2020const  MAX_SYNONYMS_SHOWN  =  10 ; 
2121
2222let  associationCache  =  new  WeakMap ( ) ; 
23+ let  chosenTypeCache  =  new  WeakMap ( ) ; 
2324let  nameNotificationCache  =  new  SingleValueCache ( ) ; 
2425let  assocNotificationCache  =  new  SingleValueCache ( ) ; 
2526
@@ -35,6 +36,8 @@ class EntityInfo extends DataComponent {
3536
3637    let  assocNotification  =  initCache (  assocNotificationCache ,  el ,  new  Notification ( {  active : true  } )  ) ; 
3738
39+     let  chosenType  =  initCache (  chosenTypeCache ,  el ,  null  ) ; 
40+ 
3841    this . debouncedUpdateMatches  =  _ . debounce (  ( name ,  postStep  =  _ . nop )  =>  { 
3942      this . updateMatches ( name ) . then ( postStep ) ; 
4043    } ,  defs . updateDelay  ) ; 
@@ -53,6 +56,7 @@ class EntityInfo extends DataComponent {
5356    this . data  =  { 
5457      element : el , 
5558      name : el . name ( ) , 
59+       chosenType, 
5660      oldName : el . name ( ) , 
5761      matches : assoc . matches , 
5862      gettingMoreMatches : false , 
@@ -131,6 +135,14 @@ class EntityInfo extends DataComponent {
131135    let  s  =  this . data ; 
132136    let  el  =  s . element ; 
133137
138+     if (  s . chosenType  &&  match . type  !==  'chemical'  ) { 
139+       match  =  Object . assign ( { } ,  match ,  { 
140+         type : s . chosenType 
141+       } ) ; 
142+ 
143+       delete  match . typeOfGene ;  // n.b. the model overrides via this field 
144+     } 
145+ 
134146    el . associate (  match  ) ; 
135147    el . complete ( ) ; 
136148
@@ -398,11 +410,15 @@ class EntityInfo extends DataComponent {
398410              name : 'entity-info-subtype-radio' , 
399411              id : `entity-info-subtype-radio-${ typeVal }  , 
400412              value : typeVal , 
401-               defaultChecked : typeVal  ===  m . type , 
413+               checked : typeVal  ===  m . type , 
402414              onChange : e  =>  { 
403415                let  newlySelectedType  =  e . target . value ; 
404416                let  newMatch  =  Object . assign ( { } ,  m ,  {  type : newlySelectedType  } ) ; 
405417
418+                 this . setData ( {  chosenType : newlySelectedType  } ) ; 
419+ 
420+                 chosenTypeCache . set ( s . element ,  newlySelectedType ) ; 
421+ 
406422                this . associate ( newMatch ) ; 
407423              } 
408424            } ) , 
@@ -434,8 +450,6 @@ class EntityInfo extends DataComponent {
434450        let  isOrgMatch  =  m  =>  isPerfectNameMatch ( m )  &&  ! isChemicalMatch ( m ) ; 
435451        let  orgMatches  =  s . matches . filter ( isOrgMatch ) ; 
436452        let  orgToMatches  =  new  Map ( ) ; 
437-         const  selectedIndex  =  _ . findIndex ( orgMatches ,  match  =>  match . id  ===  m . id  &&  match . namespace  ===  m . namespace ) ; 
438-         const  selectedOrg  =  assoc  ? assoc . organism  : null ; 
439453
440454        orgMatches . forEach ( om  =>  { 
441455          let  org  =  om . organism ; 
@@ -451,6 +465,11 @@ class EntityInfo extends DataComponent {
451465          arr . push ( om ) ; 
452466        } ) ; 
453467
468+         orgMatches  =  _ . sortBy ( orgMatches ,  m  =>  m . organismName ) ; 
469+ 
470+         const  selectedIndex  =  _ . findIndex ( orgMatches ,  match  =>  match . id  ===  m . id  &&  match . namespace  ===  m . namespace ) ; 
471+         const  selectedOrg  =  assoc  ? assoc . organism  : null ; 
472+ 
454473        const  getSelectDisplay  =  ( om ,  includeName  =  false )  =>  { 
455474          // const matches = orgToMatches.get(om.organism) || []; 
456475          // let count = matches.length; 
@@ -463,7 +482,9 @@ class EntityInfo extends DataComponent {
463482        } ; 
464483
465484        const  getDisamtDisplay  =  ( om )  =>  { 
466-           return  `${ om . name }   +  om . synonyms . slice ( 0 ,  3 ) . join ( ', ' ) ; 
485+           const  sortedSyns  =  _ . sortBy ( om . synonyms ,  syn  =>  stringDistanceMetric ( syn ,  s . name ) ) ; 
486+ 
487+           return  `${ om . name }   +  sortedSyns . slice ( 0 ,  3 ) . join ( ', ' ) ; 
467488        } ; 
468489
469490        organism  =  h ( 'div.entity-info-section.entity-info-organism-refinement' ,  [ 
@@ -503,14 +524,16 @@ class EntityInfo extends DataComponent {
503524          const  needDisam  =  ambigGrs  &&  ambigGrs . length  >  1 ; 
504525
505526          if (  needDisam  ) { 
527+             const  selectedAmIndex  =  _ . findIndex ( ambigGrs ,  match  =>  match . id  ===  m . id  &&  match . namespace  ===  m . namespace ) ; 
528+ 
506529            disambiguation  =  h ( 'div.entity-info-section.entity-info-organism-refinement' ,  [ 
507530              h ( 'span.entity-info-title' ,  'Which'  +  ( s . name  ? ` ${ s . name }   : '' )  +  '' ) , 
508531              h ( 'select.entity-info-organism-dropdown' ,  { 
509-                 defaultValue : selectedIndex , 
532+                 defaultValue : selectedAmIndex , 
510533                onChange : e  =>  { 
511534                  const  val  =  e . target . value ; 
512535                  const  index  =  parseInt ( val ) ; 
513-                   const  om  =  orgMatches [ index ] ; 
536+                   const  om  =  ambigGrs [ index ] ; 
514537
515538                  if (  om  ) { 
516539                    this . associate ( om ) ; 
0 commit comments