Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add workspace_id #7

Merged
merged 2 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 62 additions & 26 deletions frontend/src/api/experiments/Experiments.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,114 @@
import axios from 'axios'

import { BASE_URL } from 'const/API'
import { RunPostData } from 'api/run/Run'
import { EdgeDict, NodeDict, OutputPathsDTO, RunPostData } from 'api/run/Run'
import { EXPERIMENTS_STATUS } from 'store/slice/Experiments/ExperimentsType'

export type ExperimentsDTO = {
[uid: string]: ExperimentDTO
}

export type ExperimentDTO = {
function: {
[uid: string]: {
name: string
success: string
unique_id: string
hasNWB: boolean
}
export type FunctionsDTO = {
[nodeId: string]: {
name: string
success: string
unique_id: string
hasNWB: boolean
message?: string
started_at?: string
finished_at?: string
outputPaths?: OutputPathsDTO
}
}

export type ExperimentDTO = {
function: FunctionsDTO
name: string
success: string
timestamp: string
success?: EXPERIMENTS_STATUS
started_at: string
finished_at?: string
workspace_id: string
unique_id: string
hasNWB: boolean
edgeDict: EdgeDict
nodeDict: NodeDict
}

export async function getExperimentsApi(): Promise<ExperimentsDTO> {
const response = await axios.get(`${BASE_URL}/experiments`)
export async function getExperimentsApi(
workspaceId: string,
): Promise<ExperimentsDTO> {
const response = await axios.get(`${BASE_URL}/experiments/${workspaceId}`)
return response.data
}

export async function deleteExperimentByUidApi(uid: string): Promise<boolean> {
const response = await axios.delete(`${BASE_URL}/experiments/${uid}`)
export async function deleteExperimentByUidApi(
workspaceId: string,
uid: string,
): Promise<boolean> {
const response = await axios.delete(
`${BASE_URL}/experiments/${workspaceId}/${uid}`,
)
return response.data
}

export async function deleteExperimentByListApi(
workspaceId: string,
uidList: Array<string>,
): Promise<boolean> {
const response = await axios.post(`${BASE_URL}/experiments/delete`, {
uidList,
})
const response = await axios.post(
`${BASE_URL}/experiments/delete/${workspaceId}`,
{
uidList,
},
)
return response.data
}

export async function importExperimentByUidApi(
workspaceId: string,
uid: string,
): Promise<RunPostData> {
const response = await axios.get(`${BASE_URL}/experiments/import/${uid}`)
const response = await axios.get(
`${BASE_URL}/experiments/import/${workspaceId}/${uid}`,
)
return response.data
}

export async function downloadExperimentNwbApi(uid: string, nodeId?: string) {
export async function downloadExperimentNwbApi(
workspaceId: string,
uid: string,
nodeId?: string,
) {
const path =
nodeId != null
? `${BASE_URL}/experiments/download/nwb/${uid}/${nodeId}`
: `${BASE_URL}/experiments/download/nwb/${uid}`
? `${BASE_URL}/experiments/download/nwb/${workspaceId}/${uid}/${nodeId}`
: `${BASE_URL}/experiments/download/nwb/${workspaceId}/${uid}`
const response = await axios.get(path, {
responseType: 'blob',
})
return response.data
}

export async function downloadExperimentConfigApi(uid: string) {
export async function downloadExperimentConfigApi(
workspaceId: string,
uid: string,
) {
const response = await axios.get(
`${BASE_URL}/experiments/download/config/${uid}`,
`${BASE_URL}/experiments/download/config/${workspaceId}/${uid}`,
{
responseType: 'blob',
},
)
return response.data
}

export async function renameExperiment(unique_id: string, new_name: string) {
export async function renameExperiment(
workspaceId: string,
uid: string,
new_name: string,
) {
const response = await axios.patch(
`${BASE_URL}/experiments/${unique_id}/rename`,
`${BASE_URL}/experiments/${workspaceId}/${uid}/rename`,
{
new_name,
},
Expand Down
25 changes: 18 additions & 7 deletions frontend/src/api/run/Run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,23 @@ export interface AlgorithmNodePostData extends AlgorithmNodeData {
param: ParamMap
}

export async function runApi(data: RunPostData): Promise<string> {
const response = await axios.post(`${BASE_URL}/run`, data)
export async function runApi(
workspaceId: string,
data: RunPostData,
): Promise<string> {
const response = await axios.post(`${BASE_URL}/run/${workspaceId}`, data)
return response.data
}

export async function runByUidApi(
workspaceId: string,
uid: string,
data: Omit<RunPostData, 'name'>,
): Promise<string> {
const response = await axios.post(`${BASE_URL}/run/${uid}`, data)
const response = await axios.post(
`${BASE_URL}/run/${workspaceId}/${uid}`,
data,
)
return response.data
}

Expand All @@ -72,12 +79,16 @@ export type OutputPathsDTO = {
}

export async function runResult(data: {
workspaceId: string
uid: string
pendingNodeIdList: string[]
}): Promise<RunResultDTO> {
const { uid, pendingNodeIdList } = data
const response = await axios.post(`${BASE_URL}/run/result/${uid}`, {
pendingNodeIdList,
})
const { workspaceId, uid, pendingNodeIdList } = data
const response = await axios.post(
`${BASE_URL}/run/result/${workspaceId}/${uid}`,
{
pendingNodeIdList,
},
)
return response.data
}
9 changes: 6 additions & 3 deletions frontend/src/components/Experiment/Button/DownloadButton.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import React, { useState, useRef } from 'react'
import IconButton from '@mui/material/IconButton'
import GetAppIcon from '@mui/icons-material/GetApp'

import { useSelector } from 'react-redux'
import {
downloadExperimentConfigApi,
downloadExperimentNwbApi,
} from 'api/experiments/Experiments'

import { ExperimentUidContext } from '../ExperimentTable'
import { selectCurrentWorkspaceId } from 'store/slice/Workspace/WorkspaceSelector'

export const NWBDownloadButton = React.memo<{
name: string
nodeId?: string
hasNWB: boolean
}>(({ name, nodeId, hasNWB }) => {
const workspaceId = useSelector(selectCurrentWorkspaceId)
const uid = React.useContext(ExperimentUidContext)
const ref = useRef<HTMLAnchorElement | null>(null)
const [url, setFileUrl] = useState<string>()

const onClick = async () => {
try {
const responseData = await downloadExperimentNwbApi(uid, nodeId)
const responseData = await downloadExperimentNwbApi(workspaceId, uid, nodeId)
const url = URL.createObjectURL(new Blob([responseData]))
setFileUrl(url)
ref.current?.click()
Expand All @@ -43,13 +45,14 @@ export const NWBDownloadButton = React.memo<{
})

export const ConfigDownloadButton = React.memo(() => {
const workspaceId = useSelector(selectCurrentWorkspaceId)
const uid = React.useContext(ExperimentUidContext)
const ref = useRef<HTMLAnchorElement | null>(null)
const [url, setFileUrl] = useState<string>()

const onClick = async () => {
try {
const responseData = await downloadExperimentConfigApi(uid)
const responseData = await downloadExperimentConfigApi(workspaceId, uid)
const url = URL.createObjectURL(new Blob([responseData]))
setFileUrl(url)
ref.current?.click()
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/components/Experiment/Button/ImportButton.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import React from 'react'
import { useDispatch } from 'react-redux'
import { useDispatch, useSelector } from 'react-redux'
import IconButton from '@mui/material/IconButton'
import { useSnackbar } from 'notistack'
import { importExperimentByUid } from 'store/slice/Experiments/ExperimentsActions'
import { AppDispatch } from 'store/store'
import { ExperimentUidContext } from '../ExperimentTable'
import ReplyIcon from '@mui/icons-material/Reply'
import { reset } from 'store/slice/VisualizeItem/VisualizeItemSlice'
import { selectCurrentWorkspaceId } from 'store/slice/Workspace/WorkspaceSelector'

export const ImportButton = React.memo(() => {
const dispatch: AppDispatch = useDispatch()
const workspaceId = useSelector(selectCurrentWorkspaceId)
const uid = React.useContext(ExperimentUidContext)
const { enqueueSnackbar } = useSnackbar()

const onClick = () => {
dispatch(importExperimentByUid(uid))
dispatch(importExperimentByUid({workspaceId, uid}))
.unwrap()
.then(() => {
enqueueSnackbar('Successfully imported.', { variant: 'success' })
Expand Down
16 changes: 9 additions & 7 deletions frontend/src/components/Experiment/ExperimentTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import Typography from '@mui/material/Typography'

import { CollapsibleTable } from './CollapsibleTable'
import {
selectExperimentsSatusIsUninitialized,
selectExperimentsSatusIsFulfilled,
selectExperimentsStatusIsUninitialized,
selectExperimentsStatusIsFulfilled,
selectExperimentTimeStamp,
selectExperimentName,
selectExperimentStatus,
selectExperimentsSatusIsError,
selectExperimentsStatusIsError,
selectExperimentsErrorMessage,
selectExperimentList,
selectExperimentHasNWB,
Expand All @@ -53,13 +53,14 @@ import { styled } from '@mui/material/styles'
import { renameExperiment } from 'api/experiments/Experiments'
import { selectPipelineLatestUid } from 'store/slice/Pipeline/PipelineSelectors'
import { clearCurrentPipeline } from 'store/slice/Pipeline/PipelineSlice'
import { selectCurrentWorkspaceId } from 'store/slice/Workspace/WorkspaceSelector'

export const ExperimentUidContext = React.createContext<string>('')

export const ExperimentTable: React.FC = () => {
const isUninitialized = useSelector(selectExperimentsSatusIsUninitialized)
const isFulfilled = useSelector(selectExperimentsSatusIsFulfilled)
const isError = useSelector(selectExperimentsSatusIsError)
const isUninitialized = useSelector(selectExperimentsStatusIsUninitialized)
const isFulfilled = useSelector(selectExperimentsStatusIsFulfilled)
const isError = useSelector(selectExperimentsStatusIsError)
const dispatch = useDispatch()
React.useEffect(() => {
if (isUninitialized) {
Expand Down Expand Up @@ -371,6 +372,7 @@ const RowItem = React.memo<{
onCheckBoxClick: (uid: string) => void
checked: boolean
}>(({ onCheckBoxClick, checked }) => {
const workspaceId = useSelector(selectCurrentWorkspaceId)
const uid = React.useContext(ExperimentUidContext)
const timestamp = useSelector(selectExperimentTimeStamp(uid))
const status = useSelector(selectExperimentStatus(uid))
Expand Down Expand Up @@ -408,7 +410,7 @@ const RowItem = React.memo<{

const onSaveNewName = async () => {
if (valueEdit === name) return
await renameExperiment(uid, valueEdit)
await renameExperiment(workspaceId, uid, valueEdit)
dispatch(getExperiments())
}

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/common/CurrentPipelineInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { selectPipelineLatestUid } from 'store/slice/Pipeline/PipelineSelectors'
import { Divider, Typography, Grid } from '@mui/material'
import {
selectExperimentName,
selectExperimentsSatusIsFulfilled,
selectExperimentsStatusIsFulfilled,
} from 'store/slice/Experiments/ExperimentsSelectors'

export const CurrentPipelineInfo: React.FC = () => {
const uid = useSelector(selectPipelineLatestUid)
const isFulFilled = useSelector(selectExperimentsSatusIsFulfilled)
const isFulFilled = useSelector(selectExperimentsStatusIsFulfilled)

return (
<>
Expand Down
Loading