Skip to content

Commit d22fda9

Browse files
committed
feat: add create dialog and refactor rename dialog in DFlowFolderContextMenu for improved functionality
1 parent 51519f5 commit d22fda9

File tree

1 file changed

+12
-31
lines changed

1 file changed

+12
-31
lines changed

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

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import {Button} from "../button/Button";
2020
import {useService, useStore} from "../../utils";
2121
import {DFlowTypeReactiveService} from "../d-flow-type";
2222
import {DFlowFolderItemPathInput} from "./DFlowFolderItemPathInput";
23-
import {Flow} from "@code0-tech/sagittarius-graphql-types";
23+
import {Flow, FlowType} from "@code0-tech/sagittarius-graphql-types";
24+
import {DFlowFolderRenameDialog} from "./DFlowFolderRenameDialog";
25+
import {DFlowFolderCreateDialog} from "./DFlowFolderCreateDialog";
2426

2527
export interface DFlowFolderContextMenuGroupData {
2628
name: string
@@ -49,6 +51,8 @@ export const DFlowFolderContextMenu: React.FC<DFlowFolderContextMenuProps> = (pr
4951
const flowTypes = React.useMemo(() => flowTypeService.values(), [flowTypeStore])
5052
const [deleteDialogOpen, setDeleteDialogOpen] = React.useState(false)
5153
const [renameDialogOpen, setRenameDialogOpen] = React.useState(false)
54+
const [createDialogOpen, setCreateDialogOpen] = React.useState(false)
55+
const [flowTypeId, setFlowTypeId] = React.useState<FlowType['id']>(null)
5256

5357
return <>
5458
<Dialog open={deleteDialogOpen} onOpenChange={(open) => setDeleteDialogOpen(open)}>
@@ -83,35 +87,9 @@ export const DFlowFolderContextMenu: React.FC<DFlowFolderContextMenuProps> = (pr
8387
</DialogPortal>
8488
</Dialog>
8589

86-
<Dialog open={renameDialogOpen} onOpenChange={(open) => setRenameDialogOpen(open)}>
87-
<DialogPortal>
88-
<DialogContent autoFocus showCloseButton
89-
title={props.contextData.type == "item" ? "Rename flow" : "Rename folder"}>
90-
<div>
91-
<DFlowFolderItemPathInput
92-
description={"You can choose a new name here and only use alphanumeric names."}
93-
title={props.contextData.type == "item" ? "Name of the flow" : "Name of the folder"}
94-
defaultValue={props.contextData.name}/>
95-
</div>
96-
<Flex justify={"space-between"} align={"center"}>
97-
<DialogClose asChild>
98-
<Button color={"secondary"}>No, go back!</Button>
99-
</DialogClose>
100-
<DialogClose asChild>
101-
<Button color={"success"} onClick={() => {
102-
if (props.contextData.type === "item") {
103-
props.onDelete?.(props.contextData.flow)
104-
} else if (props.contextData.type === "group") {
105-
props.contextData.flows.forEach(flow => {
106-
props.onDelete?.(flow)
107-
})
108-
}
109-
}}>Yes, save!</Button>
110-
</DialogClose>
111-
</Flex>
112-
</DialogContent>
113-
</DialogPortal>
114-
</Dialog>
90+
<DFlowFolderRenameDialog onOpenChange={open => setRenameDialogOpen(open)} open={renameDialogOpen} {...props}/>
91+
92+
<DFlowFolderCreateDialog flowTypeId={flowTypeId} onOpenChange={open => setCreateDialogOpen(open)} open={createDialogOpen} {...props}/>
11593

11694
<ContextMenu>
11795
<ContextMenuTrigger asChild>
@@ -128,7 +106,10 @@ export const DFlowFolderContextMenu: React.FC<DFlowFolderContextMenuProps> = (pr
128106
</ContextMenuSubTrigger>
129107
<ContextMenuSubContent>
130108
{flowTypes.map(flowType => {
131-
return <ContextMenuItem key={flowType.id}>
109+
return <ContextMenuItem key={flowType.id} onSelect={() => {
110+
setFlowTypeId(flowType.id)
111+
setCreateDialogOpen(true)
112+
}}>
132113
{flowType.names?.nodes!![0]?.content ?? flowType.id}
133114
</ContextMenuItem>
134115
})}

0 commit comments

Comments
 (0)