-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🪟🧹 Connector builder: Fast fields performance improvements #20957
Changes from 109 commits
d2ed762
f474a1c
5b0521f
af659fd
1cd3bbb
807c436
6c76e0f
05c3107
eee4303
7d6f977
0fe11f0
34d4814
67d62c5
afea882
c7e7475
cc7f65f
a1c6cbd
9be8337
37cee8f
5686241
7b73364
7058d26
dd7e82a
6d4c7d3
d624792
36cf941
b7a6322
72b602a
5e47a4a
6c71028
809625f
10446eb
4a7a885
2024b60
ee30092
d91df38
93fe558
cbc023a
ec54d38
47152ea
6ec0e10
1aa7829
7b90088
fbefbdd
6b3e5e2
9aa3f80
c765003
5cd77ec
5dfbc22
a6aa741
95717d2
40d162d
b9384ee
582a5f2
18d6ce8
60c1f1c
9cb595d
fe74a45
5c00ad0
bd0dffc
1ff8c13
c6ee526
05bbd6f
fff4703
94ba866
97bb0a7
633b9b2
e47517f
e931956
219fcc1
8cb6873
6889f66
7b60406
d5e56eb
35a74ba
02c8096
526adfc
7d49233
c5da764
6c0bf9d
477977f
200cfe7
c7fd310
e0e3796
e23a6d8
610e668
e68ff49
9ccf294
ae9a229
a9e1d09
e4f7bba
16c71ae
54c070d
2e20fa6
65199d0
6b71161
81c12b2
b447b24
92722e0
ef86690
718c233
26acc32
6a8be0b
e166b03
4b4eb7e
a4d35be
54d744b
f5818e6
5dc707b
742538e
b2b03bf
4ce7811
0d5fcc5
98a33cf
7e08ea7
80ec5c6
8c33c36
f996b6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,7 +111,9 @@ export const BuilderSidebar: React.FC<BuilderSidebarProps> = React.memo(({ class | |
<FontAwesomeIcon icon={faUser} /> | ||
<FormattedMessage | ||
id="connectorBuilder.userInputs" | ||
values={{ number: values.inputs.length + getInferredInputs(values).length }} | ||
values={{ | ||
number: values.inputs.length + getInferredInputs(values.global, values.inferredInputOverrides).length, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason the |
||
}} | ||
/> | ||
</ViewSelectButton> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { useField } from "formik"; | ||
import React, { useRef } from "react"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
import GroupControls from "components/GroupControls"; | ||
|
@@ -60,6 +61,10 @@ interface KeyValueListFieldProps { | |
export const KeyValueListField: React.FC<KeyValueListFieldProps> = ({ path, label, tooltip }) => { | ||
const [{ value: keyValueList }, , { setValue: setKeyValueList }] = useField<Array<[string, string]>>(path); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't get rid of the "useField" here, but we can memoize everything happening within the component if the key value list didn't actually change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why can't we use a FastField here? |
||
|
||
// need to wrap the setter into a ref because it will be a new function on every formik state update | ||
const setKeyValueListRef = useRef(setKeyValueList); | ||
setKeyValueListRef.current = setKeyValueList; | ||
|
||
return ( | ||
<GroupControls | ||
label={<ControlLabels label={label} infoTooltipContent={tooltip} />} | ||
|
@@ -69,20 +74,36 @@ export const KeyValueListField: React.FC<KeyValueListFieldProps> = ({ path, labe | |
</Button> | ||
} | ||
> | ||
{keyValueList.map((keyValue, keyValueIndex) => ( | ||
<KeyValueInput | ||
key={keyValueIndex} | ||
keyValue={keyValue} | ||
onChange={(newKeyValue) => { | ||
const updatedList = keyValueList.map((entry, index) => (index === keyValueIndex ? newKeyValue : entry)); | ||
setKeyValueList(updatedList); | ||
}} | ||
onRemove={() => { | ||
const updatedList = keyValueList.filter((_, index) => index !== keyValueIndex); | ||
setKeyValueList(updatedList); | ||
}} | ||
/> | ||
))} | ||
<KeyValueList keyValueList={keyValueList} setKeyValueList={setKeyValueListRef} /> | ||
</GroupControls> | ||
); | ||
}; | ||
|
||
const KeyValueList = React.memo( | ||
({ | ||
keyValueList, | ||
setKeyValueList, | ||
}: { | ||
keyValueList: Array<[string, string]>; | ||
setKeyValueList: React.MutableRefObject<(val: Array<[string, string]>) => void>; | ||
}) => { | ||
return ( | ||
<> | ||
{keyValueList.map((keyValue, keyValueIndex) => ( | ||
<KeyValueInput | ||
key={keyValueIndex} | ||
keyValue={keyValue} | ||
onChange={(newKeyValue) => { | ||
const updatedList = keyValueList.map((entry, index) => (index === keyValueIndex ? newKeyValue : entry)); | ||
setKeyValueList.current(updatedList); | ||
}} | ||
onRemove={() => { | ||
const updatedList = keyValueList.filter((_, index) => index !== keyValueIndex); | ||
setKeyValueList.current(updatedList); | ||
}} | ||
/> | ||
))} | ||
</> | ||
); | ||
} | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't get rid of subscribing to the builder form state, but we can memoize building the actual options list and memoize the actual listbox component based on that.