Skip to content

Commit 6bdc7e1

Browse files
committed
feat: extend flow hooks and components to support namespace and project IDs
1 parent c0696f9 commit 6bdc7e1

File tree

6 files changed

+49
-25
lines changed

6 files changed

+49
-25
lines changed

src/components/d-flow-file/DFlowTabs.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {IconArrowDown, IconArrowUp, IconCornerDownLeft, IconDotsVertical, IconPl
88
import {FileTabsView} from "../file-tabs/FileTabs.view";
99
import {DLayout} from "../d-layout/DLayout";
1010
import {ButtonGroup} from "../button-group/ButtonGroup";
11-
import {Flow} from "@code0-tech/sagittarius-graphql-types";
11+
import {Flow, type Namespace, type NamespaceProject} from "@code0-tech/sagittarius-graphql-types";
1212
import {DFlowReactiveService} from "../d-flow";
1313
import {DFlowTypeReactiveService} from "../d-flow-type";
1414
import {Card} from "../card/Card";
@@ -18,11 +18,13 @@ import {Spacing} from "../spacing/Spacing";
1818

1919
export interface DFlowTabsProps {
2020
flowId: Flow['id']
21+
namespaceId: Namespace['id']
22+
projectId: NamespaceProject['id']
2123
}
2224

2325
export const DFlowTabs: React.FC<DFlowTabsProps> = (props) => {
2426

25-
const {flowId} = props
27+
const {flowId, namespaceId, projectId} = props
2628

2729
const fileTabsService = useService(FileTabsService)
2830
const fileTabsStore = useStore(FileTabsService)
@@ -32,7 +34,7 @@ export const DFlowTabs: React.FC<DFlowTabsProps> = (props) => {
3234
const flowTypeStore = useStore(DFlowTypeReactiveService)
3335
const id = React.useId()
3436

35-
const flow = React.useMemo(() => flowService.getById(flowId), [flowStore])
37+
const flow = React.useMemo(() => flowService.getById(flowId, {namespaceId, projectId}), [flowStore])
3638
const flowType = React.useMemo(() => flowTypeService.getById(flow?.type?.id!!), [flowTypeStore, flow])
3739
const activeTabId = React.useMemo(() => {
3840
return fileTabsStore.find((t: any) => (t as any).active)?.id ?? fileTabsService.getActiveTab()?.id;

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ import {
88
IconChevronRight,
99
IconDots,
1010
IconFile,
11-
IconFolder,
1211
IconFolderFilled,
1312
IconFolderOpen
1413
} from "@tabler/icons-react"
15-
import type {Flow, FlowType, Scalars} from "@code0-tech/sagittarius-graphql-types"
14+
import type {Flow, FlowType, Namespace, NamespaceProject, Scalars} from "@code0-tech/sagittarius-graphql-types"
1615
import {DFlowReactiveService} from "../d-flow"
1716
import {ScrollArea, ScrollAreaScrollbar, ScrollAreaThumb, ScrollAreaViewport} from "../scroll-area/ScrollArea"
1817
import {Flex} from "../flex/Flex"
@@ -28,6 +27,8 @@ import {md5} from "js-md5";
2827

2928
export interface DFlowFolderProps {
3029
activeFlowId: Scalars["FlowID"]["output"]
30+
namespaceId: Namespace['id']
31+
projectId: NamespaceProject['id']
3132
onRename?: (contextData: DFlowFolderContextMenuGroupData | DFlowFolderContextMenuItemData) => void
3233
onDelete?: (contextData: DFlowFolderContextMenuGroupData | DFlowFolderContextMenuItemData) => void
3334
onCreate?: (type: FlowType['id']) => void
@@ -58,7 +59,7 @@ export interface DFlowFolderItemProps extends DFlowFolderProps, Omit<Code0Compon
5859

5960
export const DFlowFolder = React.forwardRef<DFlowFolderHandle, DFlowFolderProps>((props, ref) => {
6061

61-
const {activeFlowId} = props
62+
const {activeFlowId, namespaceId, projectId} = props
6263

6364
const flowService = useService(DFlowReactiveService)
6465
const flowStore = useStore(DFlowReactiveService)
@@ -74,7 +75,7 @@ export const DFlowFolder = React.forwardRef<DFlowFolderHandle, DFlowFolderProps>
7475
p.replace(/^\/+|\/+$/g, "").split("/").filter(Boolean)
7576

7677
const flows = React.useMemo<Flow[]>(() => {
77-
const raw = (flowService.values?.() ?? []) as Flow[]
78+
const raw = (flowService.values?.({namespaceId, projectId}) ?? []) as Flow[]
7879
return raw.filter(f => !!f?.name)
7980
}, [flowStore])
8081

@@ -261,7 +262,8 @@ export const DFlowFolderItem: React.FC<DFlowFolderItemProps> = (props) => {
261262
flow: flow,
262263
type: "item"
263264
}} {...rest}>
264-
<div {...mergeCode0Props(`d-folder__item ${active ? "d-folder__item--active" : ""}`, rest)} onClick={() => onSelect?.(flow)}>
265+
<div {...mergeCode0Props(`d-folder__item ${active ? "d-folder__item--active" : ""}`, rest)}
266+
onClick={() => onSelect?.(flow)}>
265267
<IconFile color={`hsl(${hashToHue(colorHash)}, 100%, 72%)`} size={12}/>
266268
<Text>{name}</Text>
267269
</div>

src/components/d-flow/DFlow.edges.hook.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,41 @@ import {Edge} from "@xyflow/react";
44
import {DFlowFunctionReactiveService} from "../d-flow-function";
55
import {DFlowDataTypeReactiveService} from "../d-flow-data-type";
66
import React from "react";
7-
import type {DataTypeIdentifier, Flow, NodeFunction, Scalars} from "@code0-tech/sagittarius-graphql-types";
7+
import type {
8+
DataTypeIdentifier,
9+
Flow,
10+
Namespace,
11+
NamespaceProject,
12+
NodeFunction,
13+
Scalars
14+
} from "@code0-tech/sagittarius-graphql-types";
815
import {md5} from "js-md5";
916
import {DFlowEdgeDataProps} from "./DFlowEdge";
1017

1118
export const FLOW_EDGE_RAINBOW: string[] = [
12-
'rgba(255, 255, 255, 0.25)', // rot
19+
'rgba(255, 255, 255, 0.25)',
1320
];
1421

1522
// @ts-ignore
16-
export const useFlowEdges = (flowId: Flow['id']): Edge<DFlowEdgeDataProps>[] => {
23+
export const useFlowEdges = (flowId: Flow['id'], namespaceId?: Namespace['id'], projectId?: NamespaceProject['id']): Edge<DFlowEdgeDataProps>[] => {
1724
const flowService = useService(DFlowReactiveService);
1825
const flowStore = useStore(DFlowReactiveService)
1926
const functionService = useService(DFlowFunctionReactiveService);
2027
const functionStore = useStore(DFlowFunctionReactiveService)
2128
const dataTypeService = useService(DFlowDataTypeReactiveService);
2229
const dataTypeStore = useStore(DFlowDataTypeReactiveService)
2330

24-
const flow = React.useMemo(() => flowService.getById(flowId), [flowId, flowStore])
31+
const flow = React.useMemo(() => flowService.getById(flowId, {namespaceId, projectId}), [flowId, flowStore])
2532

2633
return React.useMemo(() => {
2734
if (!flow) return [];
2835

2936
// @ts-ignore
3037
const edges: Edge<DFlowEdgeDataProps>[] = [];
3138

32-
/** merkt sich für jede Function-Card die Gruppen-IDs,
33-
* **für die wirklich ein Funktions-Wert existiert** */
3439
const groupsWithValue = new Map<string, string[]>();
3540

36-
let idCounter = 0; // globale, fortlaufende Id-Vergabe
41+
let idCounter = 0;
3742

3843
const functionCache = new Map<string, ReturnType<typeof functionService.getById>>();
3944
const dataTypeCache = new Map<DataTypeIdentifier, ReturnType<typeof dataTypeService.getDataType>>();

src/components/d-flow/DFlow.nodes.hook.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import {DFlowReactiveService} from "./DFlow.service";
33
import {Node} from "@xyflow/react";
44
import {DFlowFunctionReactiveService} from "../d-flow-function";
55
import {DFlowDataTypeReactiveService} from "../d-flow-data-type";
6-
import type {DataTypeIdentifier, Flow, NodeFunction, Scalars} from "@code0-tech/sagittarius-graphql-types";
6+
import type {
7+
DataTypeIdentifier,
8+
Flow,
9+
Namespace,
10+
NamespaceProject,
11+
NodeFunction,
12+
Scalars
13+
} from "@code0-tech/sagittarius-graphql-types";
714
import React from "react";
815
import {DFlowFunctionDefaultCardDataProps} from "../d-flow-function/DFlowFunctionDefaultCard";
916
import {DFlowFunctionSuggestionCardDataProps} from "../d-flow-function/DFlowFunctionSuggestionCard";
@@ -96,15 +103,15 @@ const bestMatchValue = (map: Map<string, string>, input: string): string => {
96103
};
97104

98105
// @ts-ignore
99-
export const useFlowNodes = (flowId: Flow['id']): Node<DFlowFunctionDefaultCardDataProps | DFlowFunctionSuggestionCardDataProps | DFlowFunctionTriggerCardDataProps | DFlowFunctionGroupCardDataProps>[] => {
106+
export const useFlowNodes = (flowId: Flow['id'], namespaceId?: Namespace['id'], projectId?: NamespaceProject['id']): Node<DFlowFunctionDefaultCardDataProps | DFlowFunctionSuggestionCardDataProps | DFlowFunctionTriggerCardDataProps | DFlowFunctionGroupCardDataProps>[] => {
100107
const flowService = useService(DFlowReactiveService);
101108
const flowStore = useStore(DFlowReactiveService);
102109
const functionService = useService(DFlowFunctionReactiveService);
103110
const functionStore = useStore(DFlowFunctionReactiveService);
104111
const dataTypeService = useService(DFlowDataTypeReactiveService);
105112
const dataTypeStore = useStore(DFlowDataTypeReactiveService);
106113

107-
const flow = React.useMemo(() => flowService.getById(flowId), [flowId, flowStore])
114+
const flow = React.useMemo(() => flowService.getById(flowId, {namespaceId, projectId}), [flowId, flowStore])
108115

109116
return React.useMemo(() => {
110117
if (!flow) return [];

src/components/d-flow/DFlow.service.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
FlowInput,
77
FlowSetting,
88
LiteralValue,
9+
Namespace,
10+
NamespaceProject,
911
NamespacesProjectsFlowsCreateInput,
1012
NamespacesProjectsFlowsCreatePayload,
1113
NamespacesProjectsFlowsDeleteInput,
@@ -18,11 +20,15 @@ import {
1820
ReferenceValue
1921
} from "@code0-tech/sagittarius-graphql-types";
2022

23+
export type DFlowDependencies = {
24+
namespaceId: Namespace['id']
25+
projectId: NamespaceProject['id']
26+
}
2127

22-
export abstract class DFlowReactiveService extends ReactiveArrayService<Flow> {
28+
export abstract class DFlowReactiveService extends ReactiveArrayService<Flow, DFlowDependencies> {
2329

24-
getById(id: Flow['id']): Flow | undefined {
25-
return this.values().find(value => value.id === id);
30+
getById(id: Flow['id'], dependencies?: DFlowDependencies): Flow | undefined {
31+
return this.values(dependencies).find(value => value.id === id);
2632
}
2733

2834
protected removeParameterNode(flow: Flow, parameter: NodeParameter): void {

src/components/d-flow/DFlow.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {DFlowFunctionTriggerCard} from "../d-flow-function/DFlowFunctionTriggerC
2020
import {DFlowEdge} from "./DFlowEdge";
2121
import {DFlowPanelSize} from "../d-flow-panel";
2222
import {DFlowValidation} from "../d-flow-validation";
23-
import {Flow} from "@code0-tech/sagittarius-graphql-types";
23+
import {Flow, type Namespace, type NamespaceProject} from "@code0-tech/sagittarius-graphql-types";
2424
import {useFlowNodes} from "./DFlow.nodes.hook";
2525
import {useFlowEdges} from "./DFlow.edges.hook";
2626
import {DFlowPanelControl} from "../d-flow-panel";
@@ -515,6 +515,8 @@ const getCachedLayoutElements = React.cache(getLayoutElements)
515515

516516
export interface DFlowProps extends Code0ComponentProps {
517517
flowId: Flow['id']
518+
namespaceId: Namespace['id']
519+
projectId: NamespaceProject['id']
518520
}
519521

520522
export const DFlow: React.FC<DFlowProps> = (props) => {
@@ -525,7 +527,7 @@ export const DFlow: React.FC<DFlowProps> = (props) => {
525527

526528
const InternalDFlow: React.FC<DFlowProps> = (props) => {
527529

528-
const {flowId} = props
530+
const {flowId, namespaceId, projectId} = props
529531
const nodeTypes = {
530532
default: DFlowFunctionDefaultCard,
531533
group: DFlowFunctionGroupCard,
@@ -537,8 +539,8 @@ const InternalDFlow: React.FC<DFlowProps> = (props) => {
537539
default: DFlowEdge,
538540
}
539541

540-
const initialNodes = useFlowNodes(flowId)
541-
const initialEdges = useFlowEdges(flowId)
542+
const initialNodes = useFlowNodes(flowId, namespaceId, projectId)
543+
const initialEdges = useFlowEdges(flowId, namespaceId, projectId)
542544
const [nodes, setNodes] = useNodesState<Node>([])
543545
const [edges, setEdges, edgeChangeEvent] = useEdgesState<Edge>([])
544546
const updateNodeInternals = useUpdateNodeInternals()

0 commit comments

Comments
 (0)