Skip to content

Commit

Permalink
612 improve settings overwrite algorithm (#615)
Browse files Browse the repository at this point in the history
* improve settings overwrite algorithm

* apply formatting changes

---------

Co-authored-by: Logende <[email protected]>
  • Loading branch information
Logende and Logende authored Jan 30, 2025
1 parent 3c680db commit 324fa4e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions meta_configurator/src/utility/settingsUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {SessionMode} from '@/store/sessionMode';
import {SETTINGS_DATA_DEFAULT} from '@/settings/defaultSettingsData';
import type {SettingsInterfacePanel, SettingsInterfaceRoot} from '@/settings/settingsTypes';
import {panelTypeRegistry} from '@/components/panels/panelTypeRegistry';
import {useDataSource} from '@/data/dataSource';

function addDefaultsForMissingFields(userFile: any, defaultsFile: any) {
for (const key in defaultsFile) {
Expand All @@ -18,7 +19,15 @@ function addDefaultsForMissingFields(userFile: any, defaultsFile: any) {

function overwriteSettingsValues(userFile: any, replaceFile: any) {
for (const key in replaceFile) {
userFile[key] = replaceFile[key];
if (!(key in userFile)) {
userFile[key] = replaceFile[key];
} else if (typeof replaceFile[key] === 'object' && !Array.isArray(replaceFile[key])) {
overwriteSettingsValues(userFile[key], replaceFile[key]);
} else {
// element is in both files and is not an object
// overwrite the value
userFile[key] = replaceFile[key];
}
}
}

Expand Down Expand Up @@ -52,6 +61,6 @@ export function addDefaultsForSettings() {

export function overwriteSettings(replaceFile: any) {
// overwrites the settings with the values from the replace file. Keeps all other values
const userSettings = getDataForMode(SessionMode.Settings).data.value;
const userSettings = useDataSource().settingsData.value;
overwriteSettingsValues(userSettings, replaceFile);
}

0 comments on commit 324fa4e

Please sign in to comment.