Skip to content

Commit

Permalink
fix: fix merge project config
Browse files Browse the repository at this point in the history
  • Loading branch information
WitoDelnat committed May 9, 2022
1 parent c5ea5aa commit 9fc65b7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"strip-ansi": "6.0.1",
"styled-components": "5.3.5",
"tar": "6.1.11",
"tiny-invariant": "1.2.0",
"type-fest": "2.12.2",
"uuid": "8.3.2",
"vm2": "3.9.9",
Expand Down
32 changes: 4 additions & 28 deletions src/redux/services/projectConfig.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import flatten from 'flat';
import {readFileSync, writeFileSync} from 'fs';
import _ from 'lodash';
import _, {isArray, mergeWith} from 'lodash';
import log from 'loglevel';
import {sep} from 'path';
import {AnyAction} from 'redux';
import invariant from 'tiny-invariant';

import {K8S_VERSIONS, PREDEFINED_K8S_VERSION} from '@constants/constants';

Expand Down Expand Up @@ -158,32 +158,8 @@ export const updateProjectSettings = (dispatch: (action: AnyAction) => void, pro
};

export const mergeConfigs = (baseConfig: ProjectConfig, config?: ProjectConfig | null): ProjectConfig => {
if (!(baseConfig && baseConfig.settings && baseConfig.kubeConfig)) {
throw Error('Base config must be set');
}

if (!config) {
return baseConfig;
}

const serializedBaseConfig: SerializableObject = flatten<any, any>(baseConfig);
const serializedConfig: SerializableObject = flatten<any, any>(config);

// override base properties
Object.keys(serializedBaseConfig).forEach((key: string) => {
if (!_.isUndefined(serializedConfig[key])) {
serializedBaseConfig[key] = serializedConfig[key];
}
});

// add missing base properties
Object.keys(serializedConfig).forEach((key: string) => {
if (_.isUndefined(serializedBaseConfig[key])) {
serializedBaseConfig[key] = serializedConfig[key];
}
});

return flatten.unflatten(serializedBaseConfig);
invariant(baseConfig && baseConfig.settings && baseConfig.kubeConfig, 'base config expected');
return mergeWith(baseConfig, config, (_a, b) => (isArray(b) ? b : undefined));
};

export const keysToUpdateStateBulk = (
Expand Down

0 comments on commit 9fc65b7

Please sign in to comment.