Skip to content

Commit

Permalink
Merge pull request #857 from OpenSourceBrain/feature/816
Browse files Browse the repository at this point in the history
feature/816 - "go to workspace" dialog for Create a new NWB workspace, and others
  • Loading branch information
filippomc authored Dec 21, 2023
2 parents eca2dc0 + ee8137a commit 838a6c2
Showing 1 changed file with 55 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
lightWhite,
} from "../../theme";
import ConfirmationDialog from "../dialogs/WorkspaceConfirmDialog";
import WorkspaceConfirmDialog from "../dialogs/WorkspaceConfirmDialog";

export interface WorkspaceTemplate {
title: string;
Expand Down Expand Up @@ -141,19 +142,49 @@ export const NewWorkspaceItem = (props: ItemProps) => {
const { template, title, refreshWorkspaces, className, icon } = props;

const [newWorkspaceOpen, setNewWorkspaceOpen] = React.useState(false);
const [workspaceLink, setWorkspaceLink] = React.useState("");

const handleClick = () => {
setNewWorkspaceOpen(true);
};


const onWorkspaceCreated = (refresh = false) => {
const [createdWorkspaceConfirmationContent, setCreatedWorkspaceConfirmationContent] = React.useState({
title: "",
content: "",
isSuccess: false,
showConfirmationDialog: false,
});

const handleCloseConfirmationDialog = () => {
setCreatedWorkspaceConfirmationContent({
title: "",
content: "",
isSuccess: false,
showConfirmationDialog: false,
});
props.closeMainDialog(false);
}

const onWorkspaceCreated = (refresh = false, ws: Workspace) => {
if (refresh) {
refreshWorkspaces();
}
props.closeMainDialog(true);

// if non-default workspace
if (defaultWorkspace) {
setWorkspaceLink(`/workspace/${ws.id}`);
setCreatedWorkspaceConfirmationContent((prevContent) => ({
...prevContent,
title: "Success!",
content: "New workspace created.",
isSuccess: true,
showConfirmationDialog: true,
}));
}
};

// default workspace - other - computational modeling (NETPYNE), data analysis (NWB Explorer), interactive development (JupyterLab)
// non default workspace - Create new workspace from repository
const defaultWorkspace: Workspace = WORKSPACE_TEMPLATES[template];
return (
<>
Expand All @@ -173,14 +204,27 @@ export const NewWorkspaceItem = (props: ItemProps) => {

{newWorkspaceOpen &&
(defaultWorkspace ? (
<WorkspaceEditor
title="Create new workspace"
open={newWorkspaceOpen}
user={props.user}
workspace={defaultWorkspace}
onLoadWorkspace={onWorkspaceCreated}
closeHandler={() => setNewWorkspaceOpen(false)}
/>
<>
{createdWorkspaceConfirmationContent.showConfirmationDialog
? (
<WorkspaceConfirmDialog
setChecked={(x) => null}
createdWorkspaceConfirmationContent={createdWorkspaceConfirmationContent}
workspaceLink={workspaceLink}
handleCloseConfirmationDialog={handleCloseConfirmationDialog}
/>
) : (
<WorkspaceEditor
title="Create new workspace"
open={newWorkspaceOpen}
user={props.user}
workspace={defaultWorkspace}
onLoadWorkspace={onWorkspaceCreated}
closeHandler={() => setNewWorkspaceOpen(false)}
/>
)
}
</>
) : (
<WorkspaceFromRepository
close={() => setNewWorkspaceOpen(false)}
Expand Down

0 comments on commit 838a6c2

Please sign in to comment.