Loki: Fix error when changing operations with different parameters (#51779)

* copy defaultParams when changing an operation

* add type and name comparison

* removed name check
This commit is contained in:
Sven Grossmann 2022-07-06 16:52:58 +02:00 committed by GitHub
parent 0a6eeaa636
commit 663f3fcd2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -79,7 +79,16 @@ export const OperationHeader = React.memo<Props>(
if (value.value) {
// Operation should exist if it is selectable
const newDef = queryModeller.getOperationDef(value.value.id)!;
let changedOp = { ...operation, id: value.value.id };
// copy default params, and override with all current params
const newParams = [...newDef.defaultParams];
for (let i = 0; i < Math.min(operation.params.length, newParams.length); i++) {
if (newDef.params[i].type === def.params[i].type) {
newParams[i] = operation.params[i];
}
}
const changedOp = { ...operation, params: newParams, id: value.value.id };
onChange(index, def.changeTypeHandler ? def.changeTypeHandler(changedOp, newDef) : changedOp);
}
}}