33import "./DFlowFolder.style.scss"
44import React from "react"
55import { Code0Component , mergeCode0Props , useService , useStore } from "../../utils"
6- import { IconChevronDown , IconChevronRight , IconDots , IconFile , IconFolder , IconFolderOpen } from "@tabler/icons-react"
6+ import {
7+ IconChevronDown ,
8+ IconChevronRight ,
9+ IconDots ,
10+ IconFile ,
11+ IconFolder ,
12+ IconFolderFilled ,
13+ IconFolderOpen
14+ } from "@tabler/icons-react"
715import type { Flow , FlowType , Scalars } from "@code0-tech/sagittarius-graphql-types"
816import { DFlowReactiveService } from "../d-flow"
917import { ScrollArea , ScrollAreaScrollbar , ScrollAreaThumb , ScrollAreaViewport } from "../scroll-area/ScrollArea"
1018import { Flex } from "../flex/Flex"
1119import { Text } from "../text/Text"
1220import { Button } from "../button/Button"
13- import { DFlowFolderContextMenu } from "./DFlowFolderContextMenu" ;
21+ import {
22+ DFlowFolderContextMenu ,
23+ DFlowFolderContextMenuGroupData ,
24+ DFlowFolderContextMenuItemData
25+ } from "./DFlowFolderContextMenu" ;
1426import { md5 } from "js-md5" ;
1527
1628
1729export interface DFlowFolderProps {
1830 activeFlowId : Scalars [ "FlowID" ] [ "output" ]
19- onRename ?: ( flow : Flow , newName : string ) => void
20- onDelete ?: ( flow : Flow ) => void
21- onCreate ?: ( name : string , type : FlowType [ 'id' ] ) => void
31+ onRename ?: ( contextData : DFlowFolderContextMenuGroupData | DFlowFolderContextMenuItemData ) => void
32+ onDelete ?: ( contextData : DFlowFolderContextMenuGroupData | DFlowFolderContextMenuItemData ) => void
33+ onCreate ?: ( type : FlowType [ 'id' ] ) => void
34+ onSelect ?: ( flow : Flow ) => void
2235}
2336
2437export type DFlowFolderHandle = {
@@ -29,14 +42,14 @@ export type DFlowFolderHandle = {
2942
3043type OpenMode = "default" | "allOpen" | "allClosed" | "activePath"
3144
32- export interface DFlowFolderGroupProps extends DFlowFolderProps , Omit < Code0Component < HTMLDivElement > , "controls " > {
45+ export interface DFlowFolderGroupProps extends DFlowFolderProps , Omit < Code0Component < HTMLDivElement > , "onSelect " > {
3346 name : string
3447 children : React . ReactElement < DFlowFolderItemProps > | React . ReactElement < DFlowFolderItemProps > [ ] | React . ReactElement < DFlowFolderGroupProps > | React . ReactElement < DFlowFolderGroupProps > [ ]
3548 defaultOpen ?: boolean
3649 flows : Flow [ ]
3750}
3851
39- export interface DFlowFolderItemProps extends DFlowFolderProps , Code0Component < HTMLDivElement > {
52+ export interface DFlowFolderItemProps extends DFlowFolderProps , Omit < Code0Component < HTMLDivElement > , "onSelect" > {
4053 name : string
4154 path : string
4255 active ?: boolean
@@ -208,14 +221,12 @@ export const DFlowFolderGroup: React.FC<DFlowFolderGroupProps> = (props) => {
208221 return < >
209222 < DFlowFolderContextMenu contextData = { {
210223 name : name ,
211- flows : flows ,
212- type : "group "
224+ flow : flows ,
225+ type : "folder "
213226 } } { ...rest } >
214227 < div onClick = { ( ) => setOpen ( prevState => ! prevState ) } { ...mergeCode0Props ( `d-folder` , rest ) } >
215228 < Flex align = { "center" } style = { { gap : "0.35rem" } } >
216- < span className = { "d-folder__icon" } >
217- { open ? < IconFolderOpen size = { 12 } /> : < IconFolder size = { 12 } /> }
218- </ span >
229+ { open ? < IconFolderOpen size = { 12 } /> : < IconFolderFilled size = { 12 } /> }
219230 < Text > { name } </ Text >
220231 </ Flex >
221232 < Flex align = { "center" } style = { { gap : "0.35rem" } } >
@@ -236,7 +247,7 @@ export const DFlowFolderGroup: React.FC<DFlowFolderGroupProps> = (props) => {
236247
237248export const DFlowFolderItem : React . FC < DFlowFolderItemProps > = ( props ) => {
238249
239- const { name, path, flow, active, ...rest } = props
250+ const { name, path, flow, onSelect , active, ...rest } = props
240251
241252 const colorHash = md5 ( path + name )
242253 const hashToHue = ( md5 : string ) : number => {
@@ -250,7 +261,7 @@ export const DFlowFolderItem: React.FC<DFlowFolderItemProps> = (props) => {
250261 flow : flow ,
251262 type : "item"
252263 } } { ...rest } >
253- < div { ...mergeCode0Props ( `d-folder__item ${ active ? "d-folder__item--active" : "" } ` , rest ) } >
264+ < div { ...mergeCode0Props ( `d-folder__item ${ active ? "d-folder__item--active" : "" } ` , rest ) } onClick = { ( ) => onSelect ?. ( flow ) } >
254265 < IconFile color = { `hsl(${ hashToHue ( colorHash ) } , 100%, 72%)` } size = { 12 } />
255266 < Text > { name } </ Text >
256267 </ div >
0 commit comments