diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8de605875..7c309ef78 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,7 @@ Version History v5.27.8 ------- +* Make constraints to save logs more robust ``_ * Rollback query to FinishedScript removed on a previous commit ``_ * Increase interval between audio alarms ``_ * Improve OLE behavior when jira ticket creation fails ``_ diff --git a/love/src/Utils.js b/love/src/Utils.js index 8413daedb..481e1cb19 100644 --- a/love/src/Utils.js +++ b/love/src/Utils.js @@ -869,6 +869,12 @@ export default class ManagerInterface { return resp; }); } + if (response.status === 404) { + return response.json().then((resp) => { + toast.error('Error adding log.'); + return resp; + }); + } return response.json().then((resp) => { toast.success('Log added succesfully.'); return resp; diff --git a/love/src/components/OLE/Exposure/ExposureAdd.jsx b/love/src/components/OLE/Exposure/ExposureAdd.jsx index 5827ac0c1..84b6a9c00 100644 --- a/love/src/components/OLE/Exposure/ExposureAdd.jsx +++ b/love/src/components/OLE/Exposure/ExposureAdd.jsx @@ -67,7 +67,7 @@ export default class ExposureAdd extends Component { timespan_end: undefined, }, newMessage: { - obs_id: undefined, + obs_id: [], instrument: undefined, message_text: undefined, level: 10, @@ -176,7 +176,7 @@ export default class ExposureAdd extends Component { } // Clean form only if the response is successful - if (!result.error) { + if (!result.error && !result.detail) { this.cleanForm(); } @@ -222,6 +222,17 @@ export default class ExposureAdd extends Component { this.saveMessage(); } + isSubmitDisabled() { + const { jiraIssueError, savingLog, newMessage, selectedInstrument } = this.state; + return ( + jiraIssueError || + savingLog || + newMessage.obs_id.length === 0 || + !selectedInstrument || + !newMessage.message_text?.trim() + ); + } + renderInstrumentsSelect() { const { instruments, selectedInstrument } = this.state; return ( @@ -370,6 +381,12 @@ export default class ExposureAdd extends Component { } componentDidUpdate(prevProps, prevState) { + if (this.state.selectedInstrument && prevState.selectedInstrument !== this.state.selectedInstrument) { + this.setState((state) => ({ + newMessage: { ...state.newMessage, instrument: state.selectedInstrument }, + })); + } + if ( prevState.selectedInstrument !== this.state.selectedInstrument || (this.state.selectedDayExposureStart && @@ -550,7 +567,9 @@ export default class ExposureAdd extends Component { }} onKeyCombination={(combination) => { if (combination === 'ctrl+enter') { - this.handleSubmit(); + if (!this.isSubmitDisabled()) { + this.handleSubmit(); + } } }} /> @@ -673,7 +692,7 @@ export default class ExposureAdd extends Component {
-