import { ProjectTreePicker } from "~/views-components/project-tree-picker/project-tree-picker";
import { MOVE_TO_VALIDATION } from "~/validators/validators";
-export const MoveTo = (props: WithDialogProps<string> & InjectedFormProps<{ name: string }>) =>
+export const MoveToDialog = (props: WithDialogProps<string> & InjectedFormProps<{ name: string }>) =>
<form>
<Dialog open={props.open}
disableBackdropClick={true}
<i onClick={() => this.props.toggleItemOpen(it.id, it.status)}
className={toggableIconContainer}>
<ListItemIcon className={this.getToggableIconClassNames(it.open, it.active)}>
- {it.status === TreeItemStatus.PENDING
- || (it.status === TreeItemStatus.LOADED && !it.items)
- || (it.status === TreeItemStatus.LOADED && it.items && it.items.length === 0) ? <span /> : <SidePanelRightArrowIcon />}
+ {this.getProperArrowAnimation(it.status, it.items!)}
</ListItemIcon>
</i>
{this.props.showSelection &&
</List>;
}
+ getProperArrowAnimation = (status: string, items: Array<TreeItem<T>>) => {
+ return status === TreeItemStatus.PENDING || (status === TreeItemStatus.LOADED && !items) ? <span /> : <SidePanelRightArrowIcon />;
+ }
+
getToggableIconClassNames = (isOpen?: boolean, isActive?: boolean) => {
const { iconOpen, iconClose, active, toggableIcon } = this.props.classes;
return classnames(toggableIcon, {
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);
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<TreePickerNode>, 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<TreePickerNode>, 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<any>(getPickerTreeProjects(uuid));
- dispatch<any>(getSharedWithMeProjectsPickerTree(uuid));
- dispatch<any>(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<typeof treePickerActions>;
describe('TreePickerReducer', () => {
it('LOAD_TREE_PICKER_NODE - initial state', () => {
const tree = createTree<TreePickerNode>();
- 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 });
});
const [newState] = [{
projects: createTree<TreePickerNode>()
}]
- .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' }),
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']);
});
const [newState] = [{
projects: createTree<TreePickerNode>()
}]
- .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' }),
const [newState] = [{
projects: createTree<TreePickerNode>()
}]
- .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
const [newState] = [{
projects: createTree<TreePickerNode>()
}]
- .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
const [newState] = [{
projects: createTree<TreePickerNode>()
}]
- .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
const [newState] = [{
projects: createTree<TreePickerNode>()
}]
- .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
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
});
{
icon: MoveToIcon,
name: "Move to",
- execute: (dispatch) => {
- dispatch<any>(openMoveToDialog());
- }
+ execute: dispatch => dispatch<any>(openMoveToDialog())
},
{
component: ToggleFavoriteAction,
{
icon: MoveToIcon,
name: "Move to",
- execute: (dispatch) => {
- dispatch<any>(openMoveToDialog());
- }
+ execute: dispatch => dispatch<any>(openMoveToDialog())
},
{
component: ToggleFavoriteAction,
{
icon: MoveToIcon,
name: "Move to",
- execute: (dispatch) => {
- dispatch<any>(openMoveToDialog());
- }
+ execute: dispatch => dispatch<any>(openMoveToDialog())
},
]];
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';
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,
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<TreePickerProps, 'toggleItemActive' | 'toggleItemOpen'>;
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<any>(toggleItemOpen(id, status, pickerId));
+ toggleItemOpen: (id, status, pickerKind) => {
+ dispatch<any>(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<any>(loadProjectTreePickerProjects(id));
- } else if (pickerId === TreePickerKind.FAVORITES) {
+ } else if (pickerKind === TreePickerKind.FAVORITES) {
dispatch<any>(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 {
Select a project
</Typography>
<div style={{ flexGrow: 1, overflow: 'auto' }}>
- <TreePicker {...props} render={renderTreeItem} pickerId={TreePickerKind.PROJECTS} />
- <TreePicker {...props} render={renderTreeItem} pickerId={TreePickerKind.SHARED_WITH_ME} />
- <TreePicker {...props} render={renderTreeItem} pickerId={TreePickerKind.FAVORITES} />
+ <TreePicker {...props} render={renderTreeItem} pickerKind={TreePickerKind.PROJECTS} />
+ <TreePicker {...props} render={renderTreeItem} pickerKind={TreePickerKind.SHARED_WITH_ME} />
+ <TreePicker {...props} render={renderTreeItem} pickerKind={TreePickerKind.FAVORITES} />
</div>
</div>);
// 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;
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<any>(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();
// 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<any>(getPickerTreeProjects(uuid));
+ dispatch<any>(getSharedWithMeProjectsPickerTree(uuid));
+ dispatch<any>(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
+ );
+};
+
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<TreeProps<any>, 'items'> => {
- const tree = state.treePicker[props.pickerId] || createTree();
+ const tree = state.treePicker[props.pickerKind] || createTree();
return {
items: getNodeChildren('')(tree)
.map(treePickerToTreeItems(tree))
const mapDispatchToProps = (dispatch: Dispatch, props: TreePickerProps): Pick<TreeProps<any>, '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);