diff --git a/app/src/common/sidebar/Sidebar.tsx b/app/src/common/sidebar/Sidebar.tsx index 3f81533058..79a706cc4b 100644 --- a/app/src/common/sidebar/Sidebar.tsx +++ b/app/src/common/sidebar/Sidebar.tsx @@ -1,43 +1,43 @@ import * as React from 'react'; import * as css from './Sidebar.scss'; import { ScrollBars, SearchInput } from '@epam/promo'; -import { Tree, TreeListItem, TreeNodeProps } from '@epam/uui-components'; +import { Tree, TreeListItem } from '@epam/uui-components'; import { SidebarButton } from './SidebarButton'; -import { Link, useUuiContext } from "@epam/uui"; +import { DataRowProps, DataSourceState, Link, useUuiContext } from "@epam/uui"; import { analyticsEvents } from "../../analyticsEvents"; export interface SidebarProps { value: string; - onValueChange: (newVal: TreeNodeProps) => void; - getItemLink?: (item: TreeNodeProps) => Link; + onValueChange: (newVal: DataRowProps) => void; + getItemLink?: (item: DataRowProps) => Link; items: TItem[]; renderSearch?: () => React.ReactNode; } export function Sidebar(props: SidebarProps) { const { uuiAnalytics } = useUuiContext(); - const [searchValue, setSearchValue] = React.useState(''); - const [unfoldedIds, setUnfoldedIds] = React.useState([]); + const [value, setValue] = React.useState({ search: '', folded: {} }); React.useEffect(() => { - const { parentId } = props.items.find(i => i.id === props.value); - if (!unfoldedIds.includes(parentId) && parentId !== undefined) { - setUnfoldedIds([...unfoldedIds, parentId]); + const { parentId } = props.items.find(i => i.id == props.value); + if (parentId != null) { + const parentKey = JSON.stringify(parentId); + setValue((value) => ({...value, folded: { ...value.folded, [ parentKey ]: false } })); } }, [props.value]); - const handleClick = React.useCallback((item: TreeNodeProps) => { - item.isDropdown && item.onClick(); - const type = item.isDropdown ? 'folder' : 'document'; - uuiAnalytics.sendEvent(analyticsEvents.document.clickDocument(type, item.data.name, item.parentId)); + const handleClick = React.useCallback((row: DataRowProps) => { + row.isFoldable && row.onFold(row); + const type = row.isFoldable ? 'folder' : 'document'; + uuiAnalytics.sendEvent(analyticsEvents.document.clickDocument(type, row.value.name, row.parentId)); }, []); return (