From 67d63d61aa5a1f1bc1bb85bf6b788e6c0d21e298 Mon Sep 17 00:00:00 2001 From: Pawel Kowalczyk Date: Fri, 17 Aug 2018 16:16:29 +0200 Subject: [PATCH] cr changes Feature #13902 Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk --- .../move-to-dialog/move-to-dialog.tsx | 2 +- src/components/tree/tree.tsx | 8 ++- src/index.tsx | 2 +- src/store/tree-picker/tree-picker-actions.ts | 41 ++--------- .../tree-picker/tree-picker-reducer.test.ts | 32 ++++----- src/store/tree-picker/tree-picker-reducer.ts | 24 +++---- .../action-sets/collection-action-set.ts | 4 +- .../collection-resource-action-set.ts | 4 +- .../action-sets/project-action-set.ts | 4 +- .../move-to-dialog/move-to-dialog.tsx | 4 +- .../project-tree-picker.tsx | 71 +++++++++++++------ .../tree-picker/tree-picker.ts | 12 ++-- 12 files changed, 100 insertions(+), 108 deletions(-) diff --git a/src/components/move-to-dialog/move-to-dialog.tsx b/src/components/move-to-dialog/move-to-dialog.tsx index 51f5fbf6df..2bfc2c3d66 100644 --- a/src/components/move-to-dialog/move-to-dialog.tsx +++ b/src/components/move-to-dialog/move-to-dialog.tsx @@ -10,7 +10,7 @@ import { WithDialogProps } from "~/store/dialog/with-dialog"; import { ProjectTreePicker } from "~/views-components/project-tree-picker/project-tree-picker"; import { MOVE_TO_VALIDATION } from "~/validators/validators"; -export const MoveTo = (props: WithDialogProps & InjectedFormProps<{ name: string }>) => +export const MoveToDialog = (props: WithDialogProps & InjectedFormProps<{ name: string }>) =>
this.props.toggleItemOpen(it.id, it.status)} className={toggableIconContainer}> - {it.status === TreeItemStatus.PENDING - || (it.status === TreeItemStatus.LOADED && !it.items) - || (it.status === TreeItemStatus.LOADED && it.items && it.items.length === 0) ? : } + {this.getProperArrowAnimation(it.status, it.items!)} {this.props.showSelection && @@ -142,6 +140,10 @@ export const Tree = withStyles(styles)( ; } + getProperArrowAnimation = (status: string, items: Array>) => { + return status === TreeItemStatus.PENDING || (status === TreeItemStatus.LOADED && !items) ? : ; + } + getToggableIconClassNames = (isOpen?: boolean, isActive?: boolean) => { const { iconOpen, iconClose, active, toggableIcon } = this.props.classes; return classnames(toggableIcon, { diff --git a/src/index.tsx b/src/index.tsx index 461904c43b..faaf6b81ec 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -27,7 +27,7 @@ import { collectionFilesActionSet } from './views-components/context-menu/action import { collectionFilesItemActionSet } from './views-components/context-menu/action-sets/collection-files-item-action-set'; import { collectionActionSet } from './views-components/context-menu/action-sets/collection-action-set'; import { collectionResourceActionSet } from './views-components/context-menu/action-sets/collection-resource-action-set'; -import { initPickerProjectTree } from './store/tree-picker/tree-picker-actions'; +import { initPickerProjectTree } from './views-components/project-tree-picker/project-tree-picker'; addMenuActionSet(ContextMenuKind.ROOT_PROJECT, rootProjectActionSet); addMenuActionSet(ContextMenuKind.PROJECT, projectActionSet); diff --git a/src/store/tree-picker/tree-picker-actions.ts b/src/store/tree-picker/tree-picker-actions.ts index 5b29c4c2b5..f3c358168b 100644 --- a/src/store/tree-picker/tree-picker-actions.ts +++ b/src/store/tree-picker/tree-picker-actions.ts @@ -5,48 +5,15 @@ import { default as unionize, ofType, UnionOf } from "unionize"; import { TreePickerNode } from "./tree-picker"; -import { receiveTreePickerData, TreePickerKind } from "../../views-components/project-tree-picker/project-tree-picker"; -import { mockProjectResource } from "../../models/test-utils"; -import { Dispatch } from "redux"; -import { RootState } from "../store"; -import { ServiceRepository } from "../../services/services"; export const treePickerActions = unionize({ - LOAD_TREE_PICKER_NODE: ofType<{ id: string, pickerId: string }>(), - LOAD_TREE_PICKER_NODE_SUCCESS: ofType<{ id: string, nodes: Array, pickerId: string }>(), - TOGGLE_TREE_PICKER_NODE_COLLAPSE: ofType<{ id: string, pickerId: string }>(), - TOGGLE_TREE_PICKER_NODE_SELECT: ofType<{ id: string, pickerId: string }>() + LOAD_TREE_PICKER_NODE: ofType<{ id: string, pickerKind: string }>(), + LOAD_TREE_PICKER_NODE_SUCCESS: ofType<{ id: string, nodes: Array, pickerKind: string }>(), + TOGGLE_TREE_PICKER_NODE_COLLAPSE: ofType<{ id: string, pickerKind: string }>(), + TOGGLE_TREE_PICKER_NODE_SELECT: ofType<{ id: string, pickerKind: string }>() }, { tag: 'type', value: 'payload' }); -export const initPickerProjectTree = () => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - const uuid = services.authService.getUuid(); - - dispatch(getPickerTreeProjects(uuid)); - dispatch(getSharedWithMeProjectsPickerTree(uuid)); - dispatch(getFavoritesProjectsPickerTree(uuid)); -}; - -const getPickerTreeProjects = (uuid: string = '') => { - return getProjectsPickerTree(uuid, TreePickerKind.PROJECTS); -}; - -const getSharedWithMeProjectsPickerTree = (uuid: string = '') => { - return getProjectsPickerTree(uuid, TreePickerKind.SHARED_WITH_ME); -}; - -const getFavoritesProjectsPickerTree = (uuid: string = '') => { - return getProjectsPickerTree(uuid, TreePickerKind.FAVORITES); -}; - -const getProjectsPickerTree = (uuid: string, kind: string) => { - return receiveTreePickerData( - '', - [mockProjectResource({ uuid, name: kind })], - kind - ); -}; - export type TreePickerAction = UnionOf; diff --git a/src/store/tree-picker/tree-picker-reducer.test.ts b/src/store/tree-picker/tree-picker-reducer.test.ts index 2432b8429e..62367d570f 100644 --- a/src/store/tree-picker/tree-picker-reducer.test.ts +++ b/src/store/tree-picker/tree-picker-reducer.test.ts @@ -11,7 +11,7 @@ import { TreeItemStatus } from "~/components/tree/tree"; describe('TreePickerReducer', () => { it('LOAD_TREE_PICKER_NODE - initial state', () => { const tree = createTree(); - const newState = treePickerReducer({}, treePickerActions.LOAD_TREE_PICKER_NODE({ id: '1', pickerId: "projects" })); + const newState = treePickerReducer({}, treePickerActions.LOAD_TREE_PICKER_NODE({ id: '1', pickerKind: "projects" })); expect(newState).toEqual({ 'projects': tree }); }); @@ -20,8 +20,8 @@ describe('TreePickerReducer', () => { const [newState] = [{ projects: createTree() }] - .map(state => treePickerReducer(state, treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ id: '', nodes: [node], pickerId: "projects" }))) - .map(state => treePickerReducer(state, treePickerActions.LOAD_TREE_PICKER_NODE({ id: '1', pickerId: "projects" }))); + .map(state => treePickerReducer(state, treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ id: '', nodes: [node], pickerKind: "projects" }))) + .map(state => treePickerReducer(state, treePickerActions.LOAD_TREE_PICKER_NODE({ id: '1', pickerKind: "projects" }))); expect(getNodeValue('1')(newState.projects)).toEqual({ ...createTreePickerNode({ id: '1', value: '1' }), @@ -31,7 +31,7 @@ describe('TreePickerReducer', () => { it('LOAD_TREE_PICKER_NODE_SUCCESS - initial state', () => { const subNode = createTreePickerNode({ id: '1.1', value: '1.1' }); - const newState = treePickerReducer({}, treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ id: '', nodes: [subNode], pickerId: "projects" })); + const newState = treePickerReducer({}, treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ id: '', nodes: [subNode], pickerKind: "projects" })); expect(getNodeChildren('')(newState.projects)).toEqual(['1.1']); }); @@ -41,8 +41,8 @@ describe('TreePickerReducer', () => { const [newState] = [{ projects: createTree() }] - .map(state => treePickerReducer(state, treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ id: '', nodes: [node], pickerId: "projects" }))) - .map(state => treePickerReducer(state, treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ id: '1', nodes: [subNode], pickerId: "projects" }))); + .map(state => treePickerReducer(state, treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ id: '', nodes: [node], pickerKind: "projects" }))) + .map(state => treePickerReducer(state, treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ id: '1', nodes: [subNode], pickerKind: "projects" }))); expect(getNodeChildren('1')(newState.projects)).toEqual(['1.1']); expect(getNodeValue('1')(newState.projects)).toEqual({ ...createTreePickerNode({ id: '1', value: '1' }), @@ -55,8 +55,8 @@ describe('TreePickerReducer', () => { const [newState] = [{ projects: createTree() }] - .map(state => treePickerReducer(state, treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ id: '', nodes: [node], pickerId: "projects" }))) - .map(state => treePickerReducer(state, treePickerActions.TOGGLE_TREE_PICKER_NODE_COLLAPSE({ id: '1', pickerId: "projects" }))); + .map(state => treePickerReducer(state, treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ id: '', nodes: [node], pickerKind: "projects" }))) + .map(state => treePickerReducer(state, treePickerActions.TOGGLE_TREE_PICKER_NODE_COLLAPSE({ id: '1', pickerKind: "projects" }))); expect(getNodeValue('1')(newState.projects)).toEqual({ ...createTreePickerNode({ id: '1', value: '1' }), collapsed: false @@ -68,9 +68,9 @@ describe('TreePickerReducer', () => { const [newState] = [{ projects: createTree() }] - .map(state => treePickerReducer(state, treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ id: '', nodes: [node], pickerId: "projects" }))) - .map(state => treePickerReducer(state, treePickerActions.TOGGLE_TREE_PICKER_NODE_COLLAPSE({ id: '1', pickerId: "projects" }))) - .map(state => treePickerReducer(state, treePickerActions.TOGGLE_TREE_PICKER_NODE_COLLAPSE({ id: '1', pickerId: "projects" }))); + .map(state => treePickerReducer(state, treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ id: '', nodes: [node], pickerKind: "projects" }))) + .map(state => treePickerReducer(state, treePickerActions.TOGGLE_TREE_PICKER_NODE_COLLAPSE({ id: '1', pickerKind: "projects" }))) + .map(state => treePickerReducer(state, treePickerActions.TOGGLE_TREE_PICKER_NODE_COLLAPSE({ id: '1', pickerKind: "projects" }))); expect(getNodeValue('1')(newState.projects)).toEqual({ ...createTreePickerNode({ id: '1', value: '1' }), collapsed: true @@ -82,8 +82,8 @@ describe('TreePickerReducer', () => { const [newState] = [{ projects: createTree() }] - .map(state => treePickerReducer(state, treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ id: '', nodes: [node], pickerId: "projects" }))) - .map(state => treePickerReducer(state, treePickerActions.TOGGLE_TREE_PICKER_NODE_SELECT({ id: '1', pickerId: "projects" }))); + .map(state => treePickerReducer(state, treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ id: '', nodes: [node], pickerKind: "projects" }))) + .map(state => treePickerReducer(state, treePickerActions.TOGGLE_TREE_PICKER_NODE_SELECT({ id: '1', pickerKind: "projects" }))); expect(getNodeValue('1')(newState.projects)).toEqual({ ...createTreePickerNode({ id: '1', value: '1' }), selected: true @@ -95,9 +95,9 @@ describe('TreePickerReducer', () => { const [newState] = [{ projects: createTree() }] - .map(state => treePickerReducer(state, treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ id: '', nodes: [node], pickerId: "projects" }))) - .map(state => treePickerReducer(state, treePickerActions.TOGGLE_TREE_PICKER_NODE_SELECT({ id: '1', pickerId: "projects" }))) - .map(state => treePickerReducer(state, treePickerActions.TOGGLE_TREE_PICKER_NODE_SELECT({ id: '1', pickerId: "projects" }))); + .map(state => treePickerReducer(state, treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ id: '', nodes: [node], pickerKind: "projects" }))) + .map(state => treePickerReducer(state, treePickerActions.TOGGLE_TREE_PICKER_NODE_SELECT({ id: '1', pickerKind: "projects" }))) + .map(state => treePickerReducer(state, treePickerActions.TOGGLE_TREE_PICKER_NODE_SELECT({ id: '1', pickerKind: "projects" }))); expect(getNodeValue('1')(newState.projects)).toEqual({ ...createTreePickerNode({ id: '1', value: '1' }), selected: false diff --git a/src/store/tree-picker/tree-picker-reducer.ts b/src/store/tree-picker/tree-picker-reducer.ts index cf67aa7600..a2d7ef1352 100644 --- a/src/store/tree-picker/tree-picker-reducer.ts +++ b/src/store/tree-picker/tree-picker-reducer.ts @@ -9,27 +9,27 @@ import { TreeItemStatus } from "~/components/tree/tree"; export const treePickerReducer = (state: TreePicker = {}, action: TreePickerAction) => treePickerActions.match(action, { - LOAD_TREE_PICKER_NODE: ({ id, pickerId }) => { - const picker = state[pickerId] || createTree(); + LOAD_TREE_PICKER_NODE: ({ id, pickerKind }) => { + const picker = state[pickerKind] || createTree(); const updatedPicker = setNodeValueWith(setPending)(id)(picker); - return { ...state, [pickerId]: updatedPicker }; + return { ...state, [pickerKind]: updatedPicker }; }, - LOAD_TREE_PICKER_NODE_SUCCESS: ({ id, nodes, pickerId }) => { - const picker = state[pickerId] || createTree(); + LOAD_TREE_PICKER_NODE_SUCCESS: ({ id, nodes, pickerKind }) => { + const picker = state[pickerKind] || createTree(); const [updatedPicker] = [picker] .map(receiveNodes(nodes)(id)) .map(setNodeValueWith(setLoaded)(id)); - return { ...state, [pickerId]: updatedPicker }; + return { ...state, [pickerKind]: updatedPicker }; }, - TOGGLE_TREE_PICKER_NODE_COLLAPSE: ({ id, pickerId }) => { - const picker = state[pickerId] || createTree(); + TOGGLE_TREE_PICKER_NODE_COLLAPSE: ({ id, pickerKind }) => { + const picker = state[pickerKind] || createTree(); const updatedPicker = setNodeValueWith(toggleCollapse)(id)(picker); - return { ...state, [pickerId]: updatedPicker }; + return { ...state, [pickerKind]: updatedPicker }; }, - TOGGLE_TREE_PICKER_NODE_SELECT: ({ id, pickerId }) => { - const picker = state[pickerId] || createTree(); + TOGGLE_TREE_PICKER_NODE_SELECT: ({ id, pickerKind }) => { + const picker = state[pickerKind] || createTree(); const updatedPicker = mapTreeValues(toggleSelect(id))(picker); - return { ...state, [pickerId]: updatedPicker }; + return { ...state, [pickerKind]: updatedPicker }; }, default: () => state }); diff --git a/src/views-components/context-menu/action-sets/collection-action-set.ts b/src/views-components/context-menu/action-sets/collection-action-set.ts index e6dd686af6..9c07fb0551 100644 --- a/src/views-components/context-menu/action-sets/collection-action-set.ts +++ b/src/views-components/context-menu/action-sets/collection-action-set.ts @@ -28,9 +28,7 @@ export const collectionActionSet: ContextMenuActionSet = [[ { icon: MoveToIcon, name: "Move to", - execute: (dispatch) => { - dispatch(openMoveToDialog()); - } + execute: dispatch => dispatch(openMoveToDialog()) }, { component: ToggleFavoriteAction, diff --git a/src/views-components/context-menu/action-sets/collection-resource-action-set.ts b/src/views-components/context-menu/action-sets/collection-resource-action-set.ts index fd2f8d7525..337ca2ff95 100644 --- a/src/views-components/context-menu/action-sets/collection-resource-action-set.ts +++ b/src/views-components/context-menu/action-sets/collection-resource-action-set.ts @@ -28,9 +28,7 @@ export const collectionResourceActionSet: ContextMenuActionSet = [[ { icon: MoveToIcon, name: "Move to", - execute: (dispatch) => { - dispatch(openMoveToDialog()); - } + execute: dispatch => dispatch(openMoveToDialog()) }, { component: ToggleFavoriteAction, diff --git a/src/views-components/context-menu/action-sets/project-action-set.ts b/src/views-components/context-menu/action-sets/project-action-set.ts index ca9a4f674a..efba457821 100644 --- a/src/views-components/context-menu/action-sets/project-action-set.ts +++ b/src/views-components/context-menu/action-sets/project-action-set.ts @@ -41,8 +41,6 @@ export const projectActionSet: ContextMenuActionSet = [[ { icon: MoveToIcon, name: "Move to", - execute: (dispatch) => { - dispatch(openMoveToDialog()); - } + execute: dispatch => dispatch(openMoveToDialog()) }, ]]; diff --git a/src/views-components/move-to-dialog/move-to-dialog.tsx b/src/views-components/move-to-dialog/move-to-dialog.tsx index 21aa5159cb..9c3a6bff9b 100644 --- a/src/views-components/move-to-dialog/move-to-dialog.tsx +++ b/src/views-components/move-to-dialog/move-to-dialog.tsx @@ -5,7 +5,7 @@ import { Dispatch } from "redux"; import { withDialog } from "../../store/dialog/with-dialog"; import { dialogActions } from "../../store/dialog/dialog-actions"; -import { MoveTo } from "../../components/move-to-dialog/move-to-dialog"; +import { MoveToDialog } from "../../components/move-to-dialog/move-to-dialog"; import { reduxForm, startSubmit, stopSubmit } from "redux-form"; export const MOVE_TO_DIALOG = 'moveToDialog'; @@ -15,7 +15,7 @@ export const openMoveToDialog = () => dispatch(dialogActions.OPEN_DIALOG({ id: MOVE_TO_DIALOG, data: {}})); }; -export const [MoveToProjectDialog] = [MoveTo] +export const [MoveToProjectDialog] = [MoveToDialog] .map(withDialog(MOVE_TO_DIALOG)) .map(reduxForm({ form: MOVE_TO_DIALOG, diff --git a/src/views-components/project-tree-picker/project-tree-picker.tsx b/src/views-components/project-tree-picker/project-tree-picker.tsx index e18af9e413..ddf684381a 100644 --- a/src/views-components/project-tree-picker/project-tree-picker.tsx +++ b/src/views-components/project-tree-picker/project-tree-picker.tsx @@ -16,39 +16,40 @@ import { createTreePickerNode } from "~/store/tree-picker/tree-picker"; import { RootState } from "~/store/store"; import { ServiceRepository } from "~/services/services"; import { FilterBuilder } from "~/common/api/filter-builder"; +import { mockProjectResource } from "~/models/test-utils"; type ProjectTreePickerProps = Pick; const mapDispatchToProps = (dispatch: Dispatch, props: { onChange: (projectUuid: string) => void }): ProjectTreePickerProps => ({ - toggleItemActive: (id, status, pickerId) => { - getNotSelectedTreePickerKind(pickerId) - .forEach(pickerId => dispatch(treePickerActions.TOGGLE_TREE_PICKER_NODE_SELECT({ id: '', pickerId }))); - dispatch(treePickerActions.TOGGLE_TREE_PICKER_NODE_SELECT({ id, pickerId })); + toggleItemActive: (id, status, pickerKind) => { + getNotSelectedTreePickerKind(pickerKind) + .forEach(pickerKind => dispatch(treePickerActions.TOGGLE_TREE_PICKER_NODE_SELECT({ id: '', pickerKind }))); + dispatch(treePickerActions.TOGGLE_TREE_PICKER_NODE_SELECT({ id, pickerKind })); props.onChange(id); }, - toggleItemOpen: (id, status, pickerId) => { - dispatch(toggleItemOpen(id, status, pickerId)); + toggleItemOpen: (id, status, pickerKind) => { + dispatch(toggleItemOpen(id, status, pickerKind)); } }); -const toggleItemOpen = (id: string, status: TreeItemStatus, pickerId: string) => +const toggleItemOpen = (id: string, status: TreeItemStatus, pickerKind: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { if (status === TreeItemStatus.INITIAL) { - if (pickerId === TreePickerKind.PROJECTS) { + if (pickerKind === TreePickerKind.PROJECTS) { dispatch(loadProjectTreePickerProjects(id)); - } else if (pickerId === TreePickerKind.FAVORITES) { + } else if (pickerKind === TreePickerKind.FAVORITES) { dispatch(loadFavoriteTreePickerProjects(id === services.authService.getUuid() ? '' : id)); } else { // TODO: load sharedWithMe } } else { - dispatch(treePickerActions.TOGGLE_TREE_PICKER_NODE_COLLAPSE({ id, pickerId })); + dispatch(treePickerActions.TOGGLE_TREE_PICKER_NODE_COLLAPSE({ id, pickerKind })); } }; -const getNotSelectedTreePickerKind = (pickerId: string) => { - return [TreePickerKind.PROJECTS, TreePickerKind.FAVORITES, TreePickerKind.SHARED_WITH_ME].filter(id => id !== pickerId); +const getNotSelectedTreePickerKind = (pickerKind: string) => { + return [TreePickerKind.PROJECTS, TreePickerKind.FAVORITES, TreePickerKind.SHARED_WITH_ME].filter(id => id !== pickerKind); }; export enum TreePickerKind { @@ -63,9 +64,9 @@ export const ProjectTreePicker = connect(undefined, mapDispatchToProps)((props: Select a project
- - - + + +
); @@ -73,7 +74,7 @@ export const ProjectTreePicker = connect(undefined, mapDispatchToProps)((props: // TODO: move action creator to store directory export const loadProjectTreePickerProjects = (id: string) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - dispatch(treePickerActions.LOAD_TREE_PICKER_NODE({ id, pickerId: TreePickerKind.PROJECTS })); + dispatch(treePickerActions.LOAD_TREE_PICKER_NODE({ id, pickerKind: TreePickerKind.PROJECTS })); const ownerUuid = id.length === 0 ? services.authService.getUuid() || '' : id; @@ -91,12 +92,12 @@ export const loadFavoriteTreePickerProjects = (id: string) => const parentId = services.authService.getUuid() || ''; if (id === '') { - dispatch(treePickerActions.LOAD_TREE_PICKER_NODE({ id: parentId, pickerId: TreePickerKind.FAVORITES })); + dispatch(treePickerActions.LOAD_TREE_PICKER_NODE({ id: parentId, pickerKind: TreePickerKind.FAVORITES })); const { items } = await services.favoriteService.list(parentId); dispatch(receiveTreePickerData(parentId, items as ProjectResource[], TreePickerKind.FAVORITES)); } else { - dispatch(treePickerActions.LOAD_TREE_PICKER_NODE({ id, pickerId: TreePickerKind.FAVORITES })); + dispatch(treePickerActions.LOAD_TREE_PICKER_NODE({ id, pickerKind: TreePickerKind.FAVORITES })); const filters = new FilterBuilder() .addEqual('ownerUuid', id) .getFilters(); @@ -130,14 +131,42 @@ const renderTreeItem = (item: TreeItem) => // TODO: move action creator to store directory -export const receiveTreePickerData = (id: string, projects: ProjectResource[], pickerId: string) => +export const receiveTreePickerData = (id: string, projects: ProjectResource[], pickerKind: string) => (dispatch: Dispatch) => { dispatch(treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ id, nodes: projects.map(project => createTreePickerNode({ id: project.uuid, value: project })), - pickerId, + pickerKind, })); - dispatch(treePickerActions.TOGGLE_TREE_PICKER_NODE_COLLAPSE({ id, pickerId })); + dispatch(treePickerActions.TOGGLE_TREE_PICKER_NODE_COLLAPSE({ id, pickerKind })); }; +export const initPickerProjectTree = () => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + const uuid = services.authService.getUuid(); + + dispatch(getPickerTreeProjects(uuid)); + dispatch(getSharedWithMeProjectsPickerTree(uuid)); + dispatch(getFavoritesProjectsPickerTree(uuid)); +}; + +const getPickerTreeProjects = (uuid: string = '') => { + return getProjectsPickerTree(uuid, TreePickerKind.PROJECTS); +}; + +const getSharedWithMeProjectsPickerTree = (uuid: string = '') => { + return getProjectsPickerTree(uuid, TreePickerKind.SHARED_WITH_ME); +}; + +const getFavoritesProjectsPickerTree = (uuid: string = '') => { + return getProjectsPickerTree(uuid, TreePickerKind.FAVORITES); +}; + +const getProjectsPickerTree = (uuid: string, kind: string) => { + return receiveTreePickerData( + '', + [mockProjectResource({ uuid, name: kind })], + kind + ); +}; + diff --git a/src/views-components/tree-picker/tree-picker.ts b/src/views-components/tree-picker/tree-picker.ts index fb05b81897..73e0a99a8e 100644 --- a/src/views-components/tree-picker/tree-picker.ts +++ b/src/views-components/tree-picker/tree-picker.ts @@ -10,13 +10,13 @@ import { getNodeValue, getNodeChildren, Tree as Ttree, createTree } from "~/mode import { Dispatch } from "redux"; export interface TreePickerProps { - pickerId: string; - toggleItemOpen: (id: string, status: TreeItemStatus, pickerId: string) => void; - toggleItemActive: (id: string, status: TreeItemStatus, pickerId: string) => void; + pickerKind: string; + toggleItemOpen: (id: string, status: TreeItemStatus, pickerKind: string) => void; + toggleItemActive: (id: string, status: TreeItemStatus, pickerKind: string) => void; } const mapStateToProps = (state: RootState, props: TreePickerProps): Pick, 'items'> => { - const tree = state.treePicker[props.pickerId] || createTree(); + const tree = state.treePicker[props.pickerKind] || createTree(); return { items: getNodeChildren('')(tree) .map(treePickerToTreeItems(tree)) @@ -25,8 +25,8 @@ const mapStateToProps = (state: RootState, props: TreePickerProps): Pick, 'onContextMenu' | 'toggleItemOpen' | 'toggleItemActive'> => ({ onContextMenu: () => { return; }, - toggleItemActive: (id, status) => props.toggleItemActive(id, status, props.pickerId), - toggleItemOpen: (id, status) => props.toggleItemOpen(id, status, props.pickerId) + toggleItemActive: (id, status) => props.toggleItemActive(id, status, props.pickerKind), + toggleItemOpen: (id, status) => props.toggleItemOpen(id, status, props.pickerKind) }); export const TreePicker = connect(mapStateToProps, mapDispatchToProps)(Tree); -- 2.30.2