diff --git a/optuna_dashboard/ts/action.ts b/optuna_dashboard/ts/action.ts index c862eb9c..7ad3823d 100644 --- a/optuna_dashboard/ts/action.ts +++ b/optuna_dashboard/ts/action.ts @@ -272,7 +272,10 @@ export const actionCreator = () => { state: TrialState, values?: string[] ) => { - const message = values === undefined ? `id=${trialId}, state=${state}` : `id=${trialId}, state=${state}, values=${values}` + const message = + values === undefined + ? `id=${trialId}, state=${state}` + : `id=${trialId}, state=${state}, values=${values}` tellTrialAPI(studyId, trialId, state, values) .then(() => { enqueueSnackbar(`Success to update trial (${message})`, { @@ -281,9 +284,12 @@ export const actionCreator = () => { }) .catch((err) => { const reason = err.response?.data.reason - enqueueSnackbar(`Failed to update trial (${message}). Reason: ${reason}`, { - variant: "error", - }) + enqueueSnackbar( + `Failed to update trial (${message}). Reason: ${reason}`, + { + variant: "error", + } + ) console.log(err) }) } diff --git a/optuna_dashboard/ts/apiClient.ts b/optuna_dashboard/ts/apiClient.ts index f5ccf407..d5a76aab 100644 --- a/optuna_dashboard/ts/apiClient.ts +++ b/optuna_dashboard/ts/apiClient.ts @@ -223,7 +223,7 @@ export const tellTrialAPI = ( state: TrialState, values?: string[] ): Promise => { - const req: { [name: string]: TrialState | string[] } = {state: state} + const req: { [name: string]: TrialState | string[] } = { state: state } if (values !== undefined) { req["values"] = values } diff --git a/optuna_dashboard/ts/components/TrialTable.tsx b/optuna_dashboard/ts/components/TrialTable.tsx index 89275bb8..d28ce492 100644 --- a/optuna_dashboard/ts/components/TrialTable.tsx +++ b/optuna_dashboard/ts/components/TrialTable.tsx @@ -1,5 +1,12 @@ import React, { ChangeEvent, FC, FormEvent, MouseEvent, useState } from "react" -import { Typography, Grid, Box, Button, IconButton, TextField } from "@mui/material" +import { + Typography, + Grid, + Box, + Button, + IconButton, + TextField, +} from "@mui/material" import LinkIcon from "@mui/icons-material/Link" import { DataGridColumn, DataGrid } from "./DataGrid" @@ -7,10 +14,6 @@ import { Link } from "react-router-dom" import { actionCreator } from "../action" -interface objectiveValueFormInterface { - value: string -} - export const TrialTable: FC<{ studyDetail: StudyDetail | null isBeta: boolean @@ -269,24 +272,28 @@ export const TrialTable: FC<{ { field: "value", label: "Value", sortable: true }, ] - const collapseBody = (index: number) => { const objectiveValuesLength = studyDetail?.directions.length - const [objectiveValues, setObjectiveValues] = useState(Array(objectiveValuesLength).fill("")) + const [objectiveValues, setObjectiveValues] = useState( + Array(objectiveValuesLength).fill("") + ) const handleSubmit = (e: FormEvent): void => { e.preventDefault() const studyId = (studyDetail as StudyDetail).id const trialId = trials[index].number - action.tellTrial(studyId, trialId, "Complete" as TrialState, objectiveValues) + action.tellTrial( + studyId, + trialId, + "Complete" as TrialState, + objectiveValues + ) } - const handleChangeValue = (index: number, e: ChangeEvent): void => { - const newValues = objectiveValues.map((v, i) => { - if (i === index) { - return e.target.value - } else { - return v - } - }) + const handleChangeValue = ( + index: number, + e: ChangeEvent + ): void => { + const newValues = [...objectiveValues] + newValues[index] = e.target.value setObjectiveValues(newValues) } const handleFailTrial = (e: MouseEvent): void => { @@ -333,16 +340,25 @@ export const TrialTable: FC<{
{objectiveValues.map((value, i) => ( - handleChangeValue(i, e)} /> + ) => handleChangeValue(i, e)} + /> ))} - + + + +
-