Skip to content

Commit 53a6037

Browse files
Fix clearing all data if cluster is not loaded
Clearing all button does not work if user filled cluster without loading any cluster. Signed-off-by: Arkadiusz Balys <arkadiusz.balys@nordicsemi.no>
1 parent ae065cc commit 53a6037

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/app/Components/ClusterFile.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,17 @@ class ClusterFile {
9191
* The current instance of the cluster file.
9292
* This instance is used to track the changes provided by the user.
9393
*/
94-
static XMLCurrentInstance: XMLConfigurator = defaultXMLConfigurator;
94+
static XMLCurrentInstance: XMLConfigurator = deepClone(
95+
defaultXMLConfigurator
96+
);
9597

9698
/**
9799
* The base instance of the cluster file.
98100
* This instance is used to compare the changes with the original file to generate the cluster extension.
99101
*/
100-
static XMLBaseInstance: XMLConfigurator = defaultXMLConfigurator;
102+
static XMLBaseInstance: XMLConfigurator = deepClone(
103+
defaultXMLConfigurator
104+
);
101105

102106
static XMLDefaultInstance: XMLConfigurator = deepClone(
103107
defaultXMLConfigurator

src/app/SidePanel/StateReset.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import ClusterFile from '../Components/ClusterFile';
88
import eventEmitter from '../Components/EventEmitter';
9+
import { deepClone } from '../Components/Utils';
910
import { defaultXMLConfigurator, defaultXMLFile } from '../defaults';
1011
import { XMLExtensionConfigurator } from '../defines';
1112

@@ -17,12 +18,12 @@ import { XMLExtensionConfigurator } from '../defines';
1718
* @returns {void}
1819
*/
1920
export const resetClusterFileState = (): void => {
20-
// Reset instances to defaults (using direct reference to preserve HexString instances)
21-
ClusterFile.XMLCurrentInstance = defaultXMLConfigurator;
22-
ClusterFile.XMLBaseInstance = defaultXMLConfigurator;
21+
// Reset instances to defaults (using deep clones to avoid reference sharing)
22+
ClusterFile.XMLCurrentInstance = deepClone(defaultXMLConfigurator);
23+
ClusterFile.XMLBaseInstance = deepClone(defaultXMLConfigurator);
2324

2425
// Reset file to default structure
25-
ClusterFile.file = defaultXMLFile;
26+
ClusterFile.file = deepClone(defaultXMLFile);
2627

2728
// Clear extension file (no default available in defaults.ts)
2829
ClusterFile.extensionFile = {} as XMLExtensionConfigurator;

0 commit comments

Comments
 (0)