import { ThunkAction } from "../../../node_modules/redux-thunk";
const actions = unionize({
- OPEN_PROJECT_CREATOR: ofType<{}>(),
+ OPEN_PROJECT_CREATOR: ofType<{ownerUuid: string}>(),
+ CLOSE_PROJECT_CREATOR: ofType<{}>(),
CREATE_PROJECT: ofType<Partial<ProjectResource>>(),
CREATE_PROJECT_SUCCESS: ofType<ProjectResource>(),
CREATE_PROJECT_ERROR: ofType<string>(),
status: 1
}],
currentItemId: "1",
- creator: { opened: false, pending: false },
+ creator: { opened: false, pending: false, ownerUuid: "" },
};
const project = {
items: [{
status: 1
}],
currentItemId: "1",
- creator: { opened: false, pending: false }
+ creator: { opened: false, pending: false, ownerUuid: "" }
};
const project = {
items: [{
toggled: true
}],
currentItemId: "1",
- creator: { opened: false, pending: false },
+ creator: { opened: false, pending: false, ownerUuid: "" },
};
const state = projectsReducer(initialState, actions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(initialState.items[0].id));
toggled: false,
}],
currentItemId: "1",
- creator: { opened: false, pending: false }
+ creator: { opened: false, pending: false, ownerUuid: "" }
};
const project = {
items: [{
toggled: true
}],
currentItemId: "1",
- creator: { opened: false, pending: false },
+ creator: { opened: false, pending: false, ownerUuid: "" },
};
const state = projectsReducer(initialState, actions.TOGGLE_PROJECT_TREE_ITEM_OPEN(initialState.items[0].id));
export type ProjectState = {
items: Array<TreeItem<Project>>,
currentItemId: string,
- creator: {
- opened: boolean,
- pending: boolean
- }
+ creator: ProjectCreator
};
+interface ProjectCreator {
+ opened: boolean;
+ pending: boolean;
+ ownerUuid: string;
+}
+
export function findTreeItem<T>(tree: Array<TreeItem<T>>, itemId: string): TreeItem<T> | undefined {
let item;
for (const t of tree) {
return items;
}
+const updateCreator = (state: ProjectState, creator: Partial<ProjectCreator>) => ({
+ ...state,
+ creator: {
+ ...state.creator,
+ ...creator
+ }
+});
+
const initialState: ProjectState = {
items: [],
currentItemId: "",
creator: {
opened: false,
- pending: false
+ pending: false,
+ ownerUuid: ""
}
};
const projectsReducer = (state: ProjectState = initialState, action: ProjectAction) => {
return actions.match(action, {
- OPEN_PROJECT_CREATOR: () => ({ ...state, creator: { opened: true, pending: false } }),
- CREATE_PROJECT: () => ({ ...state, creator: { opened: false, pending: true } }),
- CREATE_PROJECT_SUCCESS: () => ({ ...state, creator: { opened: false, pending: false } }),
- CREATE_PROJECT_ERROR: () => ({ ...state, creator: { opened: false, pending: false } }),
+ OPEN_PROJECT_CREATOR: ({ ownerUuid }) => updateCreator(state, { ownerUuid, opened: true, pending: false }),
+ CLOSE_PROJECT_CREATOR: () => updateCreator(state, { opened: false }),
+ CREATE_PROJECT: () => updateCreator(state, { pending: true }),
+ CREATE_PROJECT_SUCCESS: () => updateCreator(state, { ownerUuid: "", pending: false }),
+ CREATE_PROJECT_ERROR: () => updateCreator(state, { ownerUuid: "", pending: false }),
REMOVE_PROJECT: () => state,
PROJECTS_REQUEST: itemId => {
const items = _.cloneDeep(state.items);
item.open = !item.open;
}
return {
+ ...state,
items,
currentItemId: itemId
};
item.active = true;
}
return {
+ ...state,
items,
currentItemId: itemId
};
const items = _.cloneDeep(state.items);
resetTreeActivity(items);
return {
+ ...state,
items,
currentItemId: ""
};
--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { connect } from "react-redux";
+import { Dispatch } from "../../../node_modules/redux";
+import { RootState } from "../../store/store";
+import DialogProjectCreate from "../../components/dialog-create/dialog-project-create";
+import actions from "../../store/project/project-action";
+
+const mapStateToProps = (state: RootState) => ({
+ open: state.projects.creator.opened
+});
+
+const mapDispatchToProps = (dispatch: Dispatch) => ({
+ handleClose: () => {
+ dispatch(actions.CLOSE_PROJECT_CREATOR());
+ }
+});
+
+export default connect(mapStateToProps, mapDispatchToProps)(DialogProjectCreate);
onItemClick: (item: ProjectPanelItem) => void,
onItemRouteChange: (itemId: string) => void,
onContextMenu: (event: React.MouseEvent<HTMLElement>, item: ProjectPanelItem) => void;
- onDialogOpen: () => void;
+ onDialogOpen: (ownerUuid: string) => void;
}
& DispatchProp
& WithStyles<CssRules>
<Button color="primary" variant="raised" className={this.props.classes.button}>
Run a process
</Button>
- <Button color="primary" onClick={this.props.onDialogOpen} variant="raised" className={this.props.classes.button}>
+ <Button color="primary" onClick={() => this.props.onDialogOpen(this.props.currentItemId)} variant="raised" className={this.props.classes.button}>
New project
</Button>
</div>
import { ArvadosTheme } from '../../common/custom-theme';
import ContextMenu, { ContextMenuAction } from '../../components/context-menu/context-menu';
import { mockAnchorFromMouseEvent } from '../../components/popover/helpers';
-import DialogProjectCreate from '../../components/dialog-create/dialog-project-create';
+import CreateProjectDialog from "../../views-components/create-project-dialog/create-project-dialog";
+import { authService } from '../../services/services';
+
const drawerWidth = 240;
const appBarHeight = 100;
interface WorkbenchState {
contextMenu: {
anchorEl?: HTMLElement;
+ itemUuid?: string;
};
- isCreationDialogOpen: boolean;
anchorEl: any;
searchText: string;
menuItems: {
class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
state = {
contextMenu: {
- anchorEl: undefined
+ anchorEl: undefined,
+ itemUuid: undefined
},
isCreationDialogOpen: false,
anchorEl: null,
onDetailsPanelToggle: () => {
this.setState(prev => ({ isDetailsPanelOpened: !prev.isDetailsPanelOpened }));
},
- onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: Breadcrumb) => {
- this.openContextMenu(event, breadcrumb);
+ onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: NavBreadcrumb) => {
+ this.openContextMenu(event, breadcrumb.itemId);
}
};
this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
}
- handleCreationDialogOpen = () => {
+ handleCreationDialogOpen = (itemUuid: string) => {
this.closeContextMenu();
- this.setState({ isCreationDialogOpen: true });
+ this.props.dispatch(projectActions.OPEN_PROJECT_CREATOR({ ownerUuid: itemUuid }));
}
- handleCreationDialogClose = () => {
- this.setState({ isCreationDialogOpen: false });
- }
- openContextMenu = (event: React.MouseEvent<HTMLElement>, item: any) => {
+ openContextMenu = (event: React.MouseEvent<HTMLElement>, itemUuid: string) => {
event.preventDefault();
- this.setState({ contextMenu: { anchorEl: mockAnchorFromMouseEvent(event) } });
- console.log(item);
+ this.setState({
+ contextMenu: {
+ anchorEl: mockAnchorFromMouseEvent(event),
+ itemUuid
+ }
+ });
}
closeContextMenu = () => {
this.setState({ contextMenu: {} });
}
- openCreateDialog = (item: ContextMenuAction) =>
- item.openCreateDialog ? this.handleCreationDialogOpen() : void 0
+ openCreateDialog = (item: ContextMenuAction) => {
+ const { itemUuid } = this.state.contextMenu;
+ if (item.openCreateDialog && itemUuid) {
+ this.handleCreationDialogOpen(itemUuid);
+ }
+ }
render() {
const path = getTreePath(this.props.projects, this.props.currentProjectId);
toggleOpen={this.toggleSidePanelOpen}
toggleActive={this.toggleSidePanelActive}
sidePanelItems={this.props.sidePanelItems}
- onContextMenu={this.openContextMenu}>
+ onContextMenu={(event) => this.openContextMenu(event, authService.getUuid() || "")}>
<ProjectTree
projects={this.props.projects}
toggleOpen={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.OPEN))}
toggleActive={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
- onContextMenu={this.openContextMenu} />
+ onContextMenu={(event, item) => this.openContextMenu(event, item.data.uuid)} />
</SidePanel>
</Drawer>}
<main className={classes.contentWrapper}>
actions={contextMenuActions}
onActionClick={this.openCreateDialog}
onClose={this.closeContextMenu} />
- <DialogProjectCreate open={this.state.isCreationDialogOpen} handleClose={this.handleCreationDialogClose} />
+ <CreateProjectDialog />
</div>
);
}
renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => <ProjectPanel
onItemRouteChange={itemId => this.props.dispatch<any>(setProjectItem(itemId, ItemMode.ACTIVE))}
onItemClick={item => this.props.dispatch<any>(setProjectItem(item.uuid, ItemMode.ACTIVE))}
- onContextMenu={this.openContextMenu}
+ onContextMenu={(event, item) => this.openContextMenu(event, item.uuid)}
onDialogOpen={this.handleCreationDialogOpen}
{...props} />
}