Skip to content

Commit f5a5cb1

Browse files
committed
feat: enhance DFlowFolder component with context menu integration and item selection support
1 parent 086dc6a commit f5a5cb1

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

src/components/d-flow-folder/DFlowFolder.tsx

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,35 @@
33
import "./DFlowFolder.style.scss"
44
import React from "react"
55
import {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"
715
import type {Flow, FlowType, Scalars} from "@code0-tech/sagittarius-graphql-types"
816
import {DFlowReactiveService} from "../d-flow"
917
import {ScrollArea, ScrollAreaScrollbar, ScrollAreaThumb, ScrollAreaViewport} from "../scroll-area/ScrollArea"
1018
import {Flex} from "../flex/Flex"
1119
import {Text} from "../text/Text"
1220
import {Button} from "../button/Button"
13-
import {DFlowFolderContextMenu} from "./DFlowFolderContextMenu";
21+
import {
22+
DFlowFolderContextMenu,
23+
DFlowFolderContextMenuGroupData,
24+
DFlowFolderContextMenuItemData
25+
} from "./DFlowFolderContextMenu";
1426
import {md5} from "js-md5";
1527

1628

1729
export 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

2437
export type DFlowFolderHandle = {
@@ -29,14 +42,14 @@ export type DFlowFolderHandle = {
2942

3043
type 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

237248
export 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

Comments
 (0)