@@ -33,12 +33,14 @@ import SaveModal from './components/SaveModal'
3333import { isBirthdateValid } from './services/validation'
3434import { uploadAnimalData } from './api/updateAnimalData'
3535import { getReportPath } from './services/printToPDF'
36+ import { isNonPrimate } from './services/utils'
3637
3738export default class NewAnimalPage extends React . Component {
3839 state = new NewAnimalState ( ) ;
3940debug = constants . debug ;
4041numPanels = constants . numPanels ;
4142selectedSpecies = undefined ;
43+
4244componentDidMount ( ) {
4345 // prevent user from navigating away from page
4446 window . addEventListener ( 'beforeunload' , this . beforeunload . bind ( this ) )
@@ -105,11 +107,11 @@ loadLists() {
105107 }
106108loadListsForSpecies = selectedSpecies => {
107109 const lists = { }
108-
110+ const newAssignments = this . state . numAnimals || 1
109111 async function loadListsAW ( species ) {
110112 lists . locationList = await fetchLocations ( species )
111113 lists . colonyList = await fetchColonies ( species )
112- lists . iacucList = await fetchProtocols ( species )
114+ lists . iacucList = await fetchProtocols ( species , newAssignments )
113115 lists . pedigreeList = await fetchPedigrees ( species )
114116 }
115117
@@ -131,8 +133,34 @@ loadListsForSpecies = selectedSpecies => {
131133 } ) )
132134 } )
133135 } ;
136+
137+ loadIacucList = ( species , newAssignments ) => {
138+ const lists = { }
139+
140+ async function loadListsAW ( species , newAssignments ) {
141+ lists . iacucList = await fetchProtocols ( species , newAssignments )
142+ }
143+
144+ loadListsAW ( species , newAssignments )
145+ . then ( ( ) => {
146+ this . setState ( prevState => ( {
147+ ...prevState ,
148+ iacucList : lists . iacucList
149+ } ) )
150+ } )
151+ . catch ( error => {
152+ console . log ( `Error in loadIacucList: ${ error } ` )
153+ this . setState ( prevState => ( {
154+ ...prevState ,
155+ errorMessage : error . message ,
156+ } ) )
157+ } )
158+ } ;
159+
134160disablePanels = ( ) => ! ( this . state . locationList && this . state . locationList . length > 0 ) ;
161+
135162disableFirstPanel = ( ) => ! this . state . selectedOption || ! this . state . newAnimalData . species ;
163+
136164handleAcquisitionOptionChange = type => {
137165 fetchAcquisitionTypes ( type )
138166 . then ( response => this . setState ( prevState => ( {
@@ -151,38 +179,48 @@ handleAcquisitionOptionChange = type => {
151179 console . log ( error )
152180 } )
153181 } ;
154- handleSpeciesChange = selectedSpecies => {
182+ handleSpeciesChange = selectedSpecies => {
155183 // ignore sub-species change
156184 if (
157185 this . state . newAnimalData . species !== undefined
158- && this . state . newAnimalData . species . arcSpeciesCode
159- !== selectedSpecies . arcSpeciesCode
186+ && this . state . newAnimalData . species . arcSpeciesCode !== selectedSpecies . arcSpeciesCode
160187 ) {
161188 this . selectedSpecies = selectedSpecies
162189 this . setState ( prevState => ( {
163190 ...prevState ,
164191 showSpeciesChangeModal : true ,
165192 } ) )
166193 } else {
194+ let nonPrimate = isNonPrimate ( selectedSpecies )
167195 this . setState ( prevState => ( {
168196 ...prevState ,
169197 isDirty : true ,
170198 newAnimalData : {
171199 ...prevState . newAnimalData ,
172200 species : selectedSpecies ,
201+ isNonPrimate : nonPrimate ,
173202 } ,
174203 } ) )
175204 this . loadListsForSpecies ( selectedSpecies )
176205 }
177206 } ;
178207handleNumAnimalChange = value => {
179- this . setState (
208+ const newAssignments = this . state . numAnimals || 1
209+ const species = this . state . newAnimalData . species . arcSpeciesCode
210+
211+ this . setState (
180212 prevState => ( {
181213 ...prevState ,
182214 numAnimals : value
183215 } )
184216 )
217+
218+ // see if the protocol list needs to be reloaded
219+ if ( value != newAssignments ) {
220+ this . loadIacucList ( species , value )
185221 }
222+ }
223+
186224handleDataChange = ( property , value ) => {
187225 this . setState (
188226 prevState => ( {
@@ -385,6 +423,7 @@ handleSaveReset = () => {
385423 } ;
386424onSpeciesChangeClick = ( ) => {
387425 const initialState = new NewAnimalState ( )
426+ let nonPrimate = isNonPrimate ( this . selectedSpecies )
388427 this . setState (
389428 prevState => ( {
390429 ...initialState ,
@@ -402,6 +441,7 @@ onSpeciesChangeClick = () => {
402441 ...initialState . newAnimalData ,
403442 species : this . selectedSpecies ,
404443 selectedOption : prevState . newAnimalData . selectedOption ,
444+ isNonPrimate : nonPrimate
405445 } ,
406446 } ) ,
407447 this . loadListsForSpecies ( this . selectedSpecies )
0 commit comments