includeCollections?: boolean;
includeFiles?: boolean;
rootItemIcon: IconType;
- rootItemSelection?: boolean;
- projectsSelection?: boolean;
- collectionsSelection?: boolean;
- filesSelection?: boolean;
+ showSelection?: boolean;
loadRootItem: (item: TreeItem<ProjectsTreePickerRootItem>, pickerId: string, includeCollections?: boolean, inlcudeFiles?: boolean) => void;
}
export type ProjectsTreePickerProps = ProjectsTreePickerDataProps & Partial<PickedTreePickerProps>;
-const mapStateToProps = (_: any, { rootItemIcon, ...props }: ProjectsTreePickerProps) => ({
+const mapStateToProps = (_: any, { rootItemIcon, showSelection }: ProjectsTreePickerProps) => ({
render: renderTreeItem(rootItemIcon),
- showSelection: isSelectionVisible(props),
+ showSelection: isSelectionVisible(showSelection),
});
const mapDispatchToProps = (dispatch: Dispatch, { loadRootItem, includeCollections, includeFiles, ...props }: ProjectsTreePickerProps): PickedTreePickerProps => ({
return rootIcon;
}
};
-interface IsSelectionVisibleParams {
- rootItemSelection?: boolean;
- projectsSelection?: boolean;
- collectionsSelection?: boolean;
- filesSelection?: boolean;
-}
-const isSelectionVisible = (params: IsSelectionVisibleParams) =>
- ({ data, status }: TreeItem<ProjectsTreePickerItem>) => {
- if ('kind' in data) {
- switch (data.kind) {
- case ResourceKind.COLLECTION:
- return !!params.collectionsSelection;
- default:
- return !!params.projectsSelection;
+
+const isSelectionVisible = (shouldBeVisible?: boolean) =>
+ ({ status, items }: TreeItem<ProjectsTreePickerItem>): boolean => {
+ if (shouldBeVisible) {
+ if (items && items.length > 0) {
+ return items.every(isSelectionVisible(shouldBeVisible));
}
- } else if ('type' in data) {
- return !!params.filesSelection;
- } else {
- return !!params.rootItemSelection;
+ return status === TreeItemStatus.LOADED;
}
+ return false;
};
const renderTreeItem = (rootItemIcon: IconType) => (item: TreeItem<ProjectResource>) =>
// SPDX-License-Identifier: AGPL-3.0
import * as React from 'react';
-import { Dispatch } from 'redux';
-import { connect } from 'react-redux';
import { HomeTreePicker } from '~/views-components/projects-tree-picker/home-tree-picker';
import { SharedTreePicker } from '~/views-components/projects-tree-picker/shared-tree-picker';
import { FavoritesTreePicker } from '~/views-components/projects-tree-picker/favorites-tree-picker';
-import { getProjectsTreePickerIds, treePickerActions } from '~/store/tree-picker/tree-picker-actions';
+import { getProjectsTreePickerIds } from '~/store/tree-picker/tree-picker-actions';
import { TreeItem } from '~/components/tree/tree';
import { ProjectsTreePickerItem } from './generic-projects-tree-picker';
pickerId: string;
includeCollections?: boolean;
includeFiles?: boolean;
- rootItemSelection?: boolean;
- projectsSelection?: boolean;
- collectionsSelection?: boolean;
- filesSelection?: boolean;
+ showSelection?: boolean;
toggleItemActive?: (event: React.MouseEvent<HTMLElement>, item: TreeItem<ProjectsTreePickerItem>, pickerId: string) => void;
}