From ded56df9fc54abe0cf34047f7e891a9ded690565 Mon Sep 17 00:00:00 2001 From: moririn2528 Date: Mon, 11 Sep 2023 15:35:04 +0900 Subject: [PATCH] split component --- .../ts/components/PreferentialTrials.tsx | 377 +++++++++--------- 1 file changed, 196 insertions(+), 181 deletions(-) diff --git a/optuna_dashboard/ts/components/PreferentialTrials.tsx b/optuna_dashboard/ts/components/PreferentialTrials.tsx index b7805259..b1ba6b2c 100644 --- a/optuna_dashboard/ts/components/PreferentialTrials.tsx +++ b/optuna_dashboard/ts/components/PreferentialTrials.tsx @@ -163,14 +163,12 @@ const SettingsPage: FC<{ ) } -const FeedbackContent: FC<{ +const OutputContent: FC<{ trial: Trial artifact?: Artifact componentId: FeedbackComponentType - width: string - minHeight: string urlPath: string -}> = ({ trial, artifact, componentId, width, minHeight, urlPath }) => { +}> = ({ trial, artifact, componentId, urlPath }) => { if (componentId === "Note") { return } @@ -186,6 +184,191 @@ const FeedbackContent: FC<{ return null } +const PreferentialTrial: FC<{ + trial?: Trial + studyDetail: StudyDetail + candidates: number[] + hideTrial: () => void + openDetailTrial: () => void + openThreejsArtifactModal: (urlPath: string, artifact: Artifact) => void +}> = ({ + trial, + studyDetail, + candidates, + hideTrial, + openDetailTrial, + openThreejsArtifactModal, +}) => { + const theme = useTheme() + const action = actionCreator() + const [buttonHover, setButtonHover] = useState(false) + const trialWidth = 400 + const trialHeight = 300 + const componentId = studyDetail.feedback_component_type ?? "Note" + const artifactKey = studyDetail.feedback_artifact_key + const artifactId = trial?.user_attrs.find((a) => a.key === artifactKey)?.value + const artifact = trial?.artifacts.find((a) => a.artifact_id === artifactId) + const urlPath = `/artifacts/${studyDetail.id}/${trial?.trial_id}/${artifact?.artifact_id}` + const is3dModel = + componentId === "Artifact" && + artifact !== undefined && + isThreejsArtifact(artifact) + + if (trial === undefined) { + return ( + + ) + } + + const onFeedback = () => { + hideTrial() + action.updatePreference(trial.study_id, candidates, trial.number) + } + + return ( + + + + Trial {trial.number} + {componentId === "Artifact" && artifact !== undefined ? ( + + {`(${artifact.filename})`} + + ) : null} + + {is3dModel ? ( + { + openThreejsArtifactModal(urlPath, artifact) + }} + > + + + ) : null} + { + hideTrial() + action.skipPreferentialTrial(trial.study_id, trial.trial_id) + }} + aria-label="skip trial" + > + + + + + + + { + if (e.shiftKey) onFeedback() + }} + sx={{ + position: "relative", + padding: theme.spacing(2), + overflow: "hidden", + minHeight: theme.spacing(20), + }} + > + + + + + + + ) +} + type DisplayTrials = { numbers: number[] last_number: number @@ -195,7 +378,6 @@ export const PreferentialTrials: FC<{ studyDetail: StudyDetail | null }> = ({ studyDetail, }) => { const theme = useTheme() - const action = actionCreator() const [openThreejsArtifactModal, renderThreejsArtifactModal] = useThreejsArtifactModal() const runningTrials = @@ -208,10 +390,6 @@ export const PreferentialTrials: FC<{ studyDetail: StudyDetail | null }> = ({ }) const [settingShown, setSettingShown] = useState(false) const [detailTrial, setDetailTrial] = useState(null) - const [buttonHover, setButtonHover] = useState(null) - - const trialWidth = 400 - const trialHeight = 300 if (studyDetail === null || !studyDetail.is_preferential) { return null @@ -285,179 +463,16 @@ export const PreferentialTrials: FC<{ studyDetail: StudyDetail | null }> = ({ {displayTrials.numbers.map((t, index) => { const trial = activeTrials.find((trial) => trial.number === t) const candidates = displayTrials.numbers.filter((n) => n !== -1) - const componentId = studyDetail.feedback_component_type ?? "Note" - const artifactKey = studyDetail.feedback_artifact_key - const artifactId = trial?.user_attrs.find( - (a) => a.key === artifactKey - )?.value - const artifact = trial?.artifacts.find( - (a) => a.artifact_id === artifactId - ) - const urlPath = `/artifacts/${studyDetail.id}/${trial?.trial_id}/${artifact?.artifact_id}` - - if (trial == undefined) { - return ( - - ) - } - - const is3dModel = - componentId === "Artifact" && - artifact !== undefined && - isThreejsArtifact(artifact) - const onFeedback = () => { - hideTrial(trial.number) - action.updatePreference(trial.study_id, candidates, trial.number) - } - return ( - - - - Trial {trial.number} - {componentId === "Artifact" && artifact !== undefined ? ( - - {`(${artifact.filename})`} - - ) : null} - - {is3dModel ? ( - { - openThreejsArtifactModal(urlPath, artifact) - }} - > - - - ) : null} - { - hideTrial(trial.number) - action.skipPreferentialTrial(trial.study_id, trial.trial_id) - }} - aria-label="skip trial" - > - - - setDetailTrial(trial.number)} - aria-label="show detail" - > - - - - { - if (e.shiftKey) onFeedback() - }} - sx={{ - position: "relative", - padding: theme.spacing(2), - overflow: "hidden", - minHeight: theme.spacing(20), - }} - > - - - - - - + hideTrial(t)} + openDetailTrial={() => setDetailTrial(t)} + openThreejsArtifactModal={openThreejsArtifactModal} + /> ) })}