Skip to content

Commit 23d3d21

Browse files
committed
feat: implement async transitions for flow service operations to enhance performance and user experience
1 parent 0ded2fd commit 23d3d21

File tree

5 files changed

+35
-27
lines changed

5 files changed

+35
-27
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export const DFlowTabDefault: React.FC<DFlowTabDefaultProps> = (props) => {
3131
const {node, flowId, depthLevel, scopeLevel, nodeLevel} = props
3232
const functionService = useService(DFlowFunctionReactiveService)
3333
const flowService = useService(DFlowReactiveService)
34+
const [, startTransition] = React.useTransition()
35+
3436
const definition = functionService.getById(node.functionDefinition?.id!!)
3537
const paramDefinitions = React.useMemo(() => {
3638
const map: Record<string, ParameterDefinitionView> = {}
@@ -56,7 +58,10 @@ export const DFlowTabDefault: React.FC<DFlowTabDefaultProps> = (props) => {
5658
if (!parameter) return null
5759

5860
const submitValue = (value: NodeFunction | LiteralValue | ReferenceValue | undefined) => {
59-
flowService.setParameterValue(flowId, node.id!!, parameter.id!!, value)
61+
startTransition(async () => {
62+
await flowService.setParameterValue(flowId, node.id!!, parameter.id!!, value)
63+
})
64+
6065
}
6166

6267
const submitValueEvent = (event: any) => {

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ export interface DFlowTabTriggerProps {
1818
export const DFlowTabTrigger: React.FC<DFlowTabTriggerProps> = (props) => {
1919

2020
const {instance} = props
21+
2122
const flowTypeService = useService(DFlowTypeReactiveService)
2223
const flowService = useService(DFlowReactiveService)
24+
const [,startTransition] = React.useTransition()
25+
2326
const definition = flowTypeService.getById(instance.type?.id!!)
2427

28+
2529
const suggestionsById: Record<string, DFlowSuggestion[]> = {}
2630
definition?.flowTypeSettings?.forEach(settingDefinition => {
2731
suggestionsById[settingDefinition.identifier!!] = useSuggestions({dataType: settingDefinition.dataType}, [], instance.id, 0, [0], 0)
@@ -45,11 +49,14 @@ export const DFlowTabTrigger: React.FC<DFlowTabTriggerProps> = (props) => {
4549
const defaultValue = setting.value?.__typename === "LiteralValue" ? typeof setting?.value == "object" ? JSON.stringify(setting?.value) : setting?.value : typeof setting?.value == "object" ? JSON.stringify(setting?.value) : setting?.value
4650

4751
const submitValue = (value: NodeParameterValue) => {
48-
if (value.__typename == "LiteralValue") {
49-
flowService.setSettingValue(props.instance.id, setting.id, value.value)
50-
} else {
51-
flowService.setSettingValue(props.instance.id, setting.id, value)
52-
}
52+
startTransition(async () => {
53+
if (value.__typename == "LiteralValue") {
54+
await flowService.setSettingValue(props.instance.id, setting.id, value.value)
55+
} else {
56+
await flowService.setSettingValue(props.instance.id, setting.id, value)
57+
}
58+
})
59+
5360
}
5461

5562
const submitValueEvent = (event: any) => {

src/components/d-flow-function/DFlowFunctionSuggestionCard.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import {Code0Component} from "../../utils";
1+
import {Code0Component, useService} from "../../utils";
22
import {Handle, Node, NodeProps, Position} from "@xyflow/react";
33
import React, {memo} from "react";
44
import {Button} from "../button/Button";
55
import {IconPlus} from "@tabler/icons-react";
66
import {useSuggestions} from "../d-flow-suggestion/DFlowSuggestion.hook";
7-
import {useService} from "../../utils";
87
import {DFlowReactiveService} from "../d-flow";
98
import {DFlowSuggestionMenu} from "../d-flow-suggestion/DFlowSuggestionMenu";
109
import type {Flow, NodeFunction} from "@code0-tech/sagittarius-graphql-types";
@@ -19,14 +18,17 @@ export type DFlowFunctionSuggestionCardProps = NodeProps<Node<DFlowFunctionSugge
1918

2019
export const DFlowFunctionSuggestionCard: React.FC<DFlowFunctionSuggestionCardProps> = memo((props) => {
2120

21+
const [, startTransition] = React.useTransition()
2222
const result = useSuggestions(undefined, [], props.data.flowId, 0, [0], 0)
2323
const flowService = useService(DFlowReactiveService)
2424
const flow = flowService.getById(props.data.flowId)
2525

2626
return <DFlowSuggestionMenu onSuggestionSelect={suggestion => {
27-
if (suggestion.value.__typename === "NodeFunction") {
28-
flowService.addNextNodeById(flow?.id, props.data.parentFunction?.id ?? null, suggestion.value)
29-
}
27+
startTransition(async () => {
28+
if (suggestion.value.__typename === "NodeFunction") {
29+
await flowService.addNextNodeById(flow?.id, props.data.parentFunction?.id ?? null, suggestion.value)
30+
}
31+
})
3032
}} suggestions={result} triggerContent={
3133
<Button paddingSize={"xxs"} variant={"normal"} color={"secondary"}>
3234
<Handle

src/components/d-flow-panel/DFlowPanelControl.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const DFlowPanelControl: React.FC<DFlowPanelControlProps> = (props) => {
2626
const fileTabsService = useService(FileTabsService)
2727
const fileTabsStore = useStore(FileTabsService)
2828
const flowService = useService(DFlowReactiveService)
29+
const [, startTransition] = React.useTransition()
2930

3031
//memoized values
3132
const activeTab = React.useMemo(() => {
@@ -37,15 +38,21 @@ export const DFlowPanelControl: React.FC<DFlowPanelControlProps> = (props) => {
3738
const deleteActiveNode = React.useCallback(() => {
3839
if (!activeTab) return
3940
// @ts-ignore
40-
flowService.deleteNodeById((activeTab.content.props.flowId as Flow['id']), (activeTab.content.props.node.id as NodeFunction['id']))
41+
startTransition(async () => {
42+
await flowService.deleteNodeById((activeTab.content.props.flowId as Flow['id']), (activeTab.content.props.node.id as NodeFunction['id']))
43+
})
4144
fileTabsService.deleteById(activeTab.id)
4245
}, [activeTab, flowService])
4346

4447
const addNodeToFlow = React.useCallback((suggestion: any) => {
4548
if (flowId && suggestion.value.__typename === "NodeFunction" && "node" in activeTab.content.props) {
46-
flowService.addNextNodeById(flowId, (activeTab.content.props.node.id as NodeFunction['id']) ?? undefined, suggestion.value)
49+
startTransition(async () => {
50+
await flowService.addNextNodeById(flowId, (activeTab.content.props.node.id as NodeFunction['id']) ?? undefined, suggestion.value)
51+
})
4752
} else {
48-
flowService.addNextNodeById(flowId, null, suggestion.value)
53+
startTransition(async () => {
54+
await flowService.addNextNodeById(flowId, null, suggestion.value)
55+
})
4956
}
5057
}, [flowId, flowService, activeTab])
5158

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,6 @@ export abstract class DFlowReactiveService extends ReactiveArrayService<Flow> {
3939
}
4040
}
4141

42-
async deleteById(flowId: Flow['id']): Promise<void> {
43-
const index = this.values().findIndex(f => f.id === flowId)
44-
this.delete(index)
45-
}
46-
47-
async renameById(flowId: Flow['id'], newName: string): Promise<void> {
48-
const flow = this.getById(flowId)
49-
const index = this.values().findIndex(f => f.id === flowId)
50-
if (!flow) return
51-
flow.name = newName
52-
this.set(index, flow)
53-
}
54-
5542
getNodeById(flowId: Flow['id'], nodeId: NodeFunction['id']): NodeFunction | undefined {
5643
return this.getById(flowId)?.nodes?.nodes?.find(node => node?.id === nodeId)!!
5744
}

0 commit comments

Comments
 (0)