From b14c0722a9327a762d9657ee0d5033843f997e49 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Kuty=C5=82a?= Date: Tue, 24 Nov 2020 23:04:10 +0100 Subject: [PATCH] 17114: FlatTree introduced to support old behaviour MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła --- src/components/tree/tree.tsx | 134 +++++++++++------- .../tree-picker/tree-picker.ts | 1 + 2 files changed, 87 insertions(+), 48 deletions(-) diff --git a/src/components/tree/tree.tsx b/src/components/tree/tree.tsx index 25398288ff..bdc374213a 100644 --- a/src/components/tree/tree.tsx +++ b/src/components/tree/tree.tsx @@ -3,7 +3,7 @@ // SPDX-License-Identifier: AGPL-3.0 import * as React from 'react'; -import { List, ListItem, ListItemIcon, Checkbox, Radio } from "@material-ui/core"; +import { List, ListItem, ListItemIcon, Checkbox, Radio, Collapse } from "@material-ui/core"; import { StyleRulesCallback, withStyles, WithStyles } from '@material-ui/core/styles'; import { ProjectIcon } from '~/components/icon/icon'; import { ReactElement } from "react"; @@ -95,6 +95,7 @@ export interface TreeItem { open: boolean; active: boolean; selected?: boolean; + flatTree?: boolean; status: TreeItemStatus; items?: Array>; } @@ -141,12 +142,68 @@ const getActionAndId = (event: any, initAction: string | undefined = undefined) return [action, id]; }; +interface FlatTreeProps { + it: TreeItem; + levelIndentation: number; + onContextMenu: Function; + handleToggleItemOpen: Function; + toggleItemActive: Function; + getToggableIconClassNames: Function; + getProperArrowAnimation: Function; + classes: any; +} + +const FlatTree = (props: FlatTreeProps) => +
{ + const [action, id] = getActionAndId(event, 'CONTEXT_MENU'); + props.onContextMenu(event, { id } as any); + }} + onClick={(event) => { + const [action, id] = getActionAndId(event); + + if (action && id) { + switch (action) { + case 'TOGGLE_OPEN': + props.handleToggleItemOpen({ id } as any, event); + break; + case 'TOGGLE_ACTIVE': + props.toggleItemActive(event, { id } as any); + break; + default: + break; + } + } + }} + > + { + (props.it.items || []) + .map((item: any) =>
+ + + {props.getProperArrowAnimation(item.status, item.items!)} + + +
+ + + + {item.data.name} + + +
+
) + } +
; + export const Tree = withStyles(styles)( class Component extends React.Component & WithStyles, {}> { render(): ReactElement { const level = this.props.level ? this.props.level : 0; - const { classes, render, items, toggleItemActive, disableRipple, currentItemUuid, useRadioButtons } = this.props; - const { list, listItem, loader, toggableIconContainer, renderContainer, childItem, active, childItemIcon } = classes; + const { classes, render, items, toggleItemActive, toggleItemOpen, disableRipple, currentItemUuid, useRadioButtons } = this.props; + const { list, listItem, loader, toggableIconContainer, renderContainer } = classes; const showSelection = typeof this.props.showSelection === 'function' ? this.props.showSelection : () => this.props.showSelection ? true : false; @@ -188,51 +245,32 @@ export const Tree = withStyles(styles)( {render(it, level)} - {it.open && it.items && it.items.length > 0 && -
{ - const [action, id] = getActionAndId(event, 'CONTEXT_MENU'); - this.props.onContextMenu(event, { id } as any); - }} - onClick={(event) => { - const [action, id] = getActionAndId(event); - - if (action && id) { - switch(action) { - case 'TOGGLE_OPEN': - this.handleToggleItemOpen({ id } as any, event); - break; - case 'TOGGLE_ACTIVE': - toggleItemActive(event, { id } as any); - break; - default: - break; - } - } - }} - > - { - it.items - .slice(0, 30) - .map((item: any) =>
- - - {this.getProperArrowAnimation(item.status, item.items!)} - - -
- - - - {item.data.name} - - -
-
) - } -
} + { + it.open && it.items && it.items.length > 0 && + it.flatTree ? + : + + + + } )} ; } diff --git a/src/views-components/tree-picker/tree-picker.ts b/src/views-components/tree-picker/tree-picker.ts index e7dc2a84ed..92dd958924 100644 --- a/src/views-components/tree-picker/tree-picker.ts +++ b/src/views-components/tree-picker/tree-picker.ts @@ -43,6 +43,7 @@ const memoizedMapStateToProps = () => { .map(treePickerToTreeItems(tree)) .map(parentItem => ({ ...parentItem, + flatTree: true, items: flatTree(2, parentItem.items || []), })) }; -- 2.30.2