-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experiment checking before modifying the dataset
- Loading branch information
1 parent
e939ed7
commit 5f0f47d
Showing
4 changed files
with
239 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import { useSnackbar } from "notistack"; | ||
import { | ||
Button, | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
DialogContentText, | ||
DialogTitle, | ||
} from "@mui/material"; | ||
import { copyDataset } from "../../api/datasets"; | ||
|
||
function CopyDatasetModal({ | ||
datasetId, | ||
updateDatasetId, | ||
open, | ||
setOpen, | ||
modifyDataset, | ||
}) { | ||
const { enqueueSnackbar } = useSnackbar(); | ||
|
||
const handleDatasetModification = async (id) => { | ||
modifyDataset(id); | ||
setOpen(false); | ||
}; | ||
|
||
const handleDatasetCopyModification = async () => { | ||
try { | ||
const datasetCopy = await copyDataset({ | ||
dataset_id: datasetId, | ||
}); | ||
updateDatasetId(datasetCopy.id); | ||
enqueueSnackbar("Dataset copied successfully", { | ||
variant: "success", | ||
}); | ||
|
||
handleDatasetModification(datasetCopy.id); | ||
} catch (error) { | ||
enqueueSnackbar("Error while trying to create a copy of the dataset."); | ||
} finally { | ||
setOpen(false); | ||
} | ||
}; | ||
return ( | ||
<Dialog open={open} onClose={() => setOpen(false)}> | ||
<DialogTitle>Existing experiments</DialogTitle> | ||
<DialogContent> | ||
<DialogContentText> | ||
This dataset is currently used in existing experiments. Modifying it | ||
may impact the results of re-running those experiments. Would you like | ||
to create and modify a copy of this dataset instead? | ||
</DialogContentText> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={() => setOpen(false)} autoFocus> | ||
Cancel | ||
</Button> | ||
<Button onClick={() => handleDatasetModification(datasetId)}> | ||
Modify anyway | ||
</Button> | ||
<Button | ||
onClick={handleDatasetCopyModification} | ||
variant="contained" | ||
color="primary" | ||
> | ||
Make a copy | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
} | ||
CopyDatasetModal.propTypes = { | ||
datasetId: PropTypes.number.isRequired, | ||
updateDatasetId: PropTypes.func.isRequired, | ||
open: PropTypes.bool.isRequired, | ||
setOpen: PropTypes.func.isRequired, | ||
modifyDataset: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default CopyDatasetModal; |