X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/f5e55e7a71f2fc2390d392af752c61b4d3135cb6..cba0f400f56889778321bdc0fdcf6cee236f6a79:/src/views/workbench/workbench.tsx

diff --git a/src/views/workbench/workbench.tsx b/src/views/workbench/workbench.tsx
index 6ad4d247..ef5fe215 100644
--- a/src/views/workbench/workbench.tsx
+++ b/src/views/workbench/workbench.tsx
@@ -4,41 +4,44 @@
 
 import * as React from 'react';
 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
-import Drawer from '@material-ui/core/Drawer';
 import { connect, DispatchProp } from "react-redux";
-import { Route, Switch, RouteComponentProps } from "react-router";
-import authActions from "../../store/auth/auth-action";
-import { User } from "../../models/user";
-import { RootState } from "../../store/store";
-import MainAppBar, {
-    MainAppBarActionProps,
-    MainAppBarMenuItem
-} from '../../views-components/main-app-bar/main-app-bar';
-import { Breadcrumb } from '../../components/breadcrumbs/breadcrumbs';
+import { Route, Switch } from "react-router";
+import { login, logout } from "~/store/auth/auth-action";
+import { User } from "~/models/user";
+import { RootState } from "~/store/store";
+import { MainAppBar, MainAppBarActionProps, MainAppBarMenuItem } from '~/views-components/main-app-bar/main-app-bar';
 import { push } from 'react-router-redux';
-import ProjectTree from '../../views-components/project-tree/project-tree';
-import { TreeItem } from "../../components/tree/tree";
-import { Project } from "../../models/project";
-import { getTreePath } from '../../store/project/project-reducer';
-import sidePanelActions from '../../store/side-panel/side-panel-action';
-import SidePanel, { SidePanelItem } from '../../components/side-panel/side-panel';
-import { ItemMode, setProjectItem } from "../../store/navigation/navigation-action";
-import projectActions from "../../store/project/project-action";
-import ProjectPanel from "../project-panel/project-panel";
-import DetailsPanel from '../../views-components/details-panel/details-panel';
-import { ArvadosTheme } from '../../common/custom-theme';
-import ContextMenu, { ContextMenuAction } from '../../components/context-menu/context-menu';
-import { mockAnchorFromMouseEvent } from '../../components/popover/helpers';
-import CreateProjectDialog from "../../views-components/create-project-dialog/create-project-dialog";
-import { authService } from '../../services/services';
-
-import detailsPanelActions, { loadDetails } from "../../store/details-panel/details-panel-action";
-import { ResourceKind } from '../../models/kinds';
-
-const drawerWidth = 240;
-const appBarHeight = 100;
-
-type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
+import { ProjectPanel } from "~/views/project-panel/project-panel";
+import { DetailsPanel } from '~/views-components/details-panel/details-panel';
+import { ArvadosTheme } from '~/common/custom-theme';
+import { detailsPanelActions } from "~/store/details-panel/details-panel-action";
+import { ContextMenu } from "~/views-components/context-menu/context-menu";
+import { FavoritePanel } from "../favorite-panel/favorite-panel";
+import { CurrentTokenDialog } from '~/views-components/current-token-dialog/current-token-dialog';
+import { Snackbar } from '~/views-components/snackbar/snackbar';
+import { CollectionPanel } from '../collection-panel/collection-panel';
+import { AuthService } from "~/services/auth-service/auth-service";
+import { RenameFileDialog } from '~/views-components/rename-file-dialog/rename-file-dialog';
+import { FileRemoveDialog } from '~/views-components/file-remove-dialog/file-remove-dialog';
+import { MultipleFilesRemoveDialog } from '~/views-components/file-remove-dialog/multiple-files-remove-dialog';
+import { Routes } from '~/routes/routes';
+import { SidePanel } from '~/views-components/side-panel/side-panel';
+import { ProcessPanel } from '~/views/process-panel/process-panel';
+import { Breadcrumbs } from '~/views-components/breadcrumbs/breadcrumbs';
+import { CreateProjectDialog } from '~/views-components/dialog-forms/create-project-dialog';
+import { CreateCollectionDialog } from '~/views-components/dialog-forms/create-collection-dialog';
+import { CopyCollectionDialog } from '~/views-components/dialog-forms/copy-collection-dialog';
+import { UpdateCollectionDialog } from '~/views-components/dialog-forms/update-collection-dialog';
+import { UpdateProjectDialog } from '~/views-components/dialog-forms/update-project-dialog';
+import { MoveProjectDialog } from '~/views-components/dialog-forms/move-project-dialog';
+import { MoveCollectionDialog } from '~/views-components/dialog-forms/move-collection-dialog';
+
+import { FilesUploadCollectionDialog } from '~/views-components/dialog-forms/files-upload-collection-dialog';
+import { PartialCopyCollectionDialog } from '~/views-components/dialog-forms/partial-copy-collection-dialog';
+
+const APP_BAR_HEIGHT = 100;
+
+type CssRules = 'root' | 'appBar' | 'content' | 'contentWrapper';
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     root: {
@@ -55,52 +58,42 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
         position: "absolute",
         width: "100%"
     },
-    drawerPaper: {
-        position: 'relative',
-        width: drawerWidth,
-        display: 'flex',
-        flexDirection: 'column',
-    },
     contentWrapper: {
         backgroundColor: theme.palette.background.default,
         display: "flex",
         flexGrow: 1,
         minWidth: 0,
-        paddingTop: appBarHeight
+        paddingTop: APP_BAR_HEIGHT
     },
     content: {
         padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
         overflowY: "auto",
-        flexGrow: 1
+        flexGrow: 1,
+        position: 'relative'
     },
-    toolbar: theme.mixins.toolbar
 });
 
 interface WorkbenchDataProps {
-    projects: Array<TreeItem<Project>>;
-    currentProjectId: string;
     user?: User;
-    sidePanelItems: SidePanelItem[];
+    currentToken?: string;
 }
 
-interface WorkbenchActionProps {
+interface WorkbenchGeneralProps {
+    authService: AuthService;
+    buildInfo: string;
 }
 
-type WorkbenchProps = WorkbenchDataProps & WorkbenchActionProps & DispatchProp & WithStyles<CssRules>;
-
-interface NavBreadcrumb extends Breadcrumb {
-    itemId: string;
+interface WorkbenchActionProps {
 }
 
+type WorkbenchProps = WorkbenchDataProps & WorkbenchGeneralProps & WorkbenchActionProps & DispatchProp<any> & WithStyles<CssRules>;
+
 interface NavMenuItem extends MainAppBarMenuItem {
     action: () => void;
 }
 
 interface WorkbenchState {
-    contextMenu: {
-        anchorEl?: HTMLElement;
-        itemUuid?: string;
-    };
+    isCurrentTokenDialogOpen: boolean;
     anchorEl: any;
     searchText: string;
     menuItems: {
@@ -110,205 +103,111 @@ interface WorkbenchState {
     };
 }
 
-
-class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
-    state = {
-        contextMenu: {
-            anchorEl: undefined,
-            itemUuid: undefined
-        },
-        isCreationDialogOpen: false,
-        anchorEl: null,
-        searchText: "",
-        breadcrumbs: [],
-        menuItems: {
-            accountMenu: [
-                {
-                    label: "Logout",
-                    action: () => this.props.dispatch(authActions.LOGOUT())
-                },
-                {
-                    label: "My account",
-                    action: () => this.props.dispatch(push("/my-account"))
-                }
-            ],
-            helpMenu: [
-                {
-                    label: "Help",
-                    action: () => this.props.dispatch(push("/help"))
+export const Workbench = withStyles(styles)(
+    connect<WorkbenchDataProps>(
+        (state: RootState) => ({
+            user: state.auth.user,
+            currentToken: state.auth.apiToken,
+        })
+    )(
+        class extends React.Component<WorkbenchProps, WorkbenchState> {
+            state = {
+                isCurrentTokenDialogOpen: false,
+                anchorEl: null,
+                searchText: "",
+                breadcrumbs: [],
+                menuItems: {
+                    accountMenu: [
+                        {
+                            label: 'Current token',
+                            action: () => this.toggleCurrentTokenModal()
+                        },
+                        {
+                            label: "Logout",
+                            action: () => this.props.dispatch(logout())
+                        },
+                        {
+                            label: "My account",
+                            action: () => this.props.dispatch(push("/my-account"))
+                        }
+                    ],
+                    helpMenu: [
+                        {
+                            label: "Help",
+                            action: () => this.props.dispatch(push("/help"))
+                        }
+                    ],
+                    anonymousMenu: [
+                        {
+                            label: "Sign in",
+                            action: () => this.props.dispatch(login())
+                        }
+                    ]
                 }
-            ],
-            anonymousMenu: [
-                {
-                    label: "Sign in",
-                    action: () => this.props.dispatch(authActions.LOGIN())
-                }
-            ]
-        }
-    };
-
-    mainAppBarActions: MainAppBarActionProps = {
-        onBreadcrumbClick: ({ itemId }: NavBreadcrumb) => {
-            this.props.dispatch<any>(setProjectItem(itemId, ItemMode.BOTH));
-            this.props.dispatch<any>(loadDetails(itemId, ResourceKind.Project));
-        },
-        onSearch: searchText => {
-            this.setState({ searchText });
-            this.props.dispatch(push(`/search?q=${searchText}`));
-        },
-        onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
-        onDetailsPanelToggle: () => {
-            this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
-        },
-        onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
-            this.openContextMenu(event, breadcrumb.itemId);
-        }
-    };
-
-    toggleSidePanelOpen = (itemId: string) => {
-        this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(itemId));
-    }
-
-    toggleSidePanelActive = (itemId: string) => {
-        this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
-        this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
-    }
-
-    handleCreationDialogOpen = (itemUuid: string) => {
-        this.closeContextMenu();
-        this.props.dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: itemUuid }));
-    }
-
-
-    openContextMenu = (event: React.MouseEvent<HTMLElement>, itemUuid: string) => {
-        event.preventDefault();
-        this.setState({
-            contextMenu: {
-                anchorEl: mockAnchorFromMouseEvent(event),
-                itemUuid
+            };
+
+            render() {
+                const { classes, user } = this.props;
+                return (
+                    <div className={classes.root}>
+                        <div className={classes.appBar}>
+                            <MainAppBar
+                                breadcrumbs={Breadcrumbs}
+                                searchText={this.state.searchText}
+                                user={this.props.user}
+                                menuItems={this.state.menuItems}
+                                buildInfo={this.props.buildInfo}
+                                {...this.mainAppBarActions} />
+                        </div>
+                        {user && <SidePanel />}
+                        <main className={classes.contentWrapper}>
+                            <div className={classes.content}>
+                                <Switch>
+                                    <Route path={Routes.PROJECTS} component={ProjectPanel} />
+                                    <Route path={Routes.COLLECTIONS} component={CollectionPanel} />
+                                    <Route path={Routes.FAVORITES} component={FavoritePanel} />
+                                    <Route path={Routes.PROCESSES} component={ProcessPanel} />
+                                </Switch>
+                            </div>
+                            {user && <DetailsPanel />}
+                        </main>
+                        <ContextMenu />
+                        <Snackbar />
+                        <CreateProjectDialog />
+                        <CreateCollectionDialog />
+                        <RenameFileDialog />
+                        <PartialCopyCollectionDialog />
+                        <FileRemoveDialog />
+                        <CopyCollectionDialog />
+                        <FileRemoveDialog />
+                        <MultipleFilesRemoveDialog />
+                        <UpdateCollectionDialog />
+                        <FilesUploadCollectionDialog />
+                        <UpdateProjectDialog />
+                        <MoveCollectionDialog />
+                        <MoveProjectDialog />
+                        <CurrentTokenDialog
+                            currentToken={this.props.currentToken}
+                            open={this.state.isCurrentTokenDialogOpen}
+                            handleClose={this.toggleCurrentTokenModal} />
+                    </div>
+                );
             }
-        });
-    }
 
-    closeContextMenu = () => {
-        this.setState({ contextMenu: {} });
-    }
+            mainAppBarActions: MainAppBarActionProps = {
+                onSearch: searchText => {
+                    this.setState({ searchText });
+                    this.props.dispatch(push(`/search?q=${searchText}`));
+                },
+                onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
+                onDetailsPanelToggle: () => {
+                    this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
+                },
+            };
 
-    openCreateDialog = (item: ContextMenuAction) => {
-        const { itemUuid } = this.state.contextMenu;
-        if (item.openCreateDialog && itemUuid) {
-            this.handleCreationDialogOpen(itemUuid);
+            toggleCurrentTokenModal = () => {
+                this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });
+            }
         }
-    }
-
-    render() {
-        const path = getTreePath(this.props.projects, this.props.currentProjectId);
-        const breadcrumbs = path.map(item => ({
-            label: item.data.name,
-            itemId: item.data.uuid,
-            status: item.status
-        }));
-
-        const { classes, user } = this.props;
-        return (
-            <div className={classes.root}>
-                <div className={classes.appBar}>
-                    <MainAppBar
-                        breadcrumbs={breadcrumbs}
-                        searchText={this.state.searchText}
-                        user={this.props.user}
-                        menuItems={this.state.menuItems}
-                        {...this.mainAppBarActions} />
-                </div>
-                {user &&
-                    <Drawer
-                        variant="permanent"
-                        classes={{
-                            paper: classes.drawerPaper,
-                        }}>
-                        <div className={classes.toolbar} />
-                        <SidePanel
-                            toggleOpen={this.toggleSidePanelOpen}
-                            toggleActive={this.toggleSidePanelActive}
-                            sidePanelItems={this.props.sidePanelItems}
-                            onContextMenu={(event) => this.openContextMenu(event, authService.getUuid() || "")}>
-                            <ProjectTree
-                                projects={this.props.projects}
-                                toggleOpen={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.OPEN))}
-                                onContextMenu={(event, item) => this.openContextMenu(event, item.data.uuid)}
-                                toggleActive={itemId => {
-                                    this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE));
-                                    this.props.dispatch<any>(loadDetails(itemId, ResourceKind.Project));
-                                }}/>
-                        </SidePanel>
-                    </Drawer>}
-                <main className={classes.contentWrapper}>
-                    <div className={classes.content}>
-                        <Switch>
-                            <Route path="/projects/:id" render={this.renderProjectPanel} />
-                        </Switch>
-                    </div>
-                    <DetailsPanel />
-                </main>
-                <ContextMenu
-                    anchorEl={this.state.contextMenu.anchorEl}
-                    actions={contextMenuActions}
-                    onActionClick={this.openCreateDialog}
-                    onClose={this.closeContextMenu} />
-                <CreateProjectDialog />
-            </div>
-        );
-    }
-
-    renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
-        onItemRouteChange={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
-        onContextMenu={(event, item) => this.openContextMenu(event, item.uuid)}
-        onDialogOpen={this.handleCreationDialogOpen}
-        onItemClick={item => {
-            this.props.dispatch<any>(loadDetails(item.uuid, item.kind as ResourceKind));
-        }}
-        onItemDoubleClick={item => {
-            this.props.dispatch<any>(setProjectItem(item.uuid, ItemMode.ACTIVE));
-            this.props.dispatch<any>(loadDetails(item.uuid, ResourceKind.Project));
-        }}
-        {...props} />
-}
-
-const contextMenuActions = [[{
-    icon: "fas fa-plus fa-fw",
-    name: "New project",
-    openCreateDialog: true
-}, {
-    icon: "fas fa-users fa-fw",
-    name: "Share"
-}, {
-    icon: "fas fa-sign-out-alt fa-fw",
-    name: "Move to"
-}, {
-    icon: "fas fa-star fa-fw",
-    name: "Add to favourite"
-}, {
-    icon: "fas fa-edit fa-fw",
-    name: "Rename"
-}, {
-    icon: "fas fa-copy fa-fw",
-    name: "Make a copy"
-}, {
-    icon: "fas fa-download fa-fw",
-    name: "Download"
-}], [{
-    icon: "fas fa-trash-alt fa-fw",
-    name: "Remove"
-}
-]];
-
-export default connect<WorkbenchDataProps>(
-    (state: RootState) => ({
-        projects: state.projects.items,
-        currentProjectId: state.projects.currentItemId,
-        user: state.auth.user,
-        sidePanelItems: state.sidePanel
-    })
-)(
-    withStyles(styles)(Workbench)
+    )
 );
