tree building

pull/5370/head
filip mertens 1 year ago
parent 418f4ea2f6
commit 8e5552fd5f
  1. 13
      libs/remix-ui/tree-view/src/lib/tree-view-item/tree-view-item.tsx
  2. 4
      libs/remix-ui/workspace/src/lib/components/file-label.tsx
  3. 84
      libs/remix-ui/workspace/src/lib/components/file-render.tsx

@ -5,11 +5,11 @@ import './tree-view-item.css'
export const TreeViewItem = (props: TreeViewItemProps) => { export const TreeViewItem = (props: TreeViewItemProps) => {
const {id, children, label, labelClass, expand, iconX = 'fas fa-caret-right', iconY = '', icon, controlBehaviour = false, innerRef, showIcon = true, ...otherProps} = props const {id, children, label, labelClass, expand, iconX = 'fas fa-caret-right', iconY = '', icon, controlBehaviour = false, innerRef, showIcon = true, ...otherProps} = props
const [isExpanded, setIsExpanded] = useState(false)
useEffect(() => { useEffect(() => {
//consolelog('tree view item', id) setIsExpanded(expand)
},[id]) }, [expand])
return ( return (
<li ref={innerRef} key={`treeViewLi${id}`} data-id={`treeViewLi${id}`} className="li_tv" {...otherProps}> <li ref={innerRef} key={`treeViewLi${id}`} data-id={`treeViewLi${id}`} className="li_tv" {...otherProps}>
@ -17,17 +17,16 @@ export const TreeViewItem = (props: TreeViewItemProps) => {
key={`treeViewDiv${id}`} key={`treeViewDiv${id}`}
data-id={`treeViewDiv${id}`} data-id={`treeViewDiv${id}`}
className={`d-flex flex-row align-items-center ${labelClass}`} className={`d-flex flex-row align-items-center ${labelClass}`}
onClick={() => !controlBehaviour // && setIsExpanded(!isExpanded) onClick={() => !controlBehaviour && setIsExpanded(!isExpanded)}
}
> >
{children && showIcon ? ( {children && showIcon ? (
<div className={expand ? `pl-2 ${iconY}` : `pl-2 ${iconX} caret caret_tv`} style={{visibility: children ? 'visible' : 'hidden'}}></div> <div className={isExpanded ? `pl-2 ${iconY}` : `pl-2 ${iconX} caret caret_tv`} style={{visibility: children ? 'visible' : 'hidden'}}></div>
) : icon ? ( ) : icon ? (
<div className={`pr-2 pl-2 ${icon} caret caret_tv`}></div> <div className={`pr-2 pl-2 ${icon} caret caret_tv`}></div>
) : null} ) : null}
<span className="w-100 ml-1 pl-2">{label}</span> <span className="w-100 ml-1 pl-2">{label}</span>
</div> </div>
{expand ? children : null} {isExpanded ? children : null}
</li> </li>
) )
} }

@ -23,10 +23,6 @@ export const FileLabel = (props: FileLabelProps) => {
const [fileStateClasses, setFileStateClasses] = useState<string>('') const [fileStateClasses, setFileStateClasses] = useState<string>('')
const labelRef = useRef(null) const labelRef = useRef(null)
useEffect(() => {
//consolelog('file label', file)
},[file])
useEffect(() => { useEffect(() => {
if (focusEdit.element && file.path) { if (focusEdit.element && file.path) {
setIsEditable(focusEdit.element === file.path) setIsEditable(focusEdit.element === file.path)

@ -1,21 +1,21 @@
// eslint-disable-next-line no-use-before-define // eslint-disable-next-line no-use-before-define
import React, { SyntheticEvent, useEffect, useState } from 'react' import React, {SyntheticEvent, useEffect, useState} from 'react'
import { FileType, WorkspaceElement } from '../types' import {FileType, WorkspaceElement} from '../types'
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
import { TreeView, TreeViewItem } from '@remix-ui/tree-view' import {TreeView, TreeViewItem} from '@remix-ui/tree-view'
import { getPathIcon } from '@remix-ui/helper' import {getPathIcon} from '@remix-ui/helper'
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
import { FileLabel } from './file-label' import {FileLabel} from './file-label'
import { fileDecoration, FileDecorationIcons } from '@remix-ui/file-decorators' import {fileDecoration, FileDecorationIcons} from '@remix-ui/file-decorators'
import { Draggable } from '@remix-ui/drag-n-drop' import {Draggable} from '@remix-ui/drag-n-drop'
import { fileKeySort } from '../utils' import { fileKeySort } from '../utils'
export interface RenderFileProps { export interface RenderFileProps {
file: FileType file: FileType
index: number index: number
focusEdit: { element: string; type: string; isNew: boolean; lastEdit: string } focusEdit: {element: string; type: string; isNew: boolean; lastEdit: string}
focusElement: { key: string; type: WorkspaceElement }[] focusElement: {key: string; type: WorkspaceElement}[]
focusContext: { element: string; x: number; y: number; type: string } focusContext: {element: string; x: number; y: number; type: string}
ctrlKey: boolean ctrlKey: boolean
expandPath: string[] expandPath: string[]
hideIconsMenu?: React.Dispatch<React.SetStateAction<boolean>> hideIconsMenu?: React.Dispatch<React.SetStateAction<boolean>>
@ -29,24 +29,19 @@ export interface RenderFileProps {
} }
export const FileRender = (props: RenderFileProps) => { export const FileRender = (props: RenderFileProps) => {
const { file } = props const [file, setFile] = useState<FileType>({} as FileType)
const [hover, setHover] = useState<boolean>(false) const [hover, setHover] = useState<boolean>(false)
//const [icon, setIcon] = useState<string>('') const [icon, setIcon] = useState<string>('')
const [childrenKeys, setChildrenKeys] = useState<string[]>([]) const [childrenKeys, setChildrenKeys] = useState<string[]>([])
useEffect(() => { useEffect(() => {
//if (props.file && props.file.path && props.file.type) { if (props.file && props.file.path && props.file.type) {
// //consolelog('set icon', props.file.path) setFile(props.file)
// setIcon(getPathIcon(props.file.path)) setIcon(getPathIcon(props.file.path))
//} }
}, [props.file]) }, [props.file])
useEffect(() => { useEffect(() => {
//consolelog('file render', props.file.path)
}, [])
useEffect(() => {
return
if (file.child) { if (file.child) {
try { try {
const children: FileType[] = file.child as any const children: FileType[] = file.child as any
@ -101,13 +96,8 @@ export const FileRender = (props: RenderFileProps) => {
event.stopPropagation() event.stopPropagation()
setHover(true) setHover(true)
} }
//consolelog('eval file render', file.path)
if (!file.path) return (<></>) if (file.isDirectory) {
///return (<><div className='btn btn-primary'>file</div></>)
if (file.isDirectory && false) {
return ( return (
<TreeViewItem <TreeViewItem
id={`treeViewItem${file.path}`} id={`treeViewItem${file.path}`}
@ -134,7 +124,7 @@ export const FileRender = (props: RenderFileProps) => {
> >
{file.child ? ( {file.child ? (
<TreeView id={`treeView${file.path}`} key={`treeView${file.path}`} {...spreadProps}> <TreeView id={`treeView${file.path}`} key={`treeView${file.path}`} {...spreadProps}>
{Object.keys(file.child).map((key, index) => ( {childrenKeys.map((key, index) => (
<FileRender <FileRender
file={file.child[key]} file={file.child[key]}
fileDecorations={props.fileDecorations} fileDecorations={props.fileDecorations}
@ -158,24 +148,28 @@ export const FileRender = (props: RenderFileProps) => {
)} )}
</TreeViewItem> </TreeViewItem>
) )
} else if (!file.isDirectory) { } else {
//consolelog('start do file render', file.path)
return ( return (
<> <TreeViewItem
<li ref={null} key={`treeViewLi${file.path}`} data-id={`treeViewLi${file.path}`} className="li_tv"> id={`treeViewItem${file.path}`}
<div key={`treeView${file.path}`}
key={`treeViewDiv${file.path}`} label={
data-id={`treeViewDiv${file.path}`} <>
className={`d-flex flex-row align-items-center ${labelClass}`} <Draggable isDraggable={props.focusEdit.element !== null} file={file} expandedPath={props.expandPath} handleClickFolder={props.handleClickFolder}>
onClick={() => {}} <div className="d-flex flex-row">
> <FileLabel fileDecorations={props.fileDecorations} file={file} focusEdit={props.focusEdit} editModeOff={props.editModeOff} dragStatus={props.dragStatus} />
<div className={`pr-2 pl-2 ${getPathIcon(file.path)} caret caret_tv`}></div> <FileDecorationIcons file={file} fileDecorations={props.fileDecorations} />
<span className="w-100 ml-1 pl-2">{file.name}</span> </div>
</div> </Draggable>
</li> </>
</> }
onClick={handleFileClick}
onContextMenu={handleContextMenu}
icon={icon}
labelClass={labelClass}
onMouseOver={handleMouseOver}
onMouseOut={handleMouseOut}
/>
) )
} else {
return <></>
} }
} }

Loading…
Cancel
Save