--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from 'react';
+import { ReactElement } from 'react';
+import { StyleRulesCallback, Theme, WithStyles, withStyles } from '@material-ui/core/styles';
+import List from "@material-ui/core/List/List";
+import ListItem from "@material-ui/core/ListItem/ListItem";
+import ListItemText from "@material-ui/core/ListItemText/ListItemText";
+import ListItemIcon from '@material-ui/core/ListItemIcon';
+import Collapse from "@material-ui/core/Collapse/Collapse";
+
+import { Typography } from '@material-ui/core';
+
+export interface SidePanelItem {
+ id: string;
+ name: string;
+ icon: string;
+ active?: boolean;
+ open?: boolean;
+}
+
+interface SidePanelProps {
+ toggleOpen: (id: string) => void;
+ toggleActive: (id: string) => void;
+ sidePanelItems: SidePanelItem[];
+}
+
+class SidePanel extends React.Component<SidePanelProps & WithStyles<CssRules>> {
+ render(): ReactElement<any> {
+ const { classes, toggleOpen, toggleActive, sidePanelItems } = this.props;
+ const { listItemText, leftSidePanelContainer, row, list, icon, projectIcon, active, activeArrow, inactiveArrow, arrowTransition, arrowRotate } = classes;
+ return (
+ <div className={leftSidePanelContainer}>
+ <List>
+ {sidePanelItems.map(it => (
+ <span key={it.name}>
+ <ListItem button className={list} onClick={() => toggleActive(it.id)}>
+ <span className={row}>
+ {it.name === "Projects" ? <i onClick={() => toggleOpen(it.id)} className={`${it.active ? activeArrow : inactiveArrow}
+ ${it.open ? `fas fa-caret-down ${arrowTransition}` : `fas fa-caret-down ${arrowRotate}`}`} /> : null}
+ <ListItemIcon className={it.active ? active : ''}>
+ <i className={`${it.icon} ${icon} ${it.name === "Projects" ? projectIcon : ''}`} />
+ </ListItemIcon>
+ <ListItemText className={listItemText} primary={<Typography className={it.active ? active : ''}>{it.name}</Typography>} />
+ </span>
+ </ListItem>
+ {it.name === "Projects" ? (
+ <Collapse in={it.open} timeout="auto" unmountOnExit>
+ {this.props.children}
+ </Collapse>) : null}
+ </span>
+ ))}
+ </List>
+ </div>
+ );
+ }
+}
+
+type CssRules = 'active' | 'listItemText' | 'row' | 'leftSidePanelContainer' | 'list' | 'icon' | 'projectIcon' |
+ 'activeArrow' | 'inactiveArrow' | 'arrowRotate' | 'arrowTransition';
+
+const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
+ active: {
+ color: '#4285F6',
+ },
+ listItemText: {
+ padding: '0px',
+ },
+ row: {
+ display: 'flex',
+ alignItems: 'center',
+ },
+ activeArrow: {
+ color: '#4285F6',
+ position: 'absolute',
+ },
+ inactiveArrow: {
+ position: 'absolute',
+ },
+ arrowTransition: {
+ transition: 'all 0.1s ease',
+ },
+ arrowRotate: {
+ transition: 'all 0.1s ease',
+ transform: 'rotate(-90deg)',
+ },
+ leftSidePanelContainer: {
+ overflowY: 'auto',
+ minWidth: '240px',
+ whiteSpace: 'nowrap',
+ marginTop: '38px',
+ display: 'flex',
+ flexGrow: 1,
+ },
+ list: {
+ paddingBottom: '5px',
+ paddingTop: '5px',
+ paddingLeft: '14px',
+ minWidth: '240px',
+ },
+ icon: {
+ minWidth: '20px',
+ },
+ projectIcon: {
+ marginLeft: '17px',
+ }
+});
+
+export default withStyles(styles)(SidePanel);
\ No newline at end of file
import { ReactElement } from "react";
import Collapse from "@material-ui/core/Collapse/Collapse";
import CircularProgress from '@material-ui/core/CircularProgress';
-import { inherits } from 'util';
-
-type CssRules = 'list' | 'activeArrow' | 'inactiveArrow' | 'arrowRotate' | 'arrowTransition' | 'loader' | 'arrowVisibility';
-
-const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
- list: {
- paddingBottom: '3px',
- paddingTop: '3px',
- },
- activeArrow: {
- color: '#4285F6',
- position: 'absolute',
- },
- inactiveArrow: {
- position: 'absolute',
- },
- arrowTransition: {
- transition: 'all 0.1s ease',
- },
- arrowRotate: {
- transition: 'all 0.1s ease',
- transform: 'rotate(-90deg)',
- },
- arrowVisibility: {
- opacity: 0,
- },
- loader: {
- position: 'absolute',
- transform: 'translate(0px)',
- top: '3px'
- }
-});
export enum TreeItemStatus {
Initial,
interface TreeProps<T> {
items?: Array<TreeItem<T>>;
render: (item: TreeItem<T>, level?: number) => ReactElement<{}>;
- toggleItem: (id: string, status: TreeItemStatus) => any;
+ toggleItemOpen: (id: string, status: TreeItemStatus) => void;
+ toggleItemActive: (id: string, status: TreeItemStatus) => void;
level?: number;
}
class Tree<T> extends React.Component<TreeProps<T> & WithStyles<CssRules>, {}> {
renderArrow(status: TreeItemStatus, arrowClass: string, open: boolean, id: string) {
- return <i
- onClick={() => this.props.toggleItem(id, status)}
+ const { arrowTransition, arrowVisibility, arrowRotate } = this.props.classes;
+ return <i onClick={() => this.props.toggleItemOpen(id, status)}
className={`
- ${arrowClass}
- ${status === TreeItemStatus.Pending ? this.props.classes.arrowVisibility : ''}
- ${open ? `fas fa-caret-down ${this.props.classes.arrowTransition}` : `fas fa-caret-down ${this.props.classes.arrowRotate}`}`} />;
+ ${arrowClass}
+ ${status === TreeItemStatus.Pending ? arrowVisibility : ''}
+ ${open ? `fas fa-caret-down ${arrowTransition}` : `fas fa-caret-down ${arrowRotate}`}`} />;
}
render(): ReactElement<any> {
const level = this.props.level ? this.props.level : 0;
- const { classes, render, toggleItem, items } = this.props;
+ const { classes, render, toggleItemOpen, items, toggleItemActive } = this.props;
const { list, inactiveArrow, activeArrow, loader } = classes;
return <List component="div" className={list}>
{items && items.map((it: TreeItem<T>, idx: number) =>
<div key={`item/${level}/${idx}`}>
- <ListItem button className={list} style={{ paddingLeft: (level + 1) * 20 }}>
+ <ListItem button className={list} style={{ paddingLeft: (level + 1) * 20 }} onClick={() => toggleItemActive(it.id, it.status)}>
{it.status === TreeItemStatus.Pending ? <CircularProgress size={10} className={loader} /> : null}
{it.toggled && it.items && it.items.length === 0 ? null : this.renderArrow(it.status, it.active ? activeArrow : inactiveArrow, it.open, it.id)}
{render(it, level)}
<StyledTree
items={it.items}
render={render}
- toggleItem={toggleItem}
+ toggleItemOpen={toggleItemOpen}
+ toggleItemActive={toggleItemActive}
level={level + 1} />
</Collapse>}
</div>)}
}
}
+type CssRules = 'list' | 'activeArrow' | 'inactiveArrow' | 'arrowRotate' | 'arrowTransition' | 'loader' | 'arrowVisibility';
+
+const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
+ list: {
+ paddingBottom: '3px',
+ paddingTop: '3px',
+ },
+ activeArrow: {
+ color: '#4285F6',
+ position: 'absolute',
+ },
+ inactiveArrow: {
+ position: 'absolute',
+ },
+ arrowTransition: {
+ transition: 'all 0.1s ease',
+ },
+ arrowRotate: {
+ transition: 'all 0.1s ease',
+ transform: 'rotate(-90deg)',
+ },
+ arrowVisibility: {
+ opacity: 0,
+ },
+ loader: {
+ position: 'absolute',
+ transform: 'translate(0px)',
+ top: '3px'
+ }
+});
+
const StyledTree = withStyles(styles)(Tree);
export default StyledTree;
},
auth: {
user: undefined
- }
+ },
+ sidePanel: []
}, history);
store.dispatch(authActions.INIT());
// Copyright (C) The Arvados Authors. All rights reserved.
//
// SPDX-License-Identifier: AGPL-3.0
+import { default as unionize, ofType, UnionOf } from "unionize";
import { Project } from "../../models/project";
-import { default as unionize, ofType, UnionOf } from "unionize";
import { projectService } from "../../services/services";
import { Dispatch } from "redux";
const actions = unionize({
CREATE_PROJECT: ofType<Project>(),
REMOVE_PROJECT: ofType<string>(),
- PROJECTS_REQUEST: ofType<any>(),
+ PROJECTS_REQUEST: ofType<string>(),
PROJECTS_SUCCESS: ofType<{ projects: Project[], parentItemId?: string }>(),
- TOGGLE_PROJECT_TREE_ITEM: ofType<string>()
+ TOGGLE_PROJECT_TREE_ITEM_OPEN: ofType<string>(),
+ TOGGLE_PROJECT_TREE_ITEM_ACTIVE: ofType<string>(),
+ RESET_PROJECT_TREE_ACTIVITY: ofType<string>(),
}, {
- tag: 'type',
- value: 'payload'
-});
+ tag: 'type',
+ value: 'payload'
+ });
export const getProjectList = (parentUuid?: string) => (dispatch: Dispatch): Promise<Project[]> => {
- dispatch(actions.PROJECTS_REQUEST());
- return projectService.getProjectList(parentUuid).then(projects => {
- dispatch(actions.PROJECTS_SUCCESS({projects, parentItemId: parentUuid}));
- return projects;
- });
+ if (parentUuid) {
+ dispatch(actions.PROJECTS_REQUEST(parentUuid));
+ return projectService.getProjectList(parentUuid).then(projects => {
+ dispatch(actions.PROJECTS_SUCCESS({ projects, parentItemId: parentUuid }));
+ return projects;
+ });
+ } return Promise.resolve([]);
};
export type ProjectAction = UnionOf<typeof actions>;
const projects = [project, project];
const state = projectsReducer(initialState, actions.PROJECTS_SUCCESS({ projects, parentItemId: undefined }));
expect(state).toEqual([{
+ active: false,
+ open: false,
+ id: "test123",
+ items: [],
+ data: project,
+ status: 0
+ }, {
+ active: false,
+ open: false,
+ id: "test123",
+ items: [],
+ data: project,
+ status: 0
+ }
+ ]);
+ });
+
+ it('should remove activity on projects list', () => {
+ const initialState = [
+ {
+ data: {
+ name: 'test',
+ href: 'href',
+ createdAt: '2018-01-01',
+ modifiedAt: '2018-01-01',
+ ownerUuid: 'owner-test123',
+ uuid: 'test123',
+ kind: 'example'
+ },
+ id: "1",
+ open: true,
+ active: true,
+ status: 1
+ }
+ ];
+ const project = [
+ {
+ data: {
+ name: 'test',
+ href: 'href',
+ createdAt: '2018-01-01',
+ modifiedAt: '2018-01-01',
+ ownerUuid: 'owner-test123',
+ uuid: 'test123',
+ kind: 'example'
+ },
+ id: "1",
+ open: true,
active: false,
- open: false,
- id: "test123",
- items: [],
- data: project,
- status: 0
- }, {
+ status: 1
+ }
+ ];
+
+ const state = projectsReducer(initialState, actions.RESET_PROJECT_TREE_ACTIVITY(initialState[0].id));
+ expect(state).toEqual(project);
+ });
+
+ it('should toggle project tree item activity', () => {
+ const initialState = [
+ {
+ data: {
+ name: 'test',
+ href: 'href',
+ createdAt: '2018-01-01',
+ modifiedAt: '2018-01-01',
+ ownerUuid: 'owner-test123',
+ uuid: 'test123',
+ kind: 'example'
+ },
+ id: "1",
+ open: true,
+ active: false,
+ status: 1
+ }
+ ];
+ const project = [
+ {
+ data: {
+ name: 'test',
+ href: 'href',
+ createdAt: '2018-01-01',
+ modifiedAt: '2018-01-01',
+ ownerUuid: 'owner-test123',
+ uuid: 'test123',
+ kind: 'example'
+ },
+ id: "1",
+ open: true,
+ active: true,
+ status: 1
+ }
+ ];
+
+ const state = projectsReducer(initialState, actions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(initialState[0].id));
+ expect(state).toEqual(project);
+ });
+
+
+ it('should close project tree item ', () => {
+ const initialState = [
+ {
+ data: {
+ name: 'test',
+ href: 'href',
+ createdAt: '2018-01-01',
+ modifiedAt: '2018-01-01',
+ ownerUuid: 'owner-test123',
+ uuid: 'test123',
+ kind: 'example'
+ },
+ id: "1",
+ open: true,
active: false,
+ status: 1,
+ toggled: false,
+ }
+ ];
+ const project = [
+ {
+ data: {
+ name: 'test',
+ href: 'href',
+ createdAt: '2018-01-01',
+ modifiedAt: '2018-01-01',
+ ownerUuid: 'owner-test123',
+ uuid: 'test123',
+ kind: 'example'
+ },
+ id: "1",
open: false,
- id: "test123",
- items: [],
- data: project,
- status: 0
+ active: false,
+ status: 1,
+ toggled: true
}
- ]);
+ ];
+
+ const state = projectsReducer(initialState, actions.TOGGLE_PROJECT_TREE_ITEM_OPEN(initialState[0].id));
+ expect(state).toEqual(project);
});
});
//
// SPDX-License-Identifier: AGPL-3.0
+import * as _ from "lodash";
+
import { Project } from "../../models/project";
import actions, { ProjectAction } from "./project-action";
import { TreeItem, TreeItemStatus } from "../../components/tree/tree";
-import * as _ from "lodash";
export type ProjectState = Array<TreeItem<Project>>;
PROJECTS_SUCCESS: ({ projects, parentItemId }) => {
return updateProjectTree(state, projects, parentItemId);
},
- TOGGLE_PROJECT_TREE_ITEM: itemId => {
+ TOGGLE_PROJECT_TREE_ITEM_OPEN: itemId => {
const tree = _.cloneDeep(state);
- resetTreeActivity(tree);
const item = findTreeItem(tree, itemId);
if (item) {
+ item.toggled = true;
item.open = !item.open;
+ }
+ return tree;
+ },
+ TOGGLE_PROJECT_TREE_ITEM_ACTIVE: itemId => {
+ const tree = _.cloneDeep(state);
+ resetTreeActivity(tree);
+ const item = findTreeItem(tree, itemId);
+ if (item) {
item.active = true;
- item.toggled = true;
}
return tree;
},
+ RESET_PROJECT_TREE_ACTIVITY: () => {
+ const tree = _.cloneDeep(state);
+ resetTreeActivity(tree);
+ return tree;
+ },
default: () => state
});
};
--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { default as unionize, ofType, UnionOf } from "unionize";
+
+const actions = unionize({
+ TOGGLE_SIDE_PANEL_ITEM_OPEN: ofType<string>(),
+ TOGGLE_SIDE_PANEL_ITEM_ACTIVE: ofType<string>(),
+ RESET_SIDE_PANEL_ACTIVITY: ofType<string>(),
+}, {
+ tag: 'type',
+ value: 'payload'
+});
+
+export type SidePanelAction = UnionOf<typeof actions>;
+export default actions;
\ No newline at end of file
--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import sidePanelReducer from "./side-panel-reducer";
+import actions from "./side-panel-action";
+
+describe('side-panel-reducer', () => {
+
+ it('should toggle activity on side-panel', () => {
+ const initialState = [
+ {
+ id: "1",
+ name: "Projects",
+ icon: "fas fa-th fa-fw",
+ open: false,
+ active: false,
+ }
+ ];
+ const project = [
+ {
+ id: "1",
+ name: "Projects",
+ icon: "fas fa-th fa-fw",
+ open: false,
+ active: true,
+ }
+ ];
+
+ const state = sidePanelReducer(initialState, actions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(initialState[0].id));
+ expect(state).toEqual(project);
+ });
+
+ it('should open side-panel item', () => {
+ const initialState = [
+ {
+ id: "1",
+ name: "Projects",
+ icon: "fas fa-th fa-fw",
+ open: false,
+ active: false,
+ }
+ ];
+ const project = [
+ {
+ id: "1",
+ name: "Projects",
+ icon: "fas fa-th fa-fw",
+ open: true,
+ active: false,
+ }
+ ];
+
+ const state = sidePanelReducer(initialState, actions.TOGGLE_SIDE_PANEL_ITEM_OPEN(initialState[0].id));
+ expect(state).toEqual(project);
+ });
+
+ it('should remove activity on side-panel item', () => {
+ const initialState = [
+ {
+ id: "1",
+ name: "Projects",
+ icon: "fas fa-th fa-fw",
+ open: false,
+ active: true,
+ }
+ ];
+ const project = [
+ {
+ id: "1",
+ name: "Projects",
+ icon: "fas fa-th fa-fw",
+ open: false,
+ active: false,
+ }
+ ];
+
+ const state = sidePanelReducer(initialState, actions.RESET_SIDE_PANEL_ACTIVITY(initialState[0].id));
+ expect(state).toEqual(project);
+ });
+});
\ No newline at end of file
--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as _ from "lodash";
+
+import actions, { SidePanelAction } from './side-panel-action';
+import { SidePanelItem } from '../../components/side-panel/side-panel';
+
+export type SidePanelState = SidePanelItem[];
+
+const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePanelAction) => {
+ if (state.length === 0) {
+ return sidePanelData;
+ } else {
+ return actions.match(action, {
+ TOGGLE_SIDE_PANEL_ITEM_OPEN: itemId => state.map(it => itemId === it.id && it.open === false ? {...it, open: true} : {...it, open: false}),
+ TOGGLE_SIDE_PANEL_ITEM_ACTIVE: itemId => {
+ const sidePanel = _.cloneDeep(state);
+ resetSidePanelActivity(sidePanel);
+ sidePanel.map(it => {
+ if (it.id === itemId) {
+ it.active = true;
+ }
+ });
+ return sidePanel;
+ },
+ RESET_SIDE_PANEL_ACTIVITY: () => {
+ const sidePanel = _.cloneDeep(state);
+ resetSidePanelActivity(sidePanel);
+ return sidePanel;
+ },
+ default: () => state
+ });
+ }
+};
+
+export const sidePanelData = [
+ {
+ id: "1",
+ name: "Projects",
+ icon: "fas fa-th fa-fw",
+ open: false,
+ active: false,
+ },
+ {
+ id: "2",
+ name: "Shared with me",
+ icon: "fas fa-users fa-fw",
+ active: false,
+ },
+ {
+ id: "3",
+ name: "Workflows",
+ icon: "fas fa-cogs fa-fw",
+ active: false,
+ },
+ {
+ id: "4",
+ name: "Recent open",
+ icon: "icon-time fa-fw",
+ active: false,
+ },
+ {
+ id: "5",
+ name: "Favorites",
+ icon: "fas fa-star fa-fw",
+ active: false,
+ },
+ {
+ id: "6",
+ name: "Trash",
+ icon: "fas fa-trash-alt fa-fw",
+ active: false,
+ }
+];
+
+function resetSidePanelActivity(sidePanel: SidePanelItem[]) {
+ for (const t of sidePanel) {
+ t.active = false;
+ }
+}
+
+export default sidePanelReducer;
import { routerMiddleware, routerReducer, RouterState } from "react-router-redux";
import thunkMiddleware from 'redux-thunk';
import { History } from "history";
+
import projectsReducer, { ProjectState } from "./project/project-reducer";
+import sidePanelReducer, { SidePanelState } from './side-panel/side-panel-reducer';
import authReducer, { AuthState } from "./auth/auth-reducer";
import collectionsReducer from "./collection/collection-reducer";
const composeEnhancers =
(process.env.NODE_ENV === 'development' &&
- window && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
+ window && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
compose;
export interface RootState {
auth: AuthState;
projects: ProjectState;
router: RouterState;
+ sidePanel: SidePanelState;
}
const rootReducer = combineReducers({
auth: authReducer,
projects: projectsReducer,
collections: collectionsReducer,
- router: routerReducer
+ router: routerReducer,
+ sidePanel: sidePanelReducer
});
uuid: "uuid",
ownerUuid: "ownerUuid",
href: "href",
+ kind: 'example'
},
id: "3",
open: true,
active: true,
status: 1
};
- const wrapper = mount(<ProjectTree projects={[project]} toggleProjectTreeItem={() => { }} />);
+ const wrapper = mount(<ProjectTree projects={[project]} toggleOpen={jest.fn()} toggleActive={jest.fn()} />);
expect(wrapper.find(ListItemIcon)).toHaveLength(1);
});
uuid: "uuid",
ownerUuid: "ownerUuid",
href: "href",
+ kind: 'example'
},
id: "3",
open: false,
uuid: "uuid",
ownerUuid: "ownerUuid",
href: "href",
+ kind: 'example'
},
id: "3",
open: false,
status: 1
}
];
- const wrapper = mount(<ProjectTree projects={project} toggleProjectTreeItem={() => { }} />);
+ const wrapper = mount(<ProjectTree projects={project} toggleOpen={jest.fn()} toggleActive={jest.fn()} />);
expect(wrapper.find(ListItemIcon)).toHaveLength(2);
});
uuid: "uuid",
ownerUuid: "ownerUuid",
href: "href",
+ kind: 'example'
},
id: "3",
open: true,
uuid: "uuid",
ownerUuid: "ownerUuid",
href: "href",
+ kind: 'example'
},
id: "3",
open: true,
]
}
];
- const wrapper = mount(<ProjectTree projects={project} toggleProjectTreeItem={() => { }} />);
+ const wrapper = mount(<ProjectTree projects={project} toggleOpen={jest.fn()} toggleActive={jest.fn()}/>);
expect(wrapper.find(Collapse)).toHaveLength(1);
});
uuid: "uuid",
ownerUuid: "ownerUuid",
href: "href",
+ kind: 'example'
},
id: "3",
open: false,
active: true,
status: 1
};
- const wrapper = mount(<ProjectTree projects={[project]} toggleProjectTreeItem={() => { }} />);
+ const wrapper = mount(<ProjectTree projects={[project]} toggleOpen={jest.fn()} toggleActive={jest.fn()} />);
expect(wrapper.find(CircularProgress)).toHaveLength(1);
});
import Tree, { TreeItem, TreeItemStatus } from '../../components/tree/tree';
import { Project } from '../../models/project';
+export interface ProjectTreeProps {
+ projects: Array<TreeItem<Project>>;
+ toggleOpen: (id: string, status: TreeItemStatus) => void;
+ toggleActive: (id: string, status: TreeItemStatus) => void;
+}
+
+class ProjectTree<T> extends React.Component<ProjectTreeProps & WithStyles<CssRules>> {
+ render(): ReactElement<any> {
+ const { classes, projects, toggleOpen, toggleActive } = this.props;
+ const { active, listItemText, row, treeContainer } = classes;
+ return (
+ <div className={treeContainer}>
+ <Tree items={projects}
+ toggleItemOpen={toggleOpen}
+ toggleItemActive={toggleActive}
+ render={(project: TreeItem<Project>) =>
+ <span className={row}>
+ <ListItemIcon className={project.active ? active : ''}>
+ <i className="fas fa-folder" />
+ </ListItemIcon>
+ <ListItemText className={listItemText} primary={
+ <Typography className={project.active ? active : ''}>{project.data.name}</Typography>
+ } />
+ </span>
+ } />
+ </div>
+ );
+ }
+}
+
type CssRules = 'active' | 'listItemText' | 'row' | 'treeContainer';
const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
marginLeft: '20px',
},
treeContainer: {
- marginTop: '37px',
- overflowX: 'visible',
- overflowY: 'auto',
minWidth: '240px',
whiteSpace: 'nowrap',
+ marginLeft: '13px',
}
});
-export interface ProjectTreeProps {
- projects: Array<TreeItem<Project>>;
- toggleProjectTreeItem: (id: string, status: TreeItemStatus) => void;
-}
-
-class ProjectTree<T> extends React.Component<ProjectTreeProps & WithStyles<CssRules>> {
- render(): ReactElement<any> {
- const {classes, projects} = this.props;
- const {active, listItemText, row, treeContainer} = classes;
- return (
- <div className={treeContainer}>
- <Tree items={projects}
- toggleItem={this.props.toggleProjectTreeItem}
- render={(project: TreeItem<Project>, level: number) =>
- <span className={row}>
- <ListItemIcon className={project.active ? active : ''}>
- {level === 0 ? <i className="fas fa-th"/> : <i className="fas fa-folder"/>}
- </ListItemIcon>
- <ListItemText className={listItemText} primary={
- <Typography className={project.active ? active : ''}>
- {project.data.name}
- </Typography>
- }/>
- </span>
- }/>
- </div>
- );
- }
-}
-
export default withStyles(styles)(ProjectTree);
it('renders without crashing', () => {
const div = document.createElement('div');
- const store = configureStore({ projects: [], router: { location: null }, auth: {} }, createBrowserHistory());
+ const store = configureStore({ projects: [], router: { location: null }, auth: {}, sidePanel: [] }, createBrowserHistory());
ReactDOM.render(
<Provider store={store}>
<ConnectedRouter history={history}>
// SPDX-License-Identifier: AGPL-3.0
import * as React from 'react';
-
import { StyleRulesCallback, Theme, WithStyles, withStyles } from '@material-ui/core/styles';
import Drawer from '@material-ui/core/Drawer';
import { connect, DispatchProp } from "react-redux";
import { Project } from "../../models/project";
import { getTreePath } from '../../store/project/project-reducer';
import ProjectPanel from '../project-panel/project-panel';
+import sidePanelActions from '../../store/side-panel/side-panel-action';
+import { projectService } from '../../services/services';
+import SidePanel, { SidePanelItem } from '../../components/side-panel/side-panel';
const drawerWidth = 240;
const appBarHeight = 102;
drawerPaper: {
position: 'relative',
width: drawerWidth,
+ display: 'flex',
+ flexDirection: 'column',
},
contentWrapper: {
backgroundColor: theme.palette.background.default,
interface WorkbenchDataProps {
projects: Array<TreeItem<Project>>;
user?: User;
+ sidePanelItems: SidePanelItem[];
}
interface WorkbenchActionProps {
mainAppBarActions: MainAppBarActionProps = {
onBreadcrumbClick: ({ itemId, status }: NavBreadcrumb) => {
- this.toggleProjectTreeItem(itemId, status);
+ this.toggleProjectTreeItemOpen(itemId, status);
},
onSearch: searchText => {
this.setState({ searchText });
onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action()
};
- toggleProjectTreeItem = (itemId: string, status: TreeItemStatus) => {
+ toggleProjectTreeItemOpen = (itemId: string, status: TreeItemStatus) => {
if (status === TreeItemStatus.Loaded) {
this.openProjectItem(itemId);
+ this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(itemId));
+ this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
} else {
this.props.dispatch<any>(getProjectList(itemId))
- .then(() => this.openProjectItem(itemId));
+ .then(() => {
+ this.openProjectItem(itemId);
+ this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(itemId));
+ this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
+ });
}
}
+ toggleProjectTreeItemActive = (itemId: string, status: TreeItemStatus) => {
+ if (status === TreeItemStatus.Loaded) {
+ this.openProjectItem(itemId);
+ this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
+ this.props.dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY(itemId));
+ } else {
+ this.props.dispatch<any>(getProjectList(itemId))
+ .then(() => {
+ this.openProjectItem(itemId);
+ this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
+ this.props.dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY(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));
+ }
+
openProjectItem = (itemId: string) => {
const branch = getTreePath(this.props.projects, itemId);
this.setState({
status: item.status
}))
});
- this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM(itemId));
+ this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
this.props.dispatch(push(`/project/${itemId}`));
}
render() {
- const { classes, user } = this.props;
+ const { classes, user, projects, sidePanelItems } = this.props;
return (
<div className={classes.root}>
<div className={classes.appBar}>
paper: classes.drawerPaper,
}}>
<div className={classes.toolbar} />
- <ProjectTree
- projects={this.props.projects}
- toggleProjectTreeItem={this.toggleProjectTreeItem} />
+ <SidePanel
+ toggleOpen={this.toggleSidePanelOpen}
+ toggleActive={this.toggleSidePanelActive}
+ sidePanelItems={sidePanelItems}>
+ <ProjectTree
+ projects={projects}
+ toggleOpen={this.toggleProjectTreeItemOpen}
+ toggleActive={this.toggleProjectTreeItemActive} />
+ </SidePanel>
</Drawer>}
<main className={classes.contentWrapper}>
<div className={classes.content}>
export default connect<WorkbenchDataProps>(
(state: RootState) => ({
projects: state.projects,
- user: state.auth.user
+ user: state.auth.user,
+ sidePanelItems: state.sidePanel,
})
)(
withStyles(styles)(Workbench)