-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from MetaCell/feature/CELE-52
Feature/cele 52
- Loading branch information
Showing
35 changed files
with
1,714 additions
and
637 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ | |
display: flex; | ||
flex-direction: column; | ||
height: 100vh; | ||
overflow: hidden; | ||
overflow: auto; | ||
} |
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
177 changes: 177 additions & 0 deletions
177
applications/visualizer/frontend/src/components/CreateNewWorkspaceDialog.tsx
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,177 @@ | ||
import { Box, Button, FormLabel, IconButton, TextField, Typography } from "@mui/material"; | ||
import { debounce } from "lodash"; | ||
import { useCallback, useState } from "react"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
import { useGlobalContext } from "../contexts/GlobalContext.tsx"; | ||
import { CaretIcon, CheckIcon, CloseIcon } from "../icons"; | ||
import { type Dataset, type Neuron, NeuronsService } from "../rest"; | ||
import { vars as colors } from "../theme/variables.ts"; | ||
import CustomAutocomplete from "./CustomAutocomplete.tsx"; | ||
import CustomDialog from "./CustomDialog.tsx"; | ||
|
||
const CreateNewWorkspaceDialog = ({ onCloseCreateWorkspace, showCreateWorkspaceDialog, isCompareMode, title, subTitle, submitButtonText }) => { | ||
const [neurons, setNeurons] = useState<Neuron[]>([]); | ||
const { workspaces, datasets, createWorkspace, setSelectedWorkspacesIds } = useGlobalContext(); | ||
const [searchedNeuron, setSearchedNeuron] = useState(""); | ||
const [formValues, setFormValues] = useState<{ | ||
workspaceName: string; | ||
selectedDatasets: Dataset[]; | ||
selectedNeurons: Neuron[]; | ||
}>({ | ||
workspaceName: "", | ||
selectedDatasets: [], | ||
selectedNeurons: [], | ||
}); | ||
|
||
const [errorMessage, setErrorMessage] = useState<string>(""); | ||
|
||
const workspaceFieldName = "workspaceName"; | ||
const fetchNeurons = async (name, datasetsIds) => { | ||
try { | ||
const Ids = datasetsIds.map((dataset) => dataset.id); | ||
const response = await NeuronsService.searchCells({ | ||
name: name, | ||
datasetIds: Ids, | ||
}); | ||
setNeurons(response); | ||
} catch (error) { | ||
console.error("Failed to fetch datasets", error); | ||
} | ||
}; | ||
|
||
const debouncedFetchNeurons = useCallback(debounce(fetchNeurons, 300), []); | ||
const onSearchNeurons = (value) => { | ||
setSearchedNeuron(value); | ||
debouncedFetchNeurons(value, formValues.selectedDatasets); | ||
}; | ||
const handleInputChange = (event) => { | ||
const { name, value } = event.target; | ||
setFormValues({ ...formValues, [name]: value }); | ||
if (name === workspaceFieldName && errorMessage) { | ||
setErrorMessage(""); | ||
} | ||
}; | ||
|
||
const handleDatasetChange = (value) => { | ||
setFormValues({ ...formValues, selectedDatasets: value }); | ||
debouncedFetchNeurons(searchedNeuron, value); | ||
}; | ||
|
||
const handleNeuronChange = (value) => { | ||
setFormValues({ ...formValues, selectedNeurons: value }); | ||
}; | ||
|
||
const isWorkspaceNameDuplicate = (name) => { | ||
return Object.values(workspaces).some((workspace) => workspace.name === name); | ||
}; | ||
|
||
const handleSubmit = () => { | ||
if (!formValues.workspaceName.trim()) { | ||
setErrorMessage("Workspace name is required!"); | ||
return; | ||
} | ||
|
||
if (isWorkspaceNameDuplicate(formValues.workspaceName.trim())) { | ||
setErrorMessage("Workspace name already exists!"); | ||
return; | ||
} | ||
|
||
const randomNumber = uuidv4().replace(/\D/g, "").substring(0, 13); | ||
const newWorkspaceId = `workspace-${randomNumber}`; | ||
const activeNeurons = new Set(formValues.selectedNeurons.map((neuron) => neuron.name)); | ||
const activeDatasets = new Set(formValues.selectedDatasets.map((dataset) => dataset.id)); | ||
createWorkspace(newWorkspaceId, formValues.workspaceName, activeDatasets, activeNeurons); | ||
|
||
if (isCompareMode) { | ||
const updatedWorkspaces = new Set([...Object.keys(workspaces), newWorkspaceId]); | ||
setSelectedWorkspacesIds(updatedWorkspaces); | ||
} | ||
onCloseCreateWorkspace(); | ||
}; | ||
const datasetsArray = Object.values(datasets); | ||
|
||
return ( | ||
<CustomDialog onClose={onCloseCreateWorkspace} showModal={showCreateWorkspaceDialog} title={title}> | ||
<Box px="1rem" py="1.5rem" gap={2.5} display="flex" flexDirection="column"> | ||
{subTitle && <Typography>{subTitle}</Typography>} | ||
<Box> | ||
<FormLabel> | ||
Workspace name <Typography variant="caption">(REQUIRED)</Typography> | ||
</FormLabel> | ||
<TextField | ||
fullWidth | ||
variant="outlined" | ||
placeholder="Start typing workspace name" | ||
name={workspaceFieldName} | ||
value={formValues.workspaceName} | ||
onChange={handleInputChange} | ||
error={!!errorMessage} | ||
helperText={errorMessage} | ||
/> | ||
</Box> | ||
|
||
<Box> | ||
<FormLabel>Datasets</FormLabel> | ||
<CustomAutocomplete | ||
options={datasetsArray} | ||
getOptionLabel={(option) => option.name} | ||
renderOption={(props, option) => ( | ||
<li {...props}> | ||
<CheckIcon /> | ||
<Typography>{option.name}</Typography> | ||
</li> | ||
)} | ||
placeholder="Start typing to search" | ||
id="grouped-demo" | ||
popupIcon={<CaretIcon />} | ||
ChipProps={{ | ||
deleteIcon: ( | ||
<IconButton sx={{ p: "0 !important", margin: "0 !important" }}> | ||
<CloseIcon /> | ||
</IconButton> | ||
), | ||
}} | ||
value={formValues.selectedDatasets} | ||
onChange={handleDatasetChange} | ||
/> | ||
</Box> | ||
<Box> | ||
<FormLabel>Neurons</FormLabel> | ||
<CustomAutocomplete | ||
options={neurons} | ||
getOptionLabel={(option) => option.name} | ||
renderOption={(props, option) => ( | ||
<li {...props}> | ||
<CheckIcon /> | ||
<Typography>{option.name}</Typography> | ||
</li> | ||
)} | ||
onInputChange={onSearchNeurons} | ||
placeholder="Start typing to search" | ||
className="secondary" | ||
id="tags-standard" | ||
popupIcon={<CaretIcon />} | ||
disabled={formValues.selectedDatasets.length === 0} | ||
ChipProps={{ | ||
deleteIcon: ( | ||
<IconButton sx={{ p: "0 !important", margin: "0 !important" }}> | ||
<CloseIcon /> | ||
</IconButton> | ||
), | ||
}} | ||
clearIcon={false} | ||
value={formValues.selectedNeurons} | ||
onChange={handleNeuronChange} | ||
/> | ||
</Box> | ||
</Box> | ||
<Box borderTop={`0.0625rem solid ${colors.gray100}`} px="1rem" py="0.75rem" gap={0.5} display="flex" justifyContent="flex-end"> | ||
<Button variant="contained" color="info" onClick={handleSubmit} disabled={!formValues.workspaceName}> | ||
{submitButtonText} | ||
</Button> | ||
</Box> | ||
</CustomDialog> | ||
); | ||
}; | ||
|
||
export default CreateNewWorkspaceDialog; |
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
38 changes: 38 additions & 0 deletions
38
applications/visualizer/frontend/src/components/CustomDialog.tsx
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,38 @@ | ||
import { Box, Dialog, IconButton, Typography } from "@mui/material"; | ||
import type React from "react"; | ||
import { CloseIcon } from "../icons"; | ||
import { vars } from "../theme/variables.ts"; | ||
|
||
const { gray100 } = vars; | ||
interface CustomDialogProps { | ||
onClose: () => void; | ||
showModal: boolean; | ||
title: string; | ||
children: React.ReactNode; | ||
} | ||
|
||
const CustomDialog = ({ onClose, showModal, title, children }: CustomDialogProps) => { | ||
return ( | ||
<Dialog | ||
onClose={onClose} | ||
open={showModal} | ||
sx={{ | ||
"& .MuiBackdrop-root": { | ||
background: "rgba(0,0,0,0.25)", | ||
}, | ||
}} | ||
fullWidth | ||
maxWidth="lg" | ||
> | ||
<Box borderBottom={`0.0625rem solid ${gray100}`} px="1rem" py="0.5rem" display="flex" alignItems="center" justifyContent="space-between"> | ||
<Typography component="h3">{title}</Typography> | ||
<IconButton onClick={onClose}> | ||
<CloseIcon /> | ||
</IconButton> | ||
</Box> | ||
{children} | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default CustomDialog; |
Oops, something went wrong.