Skip to content

Commit

Permalink
updated the SimpleTree component
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeriaMaltseva committed Oct 28, 2024
1 parent 2de5bbf commit 8be6bdd
Show file tree
Hide file tree
Showing 25 changed files with 1,502 additions and 3,465 deletions.
28 changes: 22 additions & 6 deletions assets/js/src/core/components/simple-tree/simple-tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
*/

import React, { type Key } from 'react'
import { Tree, type TreeDataNode } from 'antd'
import { Tree, type TreeDataNode, type TreeProps } from 'antd'
import cn from 'classnames'
import { Icon } from '@Pimcore/components/icon/icon'
import { SimpleTreeItem } from './simple-tree-item'
import { useStyles } from './simple-tree.styles'
Expand All @@ -21,7 +22,7 @@ export interface TreeDataItem extends TreeDataNode {
actions?: Array<{ key: string, icon: string }>
}

interface SimpleTreeProps {
interface SimpleTreeProps extends TreeProps {
treeData: TreeDataItem[]
className?: string
defaultExpandedKeys?: string[]
Expand All @@ -30,23 +31,38 @@ interface SimpleTreeProps {
onDragAndDrop?: (params: { node: TreeDataItem, dragNode: TreeDataItem, dropPosition: number }) => void
onSelected?: (key: any) => void
onLoadData?: (node) => Promise<any>
withCustomSwitcherIcon?: boolean
}

const SimpleTree = ({ treeData, className, defaultExpandedKeys, onCheck, onActionsClick, onDragAndDrop, onSelected, onLoadData, ...props }: SimpleTreeProps): React.JSX.Element => {
const SimpleTree = ({ treeData, className, defaultExpandedKeys, onCheck, onActionsClick, onDragAndDrop, onSelected, onLoadData, withCustomSwitcherIcon, ...props }: SimpleTreeProps): React.JSX.Element => {
const { styles } = useStyles()
const classNames = [styles.tree, className]

const [selectedKeys, setSelectedKeys] = React.useState<Key[]>([])
const [expandedKeys, setExpandedKeys] = React.useState<Key[]>(defaultExpandedKeys ?? [])

React.useEffect(() => {
setExpandedKeys(defaultExpandedKeys ?? [])
}, [defaultExpandedKeys])

const handleCustomSwitcherIcon = (): React.JSX.Element | undefined => {
if (withCustomSwitcherIcon === false) return undefined

return (
<Icon
name="chevron-down-small"
options={ {
width: 12,
height: 12
} }
/>
)
}

return (
<Tree
blockNode
checkable={ onCheck !== undefined }
className={ classNames.join(' ') }
className={ cn(styles.tree, className) }
draggable
expandedKeys={ expandedKeys }
loadData={ onLoadData !== null ? onLoadData : undefined }
Expand All @@ -61,7 +77,7 @@ const SimpleTree = ({ treeData, className, defaultExpandedKeys, onCheck, onActio
onExpand={ (keys): void => { setExpandedKeys(keys) } }
selectedKeys={ selectedKeys }
showIcon
switcherIcon={ <Icon name={ 'chevron-down-small' } /> }
switcherIcon={ handleCustomSwitcherIcon }
titleRender={ (node) => (
<SimpleTreeItem
actions={ node.actions }
Expand Down
133 changes: 0 additions & 133 deletions assets/js/src/core/components/tree-element/tree-element.stories.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useTagGetCollectionQuery } from '@Pimcore/modules/element/editor/shared
import React, { type Key } from 'react'
import { Content } from '@Pimcore/components/content/content'
import { Flex } from '@Pimcore/components/flex/flex'
import { TreeElement } from '@Pimcore/components/tree-element/tree-element'
import { SimpleTree } from '@Pimcore/components/simple-tree/simple-tree'
import {
useCreateTreeStructure
} from '@Pimcore/modules/element/editor/shared-tab-manager/tabs/tags/components/tags-tree/hooks/use-create-tree-structure'
Expand Down Expand Up @@ -53,7 +53,7 @@ export const TagsTreeFiltersContainer = ({ addOrUpdateFieldFilter, checkedKeys,
gap={ 'small' }
vertical
>
<TreeElement
<SimpleTree
checkStrictly
checkable
checkedKeys={ { checked: checkedKeys, halfChecked: [] } }
Expand Down
14 changes: 0 additions & 14 deletions public/build/2c3c76da-13c1-4739-9070-e84169e8fc17/entrypoints.json

This file was deleted.

Loading

0 comments on commit 8be6bdd

Please sign in to comment.