Merge pull request #407 from keisuke-umezawa/feature/make-separated-api-for-tell

Separate tell api into complete api and fail api
This commit is contained in:
Masashi Shibata
2023-03-06 17:01:17 +09:00
committed by GitHub
3 changed files with 44 additions and 17 deletions
+40 -13
View File
@@ -444,17 +444,9 @@ export const actionCreator = () => {
})
}
const tellTrial = (
studyId: number,
trialId: number,
state: TrialStateFinished,
values?: number[]
): void => {
const message =
values === undefined
? `id=${trialId}, state=${state}`
: `id=${trialId}, state=${state}, values=${values}`
tellTrialAPI(trialId, state, values)
const makeTrialFail = (studyId: number, trialId: number): void => {
const message = `id=${trialId}, state=Fail`
tellTrialAPI(trialId, "Fail")
.then(() => {
const index = studyDetails[studyId].trials.findIndex(
(t) => t.trial_id === trialId
@@ -465,7 +457,41 @@ export const actionCreator = () => {
})
return
}
setTrialStateValues(studyId, index, state, values)
setTrialStateValues(studyId, index, "Fail")
enqueueSnackbar(`Successfully updated trial (${message})`, {
variant: "success",
})
})
.catch((err) => {
const reason = err.response?.data.reason
enqueueSnackbar(
`Failed to update trial (${message}). Reason: ${reason}`,
{
variant: "error",
}
)
console.log(err)
})
}
const makeTrialComplete = (
studyId: number,
trialId: number,
values: number[]
): void => {
const message = `id=${trialId}, state=Complete, values=${values}`
tellTrialAPI(trialId, "Complete", values)
.then(() => {
const index = studyDetails[studyId].trials.findIndex(
(t) => t.trial_id === trialId
)
if (index === -1) {
enqueueSnackbar(`Unexpected error happens. Please reload the page.`, {
variant: "error",
})
return
}
setTrialStateValues(studyId, index, "Complete", values)
enqueueSnackbar(`Successfully updated trial (${message})`, {
variant: "success",
})
@@ -498,7 +524,8 @@ export const actionCreator = () => {
saveTrialNote,
uploadArtifact,
deleteArtifact,
tellTrial,
makeTrialComplete,
makeTrialFail,
}
}
@@ -69,7 +69,7 @@ export const ObjectiveForm: FC<{
if (filtered.length !== directions.length) {
return
}
action.tellTrial(trial.study_id, trial.trial_id, "Complete", filtered)
action.makeTrialComplete(trial.study_id, trial.trial_id, filtered)
}
const getObjectiveName = (i: number): string => {
@@ -264,7 +264,7 @@ export const ObjectiveForm: FC<{
variant="outlined"
color="error"
onClick={() => {
action.tellTrial(trial.study_id, trial.trial_id, "Fail")
action.makeTrialFail(trial.study_id, trial.trial_id)
}}
>
Fail Trial
@@ -295,7 +295,7 @@ export const TrialTable: FC<{
return
}
action.tellTrial(studyId, trialId, "Complete", objectiveValues)
action.makeTrialComplete(studyId, trialId, objectiveValues)
}
const handleFailTrial = (e: MouseEvent<HTMLButtonElement>): void => {
@@ -304,7 +304,7 @@ export const TrialTable: FC<{
}
const studyId = studyDetail.id
const trialId = trials[index].trial_id
action.tellTrial(studyId, trialId, "Fail")
action.makeTrialFail(studyId, trialId)
}
return (