Skip to content

Commit b4a6da5

Browse files
committed
feat: using JSONView instead of Editor for better performance
1 parent d54908a commit b4a6da5

1 file changed

Lines changed: 39 additions & 42 deletions

File tree

src/packages/ce/src/flow/views/FlowExecutionResultView.tsx

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
Gantt,
2121
getRelativeValue,
2222
hashToColor,
23+
JsonView,
2324
Menu,
2425
MenuContent,
2526
MenuItem,
@@ -41,7 +42,6 @@ import {
4142
} from "@code0-tech/pictor";
4243
import {FlowService} from "@edition/flow/services/Flow.service";
4344
import {IconPlayerPlayFilled, IconPlus} from "@tabler/icons-react";
44-
import {Editor} from "@code0-tech/pictor/dist/components/editor/Editor";
4545
import {
4646
FileTabs,
4747
FileTabsContent,
@@ -69,6 +69,36 @@ export interface NodeGanttItem extends GanttItem {
6969
}
7070
}
7171

72+
const ExecutionTooltipScrollArea: React.FC<React.PropsWithChildren> = ({children}) => {
73+
const contentRef = React.useRef<HTMLDivElement>(null)
74+
const [height, setHeight] = React.useState<number>()
75+
76+
React.useLayoutEffect(() => {
77+
const el = contentRef.current
78+
if (!el) return
79+
const observer = new ResizeObserver((entries) => {
80+
const entry = entries[0]
81+
if (entry) setHeight(entry.contentRect.height)
82+
})
83+
observer.observe(el)
84+
return () => observer.disconnect()
85+
}, [])
86+
87+
return (
88+
<ScrollArea h={height !== undefined ? `${height}px` : undefined}
89+
mah={"var(--radix-popper-available-height)"}>
90+
<ScrollAreaViewport>
91+
<div ref={contentRef}>
92+
{children}
93+
</div>
94+
</ScrollAreaViewport>
95+
<ScrollAreaScrollbar orientation={"vertical"}>
96+
<ScrollAreaThumb/>
97+
</ScrollAreaScrollbar>
98+
</ScrollArea>
99+
)
100+
}
101+
72102
export const FlowExecutionResultView: React.FC = () => {
73103

74104
const params = useParams()
@@ -279,7 +309,7 @@ export const FlowExecutionResultView: React.FC = () => {
279309
item.type === "node" ? item?.data?.payload?.functionDefinition?.displayIcon : item.type === "function" ? item?.data?.payload?.displayIcon : item?.data?.payload?.type?.displayIcon,
280310
)
281311

282-
return <Tooltip key={item.id} delayDuration={700}>
312+
return <Tooltip key={item.id} delayDuration={0}>
283313
<TooltipTrigger asChild>
284314
<Flex align={"center"} justify={"start"} w={"100%"} h={"100%"}
285315
style={{cursor: "pointer"}}>
@@ -320,11 +350,10 @@ export const FlowExecutionResultView: React.FC = () => {
320350
</Flex>
321351
</TooltipTrigger>
322352
<TooltipPortal>
323-
<TooltipContent forceMount sideOffset={8} align={"start"}
353+
<TooltipContent sideOffset={8} align={"start"}
324354
maw={"300px"}
325355
mah={"var(--radix-popper-available-height)"}>
326-
<ScrollArea h={"var(--radix-popper-available-height)"}>
327-
<ScrollAreaViewport>
356+
<ExecutionTooltipScrollArea>
328357
<div>
329358

330359
<Flex align={"center"} justify={"space-between"}
@@ -364,41 +393,19 @@ export const FlowExecutionResultView: React.FC = () => {
364393
hierarchy={"tertiary"}>
365394
{parameter?.names?.[0]?.content}
366395
</Text>
367-
<Editor readonly showTooltips={false}
368-
language={"json"}
369-
initialValue={input.value}
370-
customSuggestionComponent={false}
371-
basicSetup={{
372-
highlightActiveLine: false,
373-
highlightActiveLineGutter: false,
374-
}}/>
396+
<JsonView collapsed value={input.value ?? {}}/>
375397
</div>
376398

377399
}) : item.type === "trigger" ? (
378-
<Editor readonly showTooltips={false}
379-
language={"json"}
380-
initialValue={item.data.input}
381-
customSuggestionComponent={false}
382-
basicSetup={{
383-
highlightActiveLine: false,
384-
highlightActiveLineGutter: false,
385-
}}/>
400+
<JsonView collapsed value={item.data.input ?? {}}/>
386401
) : null}
387402
{
388403
item.data.error ? (
389404
<>
390405
<Text size={"md"}>
391406
Error
392407
</Text>
393-
<Editor readonly
394-
showTooltips={false}
395-
language={"json"}
396-
initialValue={item.data.error}
397-
customSuggestionComponent={false}
398-
basicSetup={{
399-
highlightActiveLine: false,
400-
highlightActiveLineGutter: false,
401-
}}/>
408+
<JsonView collapsed value={item.data.error ?? {}}/>
402409
</>
403410
) : null
404411
}
@@ -411,22 +418,12 @@ export const FlowExecutionResultView: React.FC = () => {
411418
<Text size={"md"}>
412419
Result
413420
</Text>
414-
<Editor readonly showTooltips={false}
415-
language={"json"}
416-
initialValue={item.data.success}
417-
basicSetup={{
418-
highlightActiveLine: false,
419-
highlightActiveLineGutter: false,
420-
}}/>
421+
<JsonView collapsed value={item.data.success ?? {}}/>
421422
</div>
422423
)
423424
}
424425
</div>
425-
</ScrollAreaViewport>
426-
<ScrollAreaScrollbar orientation={"vertical"}>
427-
<ScrollAreaThumb/>
428-
</ScrollAreaScrollbar>
429-
</ScrollArea>
426+
</ExecutionTooltipScrollArea>
430427
</TooltipContent>
431428
</TooltipPortal>
432429
</Tooltip>

0 commit comments

Comments
 (0)