From aec4aa03208c38dc193d63eba0e0c5ac8282e1ea Mon Sep 17 00:00:00 2001 From: moririn2528 Date: Fri, 15 Sep 2023 18:03:17 +0900 Subject: [PATCH] fix by review --- optuna_dashboard/ts/action.ts | 44 ++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/optuna_dashboard/ts/action.ts b/optuna_dashboard/ts/action.ts index 5b66c58f..1e75a3dc 100644 --- a/optuna_dashboard/ts/action.ts +++ b/optuna_dashboard/ts/action.ts @@ -611,23 +611,39 @@ export const actionCreator = () => { }) } - const removePreferentialHistory = (studyId: number, historyUuid: string) => { - removePreferentialHistoryAPI(studyId, historyUuid).catch((err) => { - const reason = err.response?.data.reason - enqueueSnackbar(`Failed to switch history. Reason: ${reason}`, { - variant: "error", + const removePreferentialHistory = (studyId: number, historyId: string) => { + removePreferentialHistoryAPI(studyId, historyId) + .then(() => { + const newStudy = Object.assign({}, studyDetails[studyId]) + newStudy.preference_history = newStudy.preference_history?.map((h) => + h.id === historyId ? { ...h, is_removed: true } : h + ) + setStudyDetailState(studyId, newStudy) + }) + .catch((err) => { + const reason = err.response?.data.reason + enqueueSnackbar(`Failed to switch history. Reason: ${reason}`, { + variant: "error", + }) + console.log(err) }) - console.log(err) - }) } - const restorePreferentialHistory = (studyId: number, historyUuid: string) => { - restorePreferentialHistoryAPI(studyId, historyUuid).catch((err) => { - const reason = err.response?.data.reason - enqueueSnackbar(`Failed to switch history. Reason: ${reason}`, { - variant: "error", + const restorePreferentialHistory = (studyId: number, historyId: string) => { + restorePreferentialHistoryAPI(studyId, historyId) + .then(() => { + const newStudy = Object.assign({}, studyDetails[studyId]) + newStudy.preference_history = newStudy.preference_history?.map((h) => + h.id === historyId ? { ...h, is_removed: false } : h + ) + setStudyDetailState(studyId, newStudy) + }) + .catch((err) => { + const reason = err.response?.data.reason + enqueueSnackbar(`Failed to switch history. Reason: ${reason}`, { + variant: "error", + }) + console.log(err) }) - console.log(err) - }) } return {