@@ -40,10 +40,47 @@ export const ConfigView = () => {
4040 } , [ klasses , options , memory . klasses , memory . options ] ) ;
4141
4242 const onSave = useCallback ( ( ) => {
43+ // Update existing objects to match new class definitions
44+ const updatedObjects = { ...memory . objects } ;
45+
46+ Object . entries ( updatedObjects ) . forEach ( ( [ objId , obj ] ) => {
47+ const klassDefinition = klasses [ obj . klass ] ;
48+
49+ // Skip if class doesn't exist (e.g., Array) or object class is not in klasses
50+ if ( ! klassDefinition ) return ;
51+
52+ const updatedAttributes = { ...obj . attributes } ;
53+ const klassAttributeNames = Object . keys ( klassDefinition . attributes ) ;
54+ const currentAttributeNames = Object . keys ( updatedAttributes ) ;
55+
56+ // Add new attributes from class definition
57+ klassAttributeNames . forEach ( ( attrName ) => {
58+ if ( ! updatedAttributes [ attrName ] ) {
59+ updatedAttributes [ attrName ] = {
60+ dataType : klassDefinition . attributes [ attrName ] ,
61+ value : undefined ,
62+ } ;
63+ }
64+ } ) ;
65+
66+ // Remove attributes that are no longer in class definition
67+ currentAttributeNames . forEach ( ( attrName ) => {
68+ if ( ! klassAttributeNames . includes ( attrName ) ) {
69+ delete updatedAttributes [ attrName ] ;
70+ }
71+ } ) ;
72+
73+ updatedObjects [ objId ] = {
74+ ...obj ,
75+ attributes : updatedAttributes ,
76+ } ;
77+ } ) ;
78+
4379 updateMemory ( {
4480 ...memory ,
4581 klasses,
4682 options,
83+ objects : updatedObjects ,
4784 } ) ;
4885 setHasUnsavedChanges ( false ) ;
4986 setShowSaveSuccess ( true ) ;
0 commit comments