VariablesEditView: Update cloned variable key when duplicating (#114908)

update cloned variable key when duplicating
This commit is contained in:
Sergej-Vlasov
2025-12-08 16:34:21 +00:00
committed by GitHub
parent e40673b298
commit ab9b070eb0
@@ -1,4 +1,5 @@
import { useMemo } from 'react';
import { v4 as uuidv4 } from 'uuid';
import { NavModel, NavModelItem, PageLayoutType } from '@grafana/data';
import { SceneComponentProps, SceneObjectBase, SceneVariable, SceneVariables, sceneGraph } from '@grafana/scenes';
@@ -109,10 +110,8 @@ export class VariablesEditView extends SceneObjectBase<VariablesEditViewState> i
newName = `copy_of_${variableToUpdate.state.name}_${copyNumber}`;
}
//clone the original variable
const newVariable = variableToUpdate.clone(variableToUpdate.state);
// update state name of the new variable
newVariable.setState({ name: newName });
//clone the original variable, update name and key
const newVariable = variableToUpdate.clone({ ...variableToUpdate.state, name: newName, key: uuidv4() });
const updatedVariables = [
...variables.slice(0, variableIndex + 1),