Skip to content

Commit ed65556

Browse files
authored
fix merge config logic (#34)
1 parent df91adc commit ed65556

3 files changed

Lines changed: 28 additions & 39 deletions

File tree

‎package-lock.json‎

Lines changed: 0 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/tool.ts‎

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,40 @@ export function hideAppLoadingIndicator() {
130130
}
131131

132132
export function mergeObjects(
133-
...objects: Record<string, any>[]
133+
lowerPriority: Record<string, any>,
134+
higherPriority: Record<string, any>
134135
): Record<string, any> {
135-
const result: Record<string, any> = {};
136-
for (const obj of objects) {
137-
for (const [key, value] of Object.entries(obj)) {
138-
if (value !== null && value !== undefined) {
139-
result[key] = value;
136+
const result: Record<string, any> = { ...lowerPriority };
137+
138+
for (const key of Object.keys(higherPriority)) {
139+
const highVal = higherPriority[key];
140+
const lowVal = lowerPriority[key];
141+
142+
// If higher is null or undefined, keep lower if it exists
143+
if (highVal === null || highVal === undefined) {
144+
if (lowVal !== null && lowVal !== undefined) {
145+
result[key] = lowVal;
140146
}
147+
continue;
148+
}
149+
150+
// Deep merge plain objects
151+
if (isPlainObject(lowVal) && isPlainObject(highVal)) {
152+
result[key] = mergeObjects(lowVal, highVal);
153+
continue;
141154
}
155+
156+
// Otherwise, higher priority wins
157+
result[key] = highVal;
142158
}
159+
143160
return result;
144161
}
145162

163+
function isPlainObject(value: any): value is Record<string, any> {
164+
return value !== null && typeof value === 'object' && !Array.isArray(value);
165+
}
166+
146167
export function getSpectaAssetUrl(path: string): string {
147168
const labExtension = PageConfig.getOption('fullLabextensionsUrl');
148169
const url = URLExt.join(labExtension, 'jupyter-specta', 'static', path);

‎style/base.css‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
gap: 10px;
9393
align-items: center;
9494
justify-content: space-between;
95-
padding: 0 1rem;
95+
padding: 0;
9696
position: relative;
9797
}
9898

0 commit comments

Comments
 (0)