@@ -5,6 +5,7 @@ import DatabasesTree from './databases_tree';
55import { Databases } from './databases' ;
66import _ from 'underscore' ;
77import { Options } from './options' ;
8+ import QueryStats from 'query_stats' ;
89
910/**
1011 * Search form.
@@ -16,15 +17,24 @@ export class Form extends Component {
1617 constructor ( props ) {
1718 super ( props ) ;
1819 this . state = {
19- databases : [ ] , preDefinedOpts : { } , tree : { }
20+ databases : [ ] ,
21+ preSelectedDbs : [ ] ,
22+ currentlySelectedDbs : [ ] ,
23+ preDefinedOpts : { } ,
24+ tree : { } ,
25+ residuesInQuerySequence : 0 ,
26+ blastMethod : ''
2027 } ;
2128 this . useTreeWidget = this . useTreeWidget . bind ( this ) ;
22- this . determineBlastMethod = this . determineBlastMethod . bind ( this ) ;
29+ this . determineBlastMethods = this . determineBlastMethods . bind ( this ) ;
2330 this . handleSequenceTypeChanged = this . handleSequenceTypeChanged . bind ( this ) ;
31+ this . handleSequenceChanged = this . handleSequenceChanged . bind ( this ) ;
2432 this . handleDatabaseTypeChanged = this . handleDatabaseTypeChanged . bind ( this ) ;
33+ this . handleDatabaseSelectionChanged = this . handleDatabaseSelectionChanged . bind ( this ) ;
2534 this . handleAlgoChanged = this . handleAlgoChanged . bind ( this ) ;
2635 this . handleFormSubmission = this . handleFormSubmission . bind ( this ) ;
2736 this . formRef = createRef ( ) ;
37+ this . setButtonState = this . setButtonState . bind ( this ) ;
2838 }
2939
3040 componentDidMount ( ) {
@@ -103,7 +113,7 @@ export class Form extends Component {
103113 } ) ;
104114 }
105115
106- determineBlastMethod ( ) {
116+ determineBlastMethods ( ) {
107117 var database_type = this . databaseType ;
108118 var sequence_type = this . sequenceType ;
109119
@@ -138,24 +148,34 @@ export class Form extends Component {
138148 return [ ] ;
139149 }
140150
151+ handleSequenceChanged ( residuesInQuerySequence ) {
152+ if ( residuesInQuerySequence !== this . state . residuesInQuerySequence )
153+ this . setState ( { residuesInQuerySequence : residuesInQuerySequence } ) ;
154+ }
155+
141156 handleSequenceTypeChanged ( type ) {
142157 this . sequenceType = type ;
143- this . refs . button . setState ( {
144- hasQuery : ! this . refs . query . isEmpty ( ) ,
145- hasDatabases : ! ! this . databaseType ,
146- methods : this . determineBlastMethod ( )
147- } ) ;
158+ this . setButtonState ( ) ;
148159 }
149160
150161 handleDatabaseTypeChanged ( type ) {
151162 this . databaseType = type ;
163+ this . setButtonState ( ) ;
164+ }
165+
166+ setButtonState ( ) {
152167 this . refs . button . setState ( {
153168 hasQuery : ! this . refs . query . isEmpty ( ) ,
154169 hasDatabases : ! ! this . databaseType ,
155- methods : this . determineBlastMethod ( )
170+ methods : this . determineBlastMethods ( )
156171 } ) ;
157172 }
158173
174+ handleDatabaseSelectionChanged ( selectedDbs ) {
175+ if ( ! _ . isEqual ( selectedDbs , this . state . currentlySelectedDbs ) )
176+ this . setState ( { currentlySelectedDbs : selectedDbs } ) ;
177+ }
178+
159179 handleAlgoChanged ( algo ) {
160180 if ( algo in this . state . preDefinedOpts ) {
161181 var preDefinedOpts = this . state . preDefinedOpts [ algo ] ;
@@ -165,12 +185,18 @@ export class Form extends Component {
165185 value : ( preDefinedOpts [ 'last search' ] ||
166186 preDefinedOpts [ 'default' ] ) . join ( ' ' )
167187 } ) ;
188+ this . setState ( { blastMethod : algo } ) ;
168189 }
169190 else {
170191 this . refs . opts . setState ( { preOpts : { } , value : '' , method : '' } ) ;
192+ this . setState ( { blastMethod : '' } ) ;
171193 }
172194 }
173195
196+ residuesInSelectedDbs ( ) {
197+ return this . state . currentlySelectedDbs . reduce ( ( sum , db ) => sum + parseInt ( db . ncharacters , 10 ) , 0 ) ;
198+ }
199+
174200 render ( ) {
175201 return (
176202 < div >
@@ -184,17 +210,19 @@ export class Form extends Component {
184210 </ div >
185211
186212 < form id = "blast" ref = { this . formRef } onSubmit = { this . handleFormSubmission } >
187- < SearchQueryWidget ref = "query" onSequenceTypeChanged = { this . handleSequenceTypeChanged } />
213+ < SearchQueryWidget ref = "query" onSequenceTypeChanged = { this . handleSequenceTypeChanged } onSequenceChanged = { this . handleSequenceChanged } />
188214
189215 { this . useTreeWidget ( ) ?
190216 < DatabasesTree ref = "databases"
191217 databases = { this . state . databases } tree = { this . state . tree }
192218 preSelectedDbs = { this . state . preSelectedDbs }
193- onDatabaseTypeChanged = { this . handleDatabaseTypeChanged } />
219+ onDatabaseTypeChanged = { this . handleDatabaseTypeChanged }
220+ onDatabaseSelectionChanged = { this . handleDatabaseSelectionChanged } />
194221 :
195222 < Databases ref = "databases" databases = { this . state . databases }
196223 preSelectedDbs = { this . state . preSelectedDbs }
197- onDatabaseTypeChanged = { this . handleDatabaseTypeChanged } />
224+ onDatabaseTypeChanged = { this . handleDatabaseTypeChanged }
225+ onDatabaseSelectionChanged = { this . handleDatabaseSelectionChanged } />
198226 }
199227
200228 < div className = "md:flex flex-row md:space-x-4 items-center my-6" >
@@ -204,6 +232,10 @@ export class Form extends Component {
204232 </ label >
205233 < SearchButton ref = "button" onAlgoChanged = { this . handleAlgoChanged } />
206234 </ div >
235+ < QueryStats
236+ residuesInQuerySequence = { this . state . residuesInQuerySequence } numberOfDatabasesSelected = { this . state . currentlySelectedDbs . length } residuesInSelectedDbs = { this . residuesInSelectedDbs ( ) }
237+ currentBlastMethod = { this . state . blastMethod }
238+ />
207239 </ form >
208240 </ div >
209241 ) ;
0 commit comments