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

feature/816 - "go to workspace" dialog for Create a new NWB workspace, and others #857

Merged
merged 2 commits into from
Dec 21, 2023
Merged
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
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
Loading