[ARVADOS-WORKBENCH2] created: 2.1.0-158-gc859c9d9

Git user git at public.arvados.org
Thu Jan 14 20:58:07 UTC 2021


        at  c859c9d9325e2ed86d5d7b067e1209e73ee81251 (commit)


commit c859c9d9325e2ed86d5d7b067e1209e73ee81251
Author: Daniel Kutyła <daniel.kutyla at contractors.roche.com>
Date:   Thu Jan 14 21:56:37 2021 +0100

    17256: Added map to enable item resolution
    
    Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla at contractors.roche.com>

diff --git a/src/components/tree/tree.tsx b/src/components/tree/tree.tsx
index 9680e3c0..2089d1cb 100644
--- a/src/components/tree/tree.tsx
+++ b/src/components/tree/tree.tsx
@@ -105,6 +105,7 @@ export interface TreeProps<T> {
     currentItemUuid?: string;
     items?: Array<TreeItem<T>>;
     level?: number;
+    itemsMap?: Map<string, TreeItem<T>>;
     onContextMenu: (event: React.MouseEvent<HTMLElement>, item: TreeItem<T>) => void;
     render: (item: TreeItem<T>, level?: number) => ReactElement<{}>;
     showSelection?: boolean | ((item: TreeItem<T>) => boolean);
@@ -150,10 +151,10 @@ interface FlatTreeProps {
     toggleItemActive: Function;
     getToggableIconClassNames: Function;
     getProperArrowAnimation: Function;
+    itemsMap?: Map<string, TreeItem<any>>;
     classes: any;
 }
 
-
 const FLAT_TREE_ACTIONS = {
     toggleOpen: 'TOGGLE_OPEN',
     contextMenu: 'CONTEXT_MENU',
@@ -170,12 +171,14 @@ const FlatTree = (props: FlatTreeProps) =>
             const [action, id] = getActionAndId(event);
 
             if (action && id) {
+                const item = props.itemsMap ? props.itemsMap[id] : { id };
+
                 switch (action) {
                     case FLAT_TREE_ACTIONS.toggleOpen:
-                        props.handleToggleItemOpen({ id } as any, event);
+                        props.handleToggleItemOpen(item as any, event);
                         break;
                     case FLAT_TREE_ACTIONS.toggleActive:
-                        props.toggleItemActive(event, { id } as any);
+                        props.toggleItemActive(event, item as any);
                         break;
                     default:
                         break;
@@ -209,7 +212,7 @@ export const Tree = withStyles(styles)(
     class Component<T> extends React.Component<TreeProps<T> & WithStyles<CssRules>, {}> {
         render(): ReactElement<any> {
             const level = this.props.level ? this.props.level : 0;
-            const { classes, render, items, toggleItemActive, toggleItemOpen, disableRipple, currentItemUuid, useRadioButtons } = this.props;
+            const { classes, render, items, toggleItemActive, toggleItemOpen, disableRipple, currentItemUuid, useRadioButtons, itemsMap } = this.props;
             const { list, listItem, loader, toggableIconContainer, renderContainer } = classes;
             const showSelection = typeof this.props.showSelection === 'function'
                 ? this.props.showSelection
@@ -257,6 +260,7 @@ export const Tree = withStyles(styles)(
                                 it.flatTree ?
                                     <FlatTree
                                         it={it}
+                                        itemsMap={itemsMap}
                                         classes={this.props.classes}
                                         levelIndentation={levelIndentation}
                                         onContextMenu={this.props.onContextMenu}
diff --git a/src/views-components/tree-picker/tree-picker.ts b/src/views-components/tree-picker/tree-picker.ts
index c34b6c37..9bb52dee 100644
--- a/src/views-components/tree-picker/tree-picker.ts
+++ b/src/views-components/tree-picker/tree-picker.ts
@@ -19,21 +19,29 @@ export interface TreePickerProps<T> {
 }
 
 const flatTree = (depth: number, items?: any): [] => {
-    return items ? items.reduce((prev: any, next: any) => {
-        const { items } = next;
+    return items ? items
+        .map(addToItemsIdMap)
+        .reduce((prev: any, next: any) => {
+            const { items } = next;
 
-        return [
-            ...prev,
-            { ...next, depth },
-            ...(next.open ? flatTree(depth + 1, items) : []),
-        ];
-    }, []) : [];
+            return [
+                ...prev,
+                { ...next, depth },
+                ...(next.open ? flatTree(depth + 1, items) : []),
+            ];
+        }, []) : [];
+};
+
+const itemsIdMap = new Map();
+const addToItemsIdMap = <T>(item: TreeItem<T>) => {
+    itemsIdMap[item.id] = item;
+    return item;
 };
 
 const memoizedMapStateToProps = () => {
     let prevTree: Ttree<any>;
-    let mappedProps: Pick<TreeProps<any>, 'items' | 'disableRipple'>;
-    return <T>(state: RootState, props: TreePickerProps<T>): Pick<TreeProps<T>, 'items' | 'disableRipple'> => {
+    let mappedProps: Pick<TreeProps<any>, 'items' | 'disableRipple' | 'itemsMap'>;
+    return <T>(state: RootState, props: TreePickerProps<T>): Pick<TreeProps<T>, 'items' | 'disableRipple' | 'itemsMap'> => {
         const tree = state.treePicker[props.pickerId] || createTree();
         if (tree !== prevTree) {
             prevTree = tree;
@@ -41,11 +49,13 @@ const memoizedMapStateToProps = () => {
                 disableRipple: true,
                 items: getNodeChildrenIds('')(tree)
                     .map(treePickerToTreeItems(tree))
+                    .map(addToItemsIdMap)
                     .map(parentItem => ({
                         ...parentItem,
                         flatTree: true,
                         items: flatTree(2, parentItem.items || []),
-                    }))
+                    })),
+                itemsMap: itemsIdMap,
             };
         }
         return mappedProps;

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list