From 804c2d54a3c918643ad0220bf8db5e9bd9aeeed3 Mon Sep 17 00:00:00 2001 From: keisuke-umezawa Date: Sun, 12 May 2024 14:12:03 +0900 Subject: [PATCH] Add modal to open csv file --- .../Artifact/StudyArtifactCards.tsx | 17 +++++ .../Artifact/TableArtifactViewer.tsx | 66 +++++++++++++++++-- 2 files changed, 79 insertions(+), 4 deletions(-) diff --git a/optuna_dashboard/ts/components/Artifact/StudyArtifactCards.tsx b/optuna_dashboard/ts/components/Artifact/StudyArtifactCards.tsx index fc749b5e..9fd12cf4 100644 --- a/optuna_dashboard/ts/components/Artifact/StudyArtifactCards.tsx +++ b/optuna_dashboard/ts/components/Artifact/StudyArtifactCards.tsx @@ -24,6 +24,7 @@ import { StudyDetail } from "ts/types/optuna" import { actionCreator } from "../../action" import { ArtifactCardMedia } from "./ArtifactCardMedia" import { useDeleteStudyArtifactDialog } from "./DeleteArtifactDialog" +import { isTableArtifact, useTableArtifactModal } from "./TableArtifactViewer" import { isThreejsArtifact, useThreejsArtifactModal, @@ -35,6 +36,8 @@ export const StudyArtifactCards: FC<{ study: StudyDetail }> = ({ study }) => { useDeleteStudyArtifactDialog() const [openThreejsArtifactModal, renderThreejsArtifactModal] = useThreejsArtifactModal() + const [openTableArtifactModal, renderTableArtifactModal] = + useTableArtifactModal() const width = "200px" const height = "150px" @@ -96,6 +99,19 @@ export const StudyArtifactCards: FC<{ study: StudyDetail }> = ({ study }) => { ) : null} + {isTableArtifact(artifact) ? ( + { + openTableArtifactModal(urlPath, artifact) + }} + > + + + ) : null} = ({ study }) => { {renderDeleteArtifactDialog()} {renderThreejsArtifactModal()} + {renderTableArtifactModal()} ) } diff --git a/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx b/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx index 744585e4..75037457 100644 --- a/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx +++ b/optuna_dashboard/ts/components/Artifact/TableArtifactViewer.tsx @@ -1,13 +1,14 @@ +import ClearIcon from "@mui/icons-material/Clear" +import { Box, Modal, useTheme } from "@mui/material" +import IconButton from "@mui/material/IconButton" import Papa from "papaparse" -import React, { useState, useEffect } from "react" +import React, { useState, useEffect, ReactNode } from "react" import { DataGrid } from "../DataGrid" import { Artifact } from "ts/types/optuna" export const isTableArtifact = (artifact: Artifact): boolean => { - return ( - artifact.filename.endsWith(".csv") || artifact.filename.endsWith(".jsonl") - ) + return artifact.filename.endsWith(".csv") } interface TableArtifactViewerProps { @@ -45,6 +46,63 @@ export const TableArtifactViewer: React.FC = ( return } +export const useTableArtifactModal = (): [ + (path: string, artifact: Artifact) => void, + () => ReactNode, +] => { + const [open, setOpen] = useState(false) + const [target, setTarget] = useState<[string, Artifact | null]>(["", null]) + const theme = useTheme() + + const openModal = (artifactUrlPath: string, artifact: Artifact) => { + setTarget([artifactUrlPath, artifact]) + setOpen(true) + } + + const renderDeleteStudyDialog = () => { + return ( + { + setOpen(false) + setTarget(["", null]) + }} + > + + { + setOpen(false) + setTarget(["", null]) + }} + > + + + + + + ) + } + return [openModal, renderDeleteStudyDialog] +} + const loadCSV = (props: TableArtifactViewerProps): any => { return new Promise((resolve, reject) => { Papa.parse(props.src, {