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

[No.203]Workflow を新しいIDでcopy する機能 #496

Open
wants to merge 20 commits into
base: develop-main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
13 changes: 13 additions & 0 deletions frontend/src/api/experiments/Experiments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ export async function deleteExperimentByListApi(
return response.data
}

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

export async function downloadExperimentNwbApi(
workspaceId: number,
uid: string,
Expand Down
25 changes: 25 additions & 0 deletions frontend/src/components/Workspace/Experiment/ExperimentTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useSelector, useDispatch } from "react-redux"

import { useSnackbar } from "notistack"

import ContentCopyIcon from "@mui/icons-material/ContentCopy"
import DeleteIcon from "@mui/icons-material/Delete"
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown"
import KeyboardArrowUpIcon from "@mui/icons-material/KeyboardArrowUp"
Expand Down Expand Up @@ -49,6 +50,7 @@ import { ReproduceButton } from "components/Workspace/Experiment/Button/Reproduc
import { CollapsibleTable } from "components/Workspace/Experiment/CollapsibleTable"
import { ExperimentStatusIcon } from "components/Workspace/Experiment/ExperimentStatusIcon"
import {
copyExperimentByList,
deleteExperimentByList,
getExperiments,
} from "store/slice/Experiments/ExperimentsActions"
Expand Down Expand Up @@ -138,6 +140,18 @@ const TableImple = memo(function TableImple() {
setSortTarget(property)
}

const onClickCopy = () => {
dispatch(copyExperimentByList(checkedList))
.unwrap()
.then(() => {
dispatch(getExperiments())
enqueueSnackbar("Record Copied", { variant: "success" })
})
.catch(() => {
enqueueSnackbar("Failed to copy", { variant: "error" })
})
}

const onCheckBoxClick = (uid: string) => {
if (checkedList.includes(uid)) {
setCheckedList(checkedList.filter((v) => v !== uid))
Expand Down Expand Up @@ -238,6 +252,17 @@ const TableImple = memo(function TableImple() {
Delete
</Button>
)}
<Button
sx={{
margin: (theme) => theme.spacing(0, 1, 1, 1),
}}
variant="outlined"
endIcon={<ContentCopyIcon />}
itutu-tienday marked this conversation as resolved.
Show resolved Hide resolved
itutu-tienday marked this conversation as resolved.
Show resolved Hide resolved
onClick={onClickCopy}
disabled={checkedList.length === 0 || isRunning}
>
COPY
</Button>
</Box>
<ConfirmDialog
open={open}
Expand Down
54 changes: 54 additions & 0 deletions frontend/src/store/slice/Experiments/Experiments.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect, describe, test } from "@jest/globals"

import {
copyExperimentByList,
deleteExperimentByList,
deleteExperimentByUid,
getExperiments,
Expand Down Expand Up @@ -215,4 +216,57 @@ describe("Experiments", () => {
targetState.status === "fulfilled" && targetState.experimentList,
).toEqual({})
})

test(copyExperimentByList.fulfilled.type, () => {
const prevState = reducer(
reducer(initialState, getExperimentsPendingAction),
getExperimentsFulfilledAction,
)
const copyExperimentByListFulfilledAction = {
type: copyExperimentByList.fulfilled.type,
payload: true,
meta: {
arg: [uid1, uid2],
requestId: "faNrL5ZV3SRODugFlJM20",
requestStatus: "fulfilled",
},
}
const targetState = reducer(prevState, copyExperimentByListFulfilledAction)
expect(targetState.loading).toBe(false)
})

test(copyExperimentByList.pending.type, () => {
const prevState = reducer(
reducer(initialState, getExperimentsPendingAction),
getExperimentsFulfilledAction,
)
const copyExperimentByListPendingAction = {
type: copyExperimentByList.pending.type,
meta: {
arg: [uid1, uid2],
requestId: "faNrL5ZV3SRODugFlJM20",
requestStatus: "pending",
},
}
const targetState = reducer(prevState, copyExperimentByListPendingAction)
expect(targetState.loading).toBe(true)
})

test(copyExperimentByList.rejected.type, () => {
const prevState = reducer(
reducer(initialState, getExperimentsPendingAction),
getExperimentsFulfilledAction,
)
const copyExperimentByListRejectedAction = {
type: copyExperimentByList.rejected.type,
payload: false,
meta: {
arg: [uid1, uid2],
requestId: "faNrL5ZV3SRODugFlJM20",
requestStatus: "rejected",
},
}
const targetState = reducer(prevState, copyExperimentByListRejectedAction)
expect(targetState.loading).toBe(false)
})
})
19 changes: 19 additions & 0 deletions frontend/src/store/slice/Experiments/ExperimentsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getExperimentsApi,
deleteExperimentByUidApi,
deleteExperimentByListApi,
copyExperimentByListApi,
} from "api/experiments/Experiments"
import { EXPERIMENTS_SLICE_NAME } from "store/slice/Experiments/ExperimentsType"
import { selectCurrentWorkspaceId } from "store/slice/Workspace/WorkspaceSelector"
Expand Down Expand Up @@ -63,3 +64,21 @@ export const deleteExperimentByList = createAsyncThunk<
return thunkAPI.rejectWithValue("workspace id does not exist.")
}
})

export const copyExperimentByList = createAsyncThunk<
boolean,
string[],
ThunkApiConfig
>(`${EXPERIMENTS_SLICE_NAME}/copyExperimentByList`, async (uid, thunkAPI) => {
const workspaceId = selectCurrentWorkspaceId(thunkAPI.getState())
if (workspaceId) {
try {
const response = await copyExperimentByListApi(workspaceId, uid)
return response
} catch (e) {
return thunkAPI.rejectWithValue(e)
}
} else {
return thunkAPI.rejectWithValue("workspace id does not exist.")
}
})
10 changes: 10 additions & 0 deletions frontend/src/store/slice/Experiments/ExperimentsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getExperiments,
deleteExperimentByUid,
deleteExperimentByList,
copyExperimentByList,
} from "store/slice/Experiments/ExperimentsActions"
import {
EXPERIMENTS_SLICE_NAME,
Expand Down Expand Up @@ -111,6 +112,15 @@ export const experimentsSlice = createSlice({
status: "uninitialized",
}
})
.addMatcher(isAnyOf(copyExperimentByList.fulfilled), (state) => {
itutu-tienday marked this conversation as resolved.
Show resolved Hide resolved
state.loading = false
})
.addMatcher(isAnyOf(copyExperimentByList.pending), (state) => {
state.loading = true
})
.addMatcher(isAnyOf(copyExperimentByList.rejected), (state) => {
state.loading = false
})
},
})

Expand Down
Loading
Loading