[ARVADOS-WORKBENCH2] created: 1.2.0-489-g847ac07
Git user
git at public.curoverse.com
Fri Sep 28 08:37:37 EDT 2018
at 847ac07f82a1432d6472390aab5e8c2198d425a5 (commit)
commit 847ac07f82a1432d6472390aab5e8c2198d425a5
Merge: 1223a1b 3b31cd1
Author: Pawel Kowalczyk <pawel.kowalczyk at contractors.roche.com>
Date: Fri Sep 28 14:37:13 2018 +0200
workflow-file-selection
Feature #14231
Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk <pawel.kowalczyk at contractors.roche.com>
diff --cc src/store/store.ts
index ab4b851,21e5029..c0e0b6b
--- a/src/store/store.ts
+++ b/src/store/store.ts
@@@ -35,9 -35,9 +35,10 @@@ import { processPanelReducer } from '~/
import { SHARED_WITH_ME_PANEL_ID } from '~/store/shared-with-me-panel/shared-with-me-panel-actions';
import { SharedWithMeMiddlewareService } from './shared-with-me-panel/shared-with-me-middleware-service';
import { progressIndicatorReducer } from './progress-indicator/progress-indicator-reducer';
+ import { runProcessPanelReducer } from '~/store/run-process-panel/run-process-panel-reducer';
import { WorkflowMiddlewareService } from './workflow-panel/workflow-middleware-service';
import { WORKFLOW_PANEL_ID } from './workflow-panel/workflow-panel-actions';
+import { workflowTreePickerReducer } from './workflow-tree-picker/workflow-tree-picker-reducer';
const composeEnhancers =
(process.env.NODE_ENV === 'development' &&
@@@ -99,5 -99,5 +100,6 @@@ const createRootReducer = (services: Se
fileUploader: fileUploaderReducer,
processPanel: processPanelReducer,
progressIndicator: progressIndicatorReducer,
- workflowTreePicker: workflowTreePickerReducer
++ workflowTreePicker: workflowTreePickerReducer,
+ runProcessPanel: runProcessPanelReducer
});
diff --cc src/store/workbench/workbench-actions.ts
index 8f034ec,2586fdc..bd480bd
--- a/src/store/workbench/workbench-actions.ts
+++ b/src/store/workbench/workbench-actions.ts
@@@ -46,6 -46,7 +46,8 @@@ import { ResourceKind, extractUuidKind
import { FilterBuilder } from '~/services/api/filter-builder';
import { GroupContentsResource } from '~/services/groups-service/groups-service';
import { unionize, ofType, UnionOf, MatchCases } from '~/common/unionize';
+ import { loadRunProcessPanel } from '~/store/run-process-panel/run-process-panel-actions';
++import { loadCollectionFiles } from '~/store/collection-panel/collection-panel-files/collection-panel-files-actions';
export const WORKBENCH_LOADING_SCREEN = 'workbenchLoadingScreen';
@@@ -197,16 -198,16 +199,19 @@@ export const loadCollection = (uuid: st
dispatch(updateResources([collection]));
await dispatch(activateSidePanelTreeItem(collection.ownerUuid));
dispatch(setSidePanelBreadcrumbs(collection.ownerUuid));
++ dispatch(loadCollectionFiles(collection.uuid));
},
SHARED: collection => {
dispatch(updateResources([collection]));
dispatch<any>(setSharedWithMeBreadcrumbs(collection.ownerUuid));
dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
++ dispatch(loadCollectionFiles(collection.uuid));
},
TRASHED: collection => {
dispatch(updateResources([collection]));
dispatch(setTrashBreadcrumbs(''));
dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
++ dispatch(loadCollectionFiles(collection.uuid));
},
});
diff --cc src/views-components/workflow-tree-picker/workflow-tree-picker.tsx
index 1dd8c10,0000000..f9db4ea
mode 100644,000000..100644
--- a/src/views-components/workflow-tree-picker/workflow-tree-picker.tsx
+++ b/src/views-components/workflow-tree-picker/workflow-tree-picker.tsx
@@@ -1,156 -1,0 +1,170 @@@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from "react";
+import { Dispatch } from "redux";
+import { connect } from "react-redux";
+import { Typography } from "@material-ui/core";
+import { MainWorkflowTreePicker, MainWorkflowTreePickerProps } from "./main-workflow-tree-picker";
+import { TreeItem, TreeItemStatus } from "~/components/tree/tree";
+import { ProjectResource } from "~/models/project";
+import { workflowTreePickerActions } from "~/store/workflow-tree-picker/workflow-tree-picker-actions";
+import { ListItemTextIcon } from "~/components/list-item-text-icon/list-item-text-icon";
- import { ProjectIcon, FavoriteIcon, ProjectsIcon, ShareMeIcon } from "~/components/icon/icon";
++import { ProjectIcon, FavoriteIcon, ProjectsIcon, ShareMeIcon, CollectionIcon } from '~/components/icon/icon';
+import { createTreePickerNode } from "~/store/tree-picker/tree-picker";
+import { RootState } from "~/store/store";
+import { ServiceRepository } from "~/services/services";
+import { FilterBuilder } from "~/services/api/filter-builder";
+import { WrappedFieldProps } from 'redux-form';
++import { ResourceKind } from '~/models/resource';
++import { GroupContentsResource } from '~/services/groups-service/groups-service';
+
+type WorkflowTreePickerProps = Pick<MainWorkflowTreePickerProps, 'onContextMenu' | 'toggleItemActive' | 'toggleItemOpen'>;
+
+const mapDispatchToProps = (dispatch: Dispatch, props: { onChange: (projectUuid: string) => void }): WorkflowTreePickerProps => ({
+ onContextMenu: () => { return; },
+ toggleItemActive: (nodeId, status, pickerId) => {
+ getNotSelectedTreePickerKind(pickerId)
+ .forEach(pickerId => dispatch(workflowTreePickerActions.TOGGLE_TREE_PICKER_NODE_SELECT({ nodeId: '', pickerId })));
+ dispatch(workflowTreePickerActions.TOGGLE_TREE_PICKER_NODE_SELECT({ nodeId, pickerId }));
+
+ props.onChange(nodeId);
+ },
+ toggleItemOpen: (nodeId, status, pickerId) => {
+ dispatch<any>(toggleItemOpen(nodeId, status, pickerId));
+ }
+});
+
+const toggleItemOpen = (nodeId: string, status: TreeItemStatus, pickerId: string) =>
+ (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+ if (status === TreeItemStatus.INITIAL) {
+ if (pickerId === TreePickerId.PROJECTS) {
- dispatch<any>(loadProjectTreePickerProjects(nodeId));
++ dispatch<any>(loadProjectTreePicker(nodeId));
+ } else if (pickerId === TreePickerId.FAVORITES) {
- dispatch<any>(loadFavoriteTreePickerProjects(nodeId === services.authService.getUuid() ? '' : nodeId));
++ dispatch<any>(loadFavoriteTreePicker(nodeId === services.authService.getUuid() ? '' : nodeId));
+ } else {
+ // TODO: load sharedWithMe
+ }
+ } else {
+ dispatch(workflowTreePickerActions.TOGGLE_TREE_PICKER_NODE_COLLAPSE({ nodeId, pickerId }));
+ }
+ };
+
+const getNotSelectedTreePickerKind = (pickerId: string) => {
+ return [TreePickerId.PROJECTS, TreePickerId.FAVORITES, TreePickerId.SHARED_WITH_ME].filter(nodeId => nodeId !== pickerId);
+};
+
+export enum TreePickerId {
+ PROJECTS = 'Projects',
+ SHARED_WITH_ME = 'Shared with me',
+ FAVORITES = 'Favorites'
+}
+
+export const WorkflowTreePicker = connect(undefined, mapDispatchToProps)((props: WorkflowTreePickerProps) =>
+ <div style={{ display: 'flex', flexDirection: 'column' }}>
+ <Typography variant='caption' style={{ flexShrink: 0 }}>
+ Select a project
+ </Typography>
+ <div style={{ flexGrow: 1, overflow: 'auto' }}>
+ <MainWorkflowTreePicker {...props} render={renderTreeItem} pickerId={TreePickerId.PROJECTS} />
+ <MainWorkflowTreePicker {...props} render={renderTreeItem} pickerId={TreePickerId.SHARED_WITH_ME} />
+ <MainWorkflowTreePicker {...props} render={renderTreeItem} pickerId={TreePickerId.FAVORITES} />
+ </div>
+ </div>);
+
- export const loadProjectTreePickerProjects = (nodeId: string) =>
++export const loadProjectTreePicker = (nodeId: string) =>
+ async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+ dispatch(workflowTreePickerActions.LOAD_TREE_PICKER_NODE({ nodeId, pickerId: TreePickerId.PROJECTS }));
+
+ const ownerUuid = nodeId.length === 0 ? services.authService.getUuid() || '' : nodeId;
+
+ const filters = new FilterBuilder()
++ .addIsA("uuid", [ResourceKind.PROJECT, ResourceKind.COLLECTION])
+ .addEqual('ownerUuid', ownerUuid)
+ .getFilters();
+
- const { items } = await services.projectService.list({ filters });
++ const { items } = await services.groupsService.contents(ownerUuid, { filters });
+
+ dispatch<any>(receiveTreePickerData(nodeId, items, TreePickerId.PROJECTS));
+ };
+
- export const loadFavoriteTreePickerProjects = (nodeId: string) =>
++export const loadFavoriteTreePicker = (nodeId: string) =>
+ async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+ const parentId = services.authService.getUuid() || '';
+
+ if (nodeId === '') {
+ dispatch(workflowTreePickerActions.LOAD_TREE_PICKER_NODE({ nodeId: parentId, pickerId: TreePickerId.FAVORITES }));
+ const { items } = await services.favoriteService.list(parentId);
+
+ dispatch<any>(receiveTreePickerData(parentId, items as ProjectResource[], TreePickerId.FAVORITES));
+ } else {
+ dispatch(workflowTreePickerActions.LOAD_TREE_PICKER_NODE({ nodeId, pickerId: TreePickerId.FAVORITES }));
+ const filters = new FilterBuilder()
+ .addEqual('ownerUuid', nodeId)
+ .getFilters();
+
- const { items } = await services.projectService.list({ filters });
++ const { items } = await services.groupsService.contents(parentId, { filters });
+
+ dispatch<any>(receiveTreePickerData(nodeId, items, TreePickerId.FAVORITES));
+ }
-
+ };
+
+const getProjectPickerIcon = (item: TreeItem<ProjectResource>) => {
++ console.log(item);
+ switch (item.data.name) {
+ case TreePickerId.FAVORITES:
+ return FavoriteIcon;
+ case TreePickerId.PROJECTS:
+ return ProjectsIcon;
+ case TreePickerId.SHARED_WITH_ME:
+ return ShareMeIcon;
+ default:
++ return getResourceIcon(item);
++ }
++};
++
++const getResourceIcon = (item: TreeItem<GroupContentsResource>) => {
++ switch (item.data.kind) {
++ case ResourceKind.COLLECTION:
++ return CollectionIcon;
++ case ResourceKind.PROJECT:
++ return ProjectsIcon;
++ default:
+ return ProjectIcon;
+ }
+};
+
+const renderTreeItem = (item: TreeItem<ProjectResource>) =>
+ <ListItemTextIcon
+ icon={getProjectPickerIcon(item)}
+ name={item.data.name}
+ isActive={item.active}
+ hasMargin={true} />;
+
+
- export const receiveTreePickerData = (nodeId: string, projects: ProjectResource[], pickerId: string) =>
++export const receiveTreePickerData = (nodeId: string, items: GroupContentsResource[], pickerId: string) =>
+ (dispatch: Dispatch) => {
+ dispatch(workflowTreePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({
+ nodeId,
- nodes: projects.map(project => createTreePickerNode({ nodeId: project.uuid, value: project })),
++ nodes: items.map(item => createTreePickerNode({ nodeId: item.uuid, value: item })),
+ pickerId,
+ }));
+
+ dispatch(workflowTreePickerActions.TOGGLE_TREE_PICKER_NODE_COLLAPSE({ nodeId, pickerId }));
+ };
+
+export const WorkflowTreePickerField = (props: WrappedFieldProps) =>
+ <div style={{ height: '200px', display: 'flex', flexDirection: 'column' }}>
+ <WorkflowTreePicker onChange={handleChange(props)} />
+ {props.meta.dirty && props.meta.error &&
+ <Typography variant='caption' color='error'>
+ {props.meta.error}
+ </Typography>}
+ </div>;
+
+const handleChange = (props: WrappedFieldProps) => (value: string) =>
+ props.input.value === value
+ ? props.input.onChange('')
+ : props.input.onChange(value);
+
commit 1223a1b7def439123f2950a6f4627a170483e779
Author: Pawel Kowalczyk <pawel.kowalczyk at contractors.roche.com>
Date: Fri Sep 28 13:01:58 2018 +0200
init-file-selection-tree
Feature #14231
Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk <pawel.kowalczyk at contractors.roche.com>
diff --git a/src/store/store.ts b/src/store/store.ts
index 16d0d05..ab4b851 100644
--- a/src/store/store.ts
+++ b/src/store/store.ts
@@ -37,6 +37,7 @@ import { SharedWithMeMiddlewareService } from './shared-with-me-panel/shared-wit
import { progressIndicatorReducer } from './progress-indicator/progress-indicator-reducer';
import { WorkflowMiddlewareService } from './workflow-panel/workflow-middleware-service';
import { WORKFLOW_PANEL_ID } from './workflow-panel/workflow-panel-actions';
+import { workflowTreePickerReducer } from './workflow-tree-picker/workflow-tree-picker-reducer';
const composeEnhancers =
(process.env.NODE_ENV === 'development' &&
@@ -97,5 +98,6 @@ const createRootReducer = (services: ServiceRepository) => combineReducers({
treePicker: treePickerReducer,
fileUploader: fileUploaderReducer,
processPanel: processPanelReducer,
- progressIndicator: progressIndicatorReducer
+ progressIndicator: progressIndicatorReducer,
+ workflowTreePicker: workflowTreePickerReducer
});
diff --git a/src/store/workflow-tree-picker/workflow-tree-picker-actions.ts b/src/store/workflow-tree-picker/workflow-tree-picker-actions.ts
new file mode 100644
index 0000000..6fd66ec
--- /dev/null
+++ b/src/store/workflow-tree-picker/workflow-tree-picker-actions.ts
@@ -0,0 +1,18 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { unionize, ofType, UnionOf } from "~/common/unionize";
+
+import { TreePickerNode } from "./workflow-tree-picker";
+
+export const workflowTreePickerActions = unionize({
+ LOAD_TREE_PICKER_NODE: ofType<{ nodeId: string, pickerId: string }>(),
+ LOAD_TREE_PICKER_NODE_SUCCESS: ofType<{ nodeId: string, nodes: Array<TreePickerNode>, pickerId: string }>(),
+ TOGGLE_TREE_PICKER_NODE_COLLAPSE: ofType<{ nodeId: string, pickerId: string }>(),
+ TOGGLE_TREE_PICKER_NODE_SELECT: ofType<{ nodeId: string, pickerId: string }>(),
+ EXPAND_TREE_PICKER_NODES: ofType<{ nodeIds: string[], pickerId: string }>(),
+ RESET_TREE_PICKER: ofType<{ pickerId: string }>()
+});
+
+export type WorkflowTreePickerAction = UnionOf<typeof workflowTreePickerActions>;
diff --git a/src/store/workflow-tree-picker/workflow-tree-picker-reducer.ts b/src/store/workflow-tree-picker/workflow-tree-picker-reducer.ts
new file mode 100644
index 0000000..a0c2d48
--- /dev/null
+++ b/src/store/workflow-tree-picker/workflow-tree-picker-reducer.ts
@@ -0,0 +1,73 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { createTree, setNodeValueWith, TreeNode, setNode, mapTreeValues, Tree } from "~/models/tree";
+import { TreePicker, TreePickerNode } from "./workflow-tree-picker";
+import { workflowTreePickerActions, WorkflowTreePickerAction } from "./workflow-tree-picker-actions";
+import { TreeItemStatus } from "~/components/tree/tree";
+import { compose } from "redux";
+import { getNode } from '~/models/tree';
+
+export const workflowTreePickerReducer = (state: TreePicker = {}, action: WorkflowTreePickerAction) =>
+ workflowTreePickerActions.match(action, {
+ LOAD_TREE_PICKER_NODE: ({ nodeId, pickerId }) =>
+ updateOrCreatePicker(state, pickerId, setNodeValueWith(setPending)(nodeId)),
+ LOAD_TREE_PICKER_NODE_SUCCESS: ({ nodeId, nodes, pickerId }) =>
+ updateOrCreatePicker(state, pickerId, compose(receiveNodes(nodes)(nodeId), setNodeValueWith(setLoaded)(nodeId))),
+ TOGGLE_TREE_PICKER_NODE_COLLAPSE: ({ nodeId, pickerId }) =>
+ updateOrCreatePicker(state, pickerId, setNodeValueWith(toggleCollapse)(nodeId)),
+ TOGGLE_TREE_PICKER_NODE_SELECT: ({ nodeId, pickerId }) =>
+ updateOrCreatePicker(state, pickerId, mapTreeValues(toggleSelect(nodeId))),
+ RESET_TREE_PICKER: ({ pickerId }) =>
+ updateOrCreatePicker(state, pickerId, createTree),
+ EXPAND_TREE_PICKER_NODES: ({ pickerId, nodeIds }) =>
+ updateOrCreatePicker(state, pickerId, mapTreeValues(expand(nodeIds))),
+ default: () => state
+ });
+
+const updateOrCreatePicker = (state: TreePicker, pickerId: string, func: (value: Tree<TreePickerNode>) => Tree<TreePickerNode>) => {
+ const picker = state[pickerId] || createTree();
+ const updatedPicker = func(picker);
+ return { ...state, [pickerId]: updatedPicker };
+};
+
+const expand = (ids: string[]) => (node: TreePickerNode): TreePickerNode =>
+ ids.some(id => id === node.nodeId)
+ ? { ...node, collapsed: false }
+ : node;
+
+const setPending = (value: TreePickerNode): TreePickerNode =>
+ ({ ...value, status: TreeItemStatus.PENDING });
+
+const setLoaded = (value: TreePickerNode): TreePickerNode =>
+ ({ ...value, status: TreeItemStatus.LOADED });
+
+const toggleCollapse = (value: TreePickerNode): TreePickerNode =>
+ ({ ...value, collapsed: !value.collapsed });
+
+const toggleSelect = (nodeId: string) => (value: TreePickerNode): TreePickerNode =>
+ value.nodeId === nodeId
+ ? ({ ...value, selected: !value.selected })
+ : ({ ...value, selected: false });
+
+const receiveNodes = (nodes: Array<TreePickerNode>) => (parent: string) => (state: Tree<TreePickerNode>) => {
+ const parentNode = getNode(parent)(state);
+ let newState = state;
+ if (parentNode) {
+ newState = setNode({ ...parentNode, children: [] })(state);
+ }
+ return nodes.reduce((tree, node) => {
+ const oldNode = getNode(node.nodeId)(state) || { value: {} };
+ const newNode = createTreeNode(parent)(node);
+ const value = { ...oldNode.value, ...newNode.value };
+ return setNode({ ...newNode, value })(tree);
+ }, newState);
+};
+
+const createTreeNode = (parent: string) => (node: TreePickerNode): TreeNode<TreePickerNode> => ({
+ children: [],
+ id: node.nodeId,
+ parent,
+ value: node
+});
diff --git a/src/store/workflow-tree-picker/workflow-tree-picker.ts b/src/store/workflow-tree-picker/workflow-tree-picker.ts
new file mode 100644
index 0000000..259a4b8
--- /dev/null
+++ b/src/store/workflow-tree-picker/workflow-tree-picker.ts
@@ -0,0 +1,25 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { Tree } from "~/models/tree";
+import { TreeItemStatus } from "~/components/tree/tree";
+
+export type TreePicker = { [key: string]: Tree<TreePickerNode> };
+
+export interface TreePickerNode<Value = any> {
+ nodeId: string;
+ value: Value;
+ selected: boolean;
+ collapsed: boolean;
+ status: TreeItemStatus;
+}
+
+export const createTreePickerNode = (data: { nodeId: string, value: any }) => ({
+ ...data,
+ selected: false,
+ collapsed: true,
+ status: TreeItemStatus.INITIAL
+});
+
+export const getTreePicker = <Value = {}>(id: string) => (state: TreePicker): Tree<TreePickerNode<Value>> | undefined => state[id];
\ No newline at end of file
diff --git a/src/views-components/dialog-move/dialog-move-to.tsx b/src/views-components/dialog-move/dialog-move-to.tsx
index 425b9e4..6b0ac88 100644
--- a/src/views-components/dialog-move/dialog-move-to.tsx
+++ b/src/views-components/dialog-move/dialog-move-to.tsx
@@ -6,7 +6,7 @@ import * as React from "react";
import { InjectedFormProps, Field } from 'redux-form';
import { WithDialogProps } from '~/store/dialog/with-dialog';
import { FormDialog } from '~/components/form-dialog/form-dialog';
-import { ProjectTreePickerField } from '~/views-components/project-tree-picker/project-tree-picker';
+import { WorkflowTreePickerField } from '~/views-components/workflow-tree-picker/workflow-tree-picker';
import { MOVE_TO_VALIDATION } from '~/validators/validators';
import { MoveToFormDialogData } from '~/store/move-to-dialog/move-to-dialog';
@@ -21,6 +21,6 @@ export const DialogMoveTo = (props: WithDialogProps<string> & InjectedFormProps<
const MoveToDialogFields = () =>
<Field
name="ownerUuid"
- component={ProjectTreePickerField}
+ component={WorkflowTreePickerField}
validate={MOVE_TO_VALIDATION} />;
diff --git a/src/views-components/workflow-tree-picker/main-workflow-tree-picker.ts b/src/views-components/workflow-tree-picker/main-workflow-tree-picker.ts
new file mode 100644
index 0000000..4868160
--- /dev/null
+++ b/src/views-components/workflow-tree-picker/main-workflow-tree-picker.ts
@@ -0,0 +1,57 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { connect } from "react-redux";
+import { Tree, TreeProps, TreeItem, TreeItemStatus } from "~/components/tree/tree";
+import { RootState } from "~/store/store";
+import { createTreePickerNode, TreePickerNode } from "~/store/workflow-tree-picker/workflow-tree-picker";
+import { getNodeValue, getNodeChildrenIds, Tree as Ttree, createTree } from "~/models/tree";
+import { Dispatch } from "redux";
+
+export interface MainWorkflowTreePickerProps {
+ pickerId: string;
+ onContextMenu: (event: React.MouseEvent<HTMLElement>, nodeId: string, pickerId: string) => void;
+ toggleItemOpen: (nodeId: string, status: TreeItemStatus, pickerId: string) => void;
+ toggleItemActive: (nodeId: string, status: TreeItemStatus, pickerId: string) => void;
+}
+
+const memoizedMapStateToProps = () => {
+ let prevTree: Ttree<TreePickerNode>;
+ let mappedProps: Pick<TreeProps<any>, 'items'>;
+ return (state: RootState, props: MainWorkflowTreePickerProps): Pick<TreeProps<any>, 'items'> => {
+ const tree = state.treePicker[props.pickerId] || createTree();
+ if(tree !== prevTree){
+ prevTree = tree;
+ mappedProps = {
+ items: getNodeChildrenIds('')(tree)
+ .map(treePickerToTreeItems(tree))
+ };
+ }
+ return mappedProps;
+ };
+};
+
+const mapDispatchToProps = (dispatch: Dispatch, props: MainWorkflowTreePickerProps): Pick<TreeProps<any>, 'onContextMenu' | 'toggleItemOpen' | 'toggleItemActive'> => ({
+ onContextMenu: (event, item) => props.onContextMenu(event, item.id, props.pickerId),
+ toggleItemActive: (id, status) => props.toggleItemActive(id, status, props.pickerId),
+ toggleItemOpen: (id, status) => props.toggleItemOpen(id, status, props.pickerId)
+});
+
+export const MainWorkflowTreePicker = connect(memoizedMapStateToProps(), mapDispatchToProps)(Tree);
+
+const treePickerToTreeItems = (tree: Ttree<TreePickerNode>) =>
+ (id: string): TreeItem<any> => {
+ const node: TreePickerNode = getNodeValue(id)(tree) || createTreePickerNode({ nodeId: '', value: 'InvalidNode' });
+ const items = getNodeChildrenIds(node.nodeId)(tree)
+ .map(treePickerToTreeItems(tree));
+ return {
+ active: node.selected,
+ data: node.value,
+ id: node.nodeId,
+ items: items.length > 0 ? items : undefined,
+ open: !node.collapsed,
+ status: node.status
+ };
+ };
+
diff --git a/src/views-components/workflow-tree-picker/workflow-tree-picker.tsx b/src/views-components/workflow-tree-picker/workflow-tree-picker.tsx
new file mode 100644
index 0000000..1dd8c10
--- /dev/null
+++ b/src/views-components/workflow-tree-picker/workflow-tree-picker.tsx
@@ -0,0 +1,156 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from "react";
+import { Dispatch } from "redux";
+import { connect } from "react-redux";
+import { Typography } from "@material-ui/core";
+import { MainWorkflowTreePicker, MainWorkflowTreePickerProps } from "./main-workflow-tree-picker";
+import { TreeItem, TreeItemStatus } from "~/components/tree/tree";
+import { ProjectResource } from "~/models/project";
+import { workflowTreePickerActions } from "~/store/workflow-tree-picker/workflow-tree-picker-actions";
+import { ListItemTextIcon } from "~/components/list-item-text-icon/list-item-text-icon";
+import { ProjectIcon, FavoriteIcon, ProjectsIcon, ShareMeIcon } from "~/components/icon/icon";
+import { createTreePickerNode } from "~/store/tree-picker/tree-picker";
+import { RootState } from "~/store/store";
+import { ServiceRepository } from "~/services/services";
+import { FilterBuilder } from "~/services/api/filter-builder";
+import { WrappedFieldProps } from 'redux-form';
+
+type WorkflowTreePickerProps = Pick<MainWorkflowTreePickerProps, 'onContextMenu' | 'toggleItemActive' | 'toggleItemOpen'>;
+
+const mapDispatchToProps = (dispatch: Dispatch, props: { onChange: (projectUuid: string) => void }): WorkflowTreePickerProps => ({
+ onContextMenu: () => { return; },
+ toggleItemActive: (nodeId, status, pickerId) => {
+ getNotSelectedTreePickerKind(pickerId)
+ .forEach(pickerId => dispatch(workflowTreePickerActions.TOGGLE_TREE_PICKER_NODE_SELECT({ nodeId: '', pickerId })));
+ dispatch(workflowTreePickerActions.TOGGLE_TREE_PICKER_NODE_SELECT({ nodeId, pickerId }));
+
+ props.onChange(nodeId);
+ },
+ toggleItemOpen: (nodeId, status, pickerId) => {
+ dispatch<any>(toggleItemOpen(nodeId, status, pickerId));
+ }
+});
+
+const toggleItemOpen = (nodeId: string, status: TreeItemStatus, pickerId: string) =>
+ (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+ if (status === TreeItemStatus.INITIAL) {
+ if (pickerId === TreePickerId.PROJECTS) {
+ dispatch<any>(loadProjectTreePickerProjects(nodeId));
+ } else if (pickerId === TreePickerId.FAVORITES) {
+ dispatch<any>(loadFavoriteTreePickerProjects(nodeId === services.authService.getUuid() ? '' : nodeId));
+ } else {
+ // TODO: load sharedWithMe
+ }
+ } else {
+ dispatch(workflowTreePickerActions.TOGGLE_TREE_PICKER_NODE_COLLAPSE({ nodeId, pickerId }));
+ }
+ };
+
+const getNotSelectedTreePickerKind = (pickerId: string) => {
+ return [TreePickerId.PROJECTS, TreePickerId.FAVORITES, TreePickerId.SHARED_WITH_ME].filter(nodeId => nodeId !== pickerId);
+};
+
+export enum TreePickerId {
+ PROJECTS = 'Projects',
+ SHARED_WITH_ME = 'Shared with me',
+ FAVORITES = 'Favorites'
+}
+
+export const WorkflowTreePicker = connect(undefined, mapDispatchToProps)((props: WorkflowTreePickerProps) =>
+ <div style={{ display: 'flex', flexDirection: 'column' }}>
+ <Typography variant='caption' style={{ flexShrink: 0 }}>
+ Select a project
+ </Typography>
+ <div style={{ flexGrow: 1, overflow: 'auto' }}>
+ <MainWorkflowTreePicker {...props} render={renderTreeItem} pickerId={TreePickerId.PROJECTS} />
+ <MainWorkflowTreePicker {...props} render={renderTreeItem} pickerId={TreePickerId.SHARED_WITH_ME} />
+ <MainWorkflowTreePicker {...props} render={renderTreeItem} pickerId={TreePickerId.FAVORITES} />
+ </div>
+ </div>);
+
+export const loadProjectTreePickerProjects = (nodeId: string) =>
+ async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+ dispatch(workflowTreePickerActions.LOAD_TREE_PICKER_NODE({ nodeId, pickerId: TreePickerId.PROJECTS }));
+
+ const ownerUuid = nodeId.length === 0 ? services.authService.getUuid() || '' : nodeId;
+
+ const filters = new FilterBuilder()
+ .addEqual('ownerUuid', ownerUuid)
+ .getFilters();
+
+ const { items } = await services.projectService.list({ filters });
+
+ dispatch<any>(receiveTreePickerData(nodeId, items, TreePickerId.PROJECTS));
+ };
+
+export const loadFavoriteTreePickerProjects = (nodeId: string) =>
+ async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+ const parentId = services.authService.getUuid() || '';
+
+ if (nodeId === '') {
+ dispatch(workflowTreePickerActions.LOAD_TREE_PICKER_NODE({ nodeId: parentId, pickerId: TreePickerId.FAVORITES }));
+ const { items } = await services.favoriteService.list(parentId);
+
+ dispatch<any>(receiveTreePickerData(parentId, items as ProjectResource[], TreePickerId.FAVORITES));
+ } else {
+ dispatch(workflowTreePickerActions.LOAD_TREE_PICKER_NODE({ nodeId, pickerId: TreePickerId.FAVORITES }));
+ const filters = new FilterBuilder()
+ .addEqual('ownerUuid', nodeId)
+ .getFilters();
+
+ const { items } = await services.projectService.list({ filters });
+
+ dispatch<any>(receiveTreePickerData(nodeId, items, TreePickerId.FAVORITES));
+ }
+
+ };
+
+const getProjectPickerIcon = (item: TreeItem<ProjectResource>) => {
+ switch (item.data.name) {
+ case TreePickerId.FAVORITES:
+ return FavoriteIcon;
+ case TreePickerId.PROJECTS:
+ return ProjectsIcon;
+ case TreePickerId.SHARED_WITH_ME:
+ return ShareMeIcon;
+ default:
+ return ProjectIcon;
+ }
+};
+
+const renderTreeItem = (item: TreeItem<ProjectResource>) =>
+ <ListItemTextIcon
+ icon={getProjectPickerIcon(item)}
+ name={item.data.name}
+ isActive={item.active}
+ hasMargin={true} />;
+
+
+export const receiveTreePickerData = (nodeId: string, projects: ProjectResource[], pickerId: string) =>
+ (dispatch: Dispatch) => {
+ dispatch(workflowTreePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({
+ nodeId,
+ nodes: projects.map(project => createTreePickerNode({ nodeId: project.uuid, value: project })),
+ pickerId,
+ }));
+
+ dispatch(workflowTreePickerActions.TOGGLE_TREE_PICKER_NODE_COLLAPSE({ nodeId, pickerId }));
+ };
+
+export const WorkflowTreePickerField = (props: WrappedFieldProps) =>
+ <div style={{ height: '200px', display: 'flex', flexDirection: 'column' }}>
+ <WorkflowTreePicker onChange={handleChange(props)} />
+ {props.meta.dirty && props.meta.error &&
+ <Typography variant='caption' color='error'>
+ {props.meta.error}
+ </Typography>}
+ </div>;
+
+const handleChange = (props: WrappedFieldProps) => (value: string) =>
+ props.input.value === value
+ ? props.input.onChange('')
+ : props.input.onChange(value);
+
diff --git a/src/views/workflow-panel/workflow-panel-view.tsx b/src/views/workflow-panel/workflow-panel-view.tsx
index 8a29cb7..094c1e6 100644
--- a/src/views/workflow-panel/workflow-panel-view.tsx
+++ b/src/views/workflow-panel/workflow-panel-view.tsx
@@ -111,6 +111,7 @@ export const WorkflowPanelView = ({...props}) => {
onRowClick={props.handleRowClick}
onRowDoubleClick={props.handleRowDoubleClick}
contextMenuColumn={false}
+ onContextMenu={e=>e}
dataTableDefaultView={<DataTableDefaultView icon={WorkflowIcon} />} />
</Grid>
<Grid item xs={6}>
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list