sync parameter key renames and deletions to all block types (#4459)
This commit is contained in:
@@ -11,6 +11,14 @@ type Props = {
|
||||
values: Set<string>;
|
||||
};
|
||||
|
||||
function areSetsEqual<T>(a: Set<T>, b: Set<T>): boolean {
|
||||
if (a.size !== b.size) return false;
|
||||
for (const item of a) {
|
||||
if (!b.has(item)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function WorkflowBlockInputSet(props: Props) {
|
||||
const { nodeId, onChange, values } = props;
|
||||
const [parameterKeys, setParameterKeys] = useState<Set<string>>(values);
|
||||
@@ -20,6 +28,13 @@ function WorkflowBlockInputSet(props: Props) {
|
||||
workflowParameters.map((parameter) => parameter.key),
|
||||
);
|
||||
|
||||
// Sync local state when values prop changes (e.g., parameter renamed externally)
|
||||
useEffect(() => {
|
||||
if (!areSetsEqual(parameterKeys, values)) {
|
||||
setParameterKeys(values);
|
||||
}
|
||||
}, [values, parameterKeys]);
|
||||
|
||||
useEffect(() => {
|
||||
onChange(new Set(parameterKeys));
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
|
||||
Reference in New Issue
Block a user