Skip to content

Commit 02830dc

Browse files
Roman SnapkoMarceloRGonc
andauthored
Improve data picker performance (#1179)
Co-authored-by: Marcelo Gonçalves <marcelo@openops.com>
1 parent 2d6d6c2 commit 02830dc

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

packages/react-ui/src/app/features/builder/data-selector/data-selector-utils.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ type HandleStepOutputProps = {
2828
displayName: string;
2929
};
3030

31+
const MAX_SLICE_LENGTH = 10;
32+
const MAX_SLICES_AMOUNT = 10;
33+
3134
function traverseStepOutputAndReturnMentionTree({
3235
stepOutput,
3336
success,
@@ -70,9 +73,8 @@ function handlingArrayStepOutput(
7073
parentDisplayName: string,
7174
startingIndex = 0,
7275
): MentionTreeNode {
73-
const maxSliceLength = 100;
7476
const isEmptyList = Object.keys(stepOutput).length === 0;
75-
if (stepOutput.length <= maxSliceLength) {
77+
if (stepOutput.length <= MAX_SLICE_LENGTH) {
7678
return {
7779
key: parentDisplayName,
7880
children: stepOutput.map((ouput, idx) =>
@@ -92,13 +94,15 @@ function handlingArrayStepOutput(
9294
};
9395
}
9496

97+
const slicesAmount = Math.ceil(stepOutput.length / MAX_SLICE_LENGTH);
98+
9599
const numberOfSlices = new Array(
96-
Math.ceil(stepOutput.length / maxSliceLength),
100+
Math.min(slicesAmount, MAX_SLICES_AMOUNT),
97101
).fill(0);
98102
const children: MentionTreeNode[] = numberOfSlices.map((_, idx) => {
99-
const startingIndex = idx * maxSliceLength;
103+
const startingIndex = idx * MAX_SLICE_LENGTH;
100104
const endingIndex =
101-
Math.min((idx + 1) * maxSliceLength, stepOutput.length) - 1;
105+
Math.min((idx + 1) * MAX_SLICE_LENGTH, stepOutput.length) - 1;
102106
const displayName = `${parentDisplayName} ${startingIndex}-${endingIndex}`;
103107
const sliceOutput = handlingArrayStepOutput(
104108
stepOutput.slice(startingIndex, endingIndex),

packages/ui-components/src/components/code-editor/code-editor.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import React, {
88
useCallback,
99
useEffect,
1010
useImperativeHandle,
11+
useMemo,
1112
useRef,
1213
useState,
1314
} from 'react';
@@ -67,9 +68,14 @@ const CodeEditor = React.forwardRef<CodeEditorRef, CodeEditorProps>(
6768
const [currentLanguage, setCurrentLanguage] =
6869
useState<MonacoLanguage>(language);
6970

70-
const { code, packageJson } = isStringValue
71-
? { code: value, packageJson: undefined }
72-
: sourceCodeObject || { code: convertToString(value), packageJson: '{}' };
71+
const { code, packageJson } = useMemo(() => {
72+
return isStringValue
73+
? { code: value, packageJson: undefined }
74+
: sourceCodeObject || {
75+
code: convertToString(value),
76+
packageJson: '{}',
77+
};
78+
}, [value, sourceCodeObject, isStringValue]);
7379

7480
const formatValue = (value: unknown): string => {
7581
if (typeof value === 'string') {

0 commit comments

Comments
 (0)